TextControl.Web: Adding Custom Ribbon Tabs
In recent blog entries, we explained how to add custom buttons or ribbon groups to the ribbon bar. This article shows how to add complete ribbon tabs to the existing ribbon bar of Web.TextControl. Basically, the way to add a ribbon tab to the ribbon bar is the same like adding buttons or ribbon groups: The HTML DOM is changed dynamically after the ribbon has been completely loaded. The following Javascript code is all you need to add the new ribbon tab with a button in a ribbon group. The…

In recent blog entries, we explained how to add custom buttons or ribbon groups to the ribbon bar. This article shows how to add complete ribbon tabs to the existing ribbon bar of Web.TextControl.

Basically, the way to add a ribbon tab to the ribbon bar is the same like adding buttons or ribbon groups: The HTML DOM is changed dynamically after the ribbon has been completely loaded.
The following Javascript code is all you need to add the new ribbon tab with a button in a ribbon group. The ribbonTabsLoaded event is fired after the ribbon has been completely loaded. In this event handler, the new tab is added before the View tab. The tab content ribbonTabCustom is added to the txRibbonTabContentContainer which is basically the container for all ribbon tab content pages.
<script type="text/javascript">
// elements can be only added when the ribbon is completely loaded
TXTextControl.addEventListener("ribbonTabsLoaded", function (e) {
addTab();
});
// this function adds a new tab and the tab content page
function addTab() {
sCustomTab = "<li><a onclick=\'activateCustomTab();\' id=\'tabCustom\' data-applicationmodes=\'0\' tabindex=\'-1\' href=\'#!\'>Custom Ribbon Tab</a></li>";
// add the new tab after the \'View\' tab
document.getElementById(\'tabView\').parentElement.insertAdjacentHTML(
\'beforebegin\', sCustomTab);
sCustomTabContent = "<div id=\'ribbonTabCustom\' class=\'tab-content\' style=\'display: none;\'>";
sCustomTabContent += "<div id=\'ribbonGroupCustom\' class=\'ribbon-group\'>";
sCustomTabContent += " <div class=\'ribbon-group-content\'>";
sCustomTabContent += " <div class=\'ribbon-group-content-row\'>";
sCustomTabContent += " <div class=\'ribbon-group-button-group\'>";
sCustomTabContent += " <div onclick=\'BtnCustomAction()\' id=\'BtnCustom\' class=\'ribbon-button ribbon-button-big\' title=\'Custom\'>";
sCustomTabContent += " <div class=\'ribbon-button-big-image-container\'><img id=\'imgID_RibbonTabInsert_html_0\' class=\'ribbon-button-big-image\' src=\'custom.png\'></img></div>";
sCustomTabContent += " <div class=\'ribbon-button-big-label-container\'><p class=\'ribbon-button-label\'>Custom</p></div>";
sCustomTabContent += " </div>";
sCustomTabContent += " </div>";
sCustomTabContent += " </div>";
sCustomTabContent += " </div>";
sCustomTabContent += " <div class=\'ribbon-group-label-container\'>";
sCustomTabContent += " <p class=\'ribbon-group-label\'>Custom</p>";
sCustomTabContent += " </div>";
sCustomTabContent += "</div>";
sCustomTabContent += "</div>";
// add the tab content to the tab content container
document.getElementById(\'txRibbonTabContentContainer\').insertAdjacentHTML(
\'afterbegin\', sCustomTabContent);
}
</script>
The activateCustomTab is called when the new tab page is clicked. This function is deactivating all active tabs in order to activate the newly added tab page.
function activateCustomTab() {
$(\'div.tab-content\').css("display", "none");
$(\'ul.tabs a\').removeClass("selected");
$("#ribbonTabCustom").css("display", "inline-block");
$("#tabCustom").addClass("selected");
}
Download the sample from GitHub and test it on your own.
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2012 or better
- TX Text Control .NET Server (trial sufficient)
Related Posts
ASP.NETJavaScriptDocument Editor
Detect Toggle Button Changes Using a MutationObserver
This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…
TextControl.Web: Determine when a Document Has Been Completely Loaded
Web.TextControl provides an event that can be used to determine when the ribbon bar has been loaded completely in order to add and remove ribbon items such as groups, tabs and buttons. But when…
Building a Touch-enabled Button Bar with Javascript
A ribbon bar is a user-friendly interface for desktop environments when users can utilize a mouse to navigate. On tablets or smart-phones, another, more touch-enabled, interface might be required.…
TextControl.Web: Inserting Merge Fields Using Javascript
In a recent post, we already introduced the hidden Javascript interface that is available in version X12. This interface gives you access to the majority of internal Javascript calls that are used…
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.