SharePoint JavaScript Ribbon Events with jQuery

After hours of hacking away and searching – I finally asked google the right question and came by this gem for triggering SharePoint Ribbon events with jQuery.  Thanks dennispg!

Trigger an event whenever the SharePoint 2010 ribbon changes
http://spmonkeypoint.wordpress.com/2012/05/16/trigger-an-event-whenever-the-sharepoint-2010-ribbon-changes/

From his site: ”

// Fires ‘ribbontabselected’ every time the ribbon selection changes

ExecuteOrDelayUntilScriptLoaded(function () {
CUI.Ribbon.prototype.$L_old = CUI.Ribbon.prototype.$L;
CUI.Ribbon.prototype.$L = function () {
this.$L_old();
$(document).trigger(‘ribbontabselected’, [this.get_selectedTabCommand()]);
};
}, ‘cui.js’);

// Fires ‘ribbontabselected’ after the ribbon has been initialized after load
ExecuteOrDelayUntilScriptLoaded(function () {
var pm = SP.Ribbon.PageManager.get_instance();
pm.add_ribbonInited(function () {
$(document).trigger(‘ribbontabselected’, [SP.Ribbon.PageManager.get_instance().get_ribbon().get_selectedTabCommand()]);
});
}, ‘sp.ribbon.js’);

// Example code for binding to the event
$(document).on(‘ribbontabselected’, function (e, selectedTabCommand) {
if (selectedTabCommand != “ReadTab”) {
alert(selectedTabCommand);
}
}); ”

Trigger an event whenever the SharePoint 2010 ribbon changes

One thought on “SharePoint JavaScript Ribbon Events with jQuery

  1. ExecuteOrDelayUntilScriptLoaded(function () {
    CUI.Ribbon.prototype.$L_old = CUI.Ribbon.prototype.$L;
    CUI.Ribbon.prototype.$L = function () {
    this.$L_old();
    $(document).trigger(‘ribbontabselected’, [this.get_selectedTabCommand()]);
    };
    }, ‘cui.js’);

    This code does not work. I dont get anything when i switch between ribbon tabs.

Leave a Reply

Your email address will not be published. Required fields are marked *