Custom_AddDocLibMenuItems

SharePoint Short #19

When implementing your own Custom_AddDocLibMenuItems, which allows you to add custom menu items to the ECB of SharePoint items, remember to check for other implementations of this method before your own version.

For example:

function YourImplementationOf_AddDocLibMenuItems(m, ctx, url) {
    if (typeof Custom_AddDocLibMenuItems != 'undefined') {
        var CurrentCustom_AddDocLibMenuItems = Custom_AddDocLibMenuItems;
    }
 
    Custom_AddDocLibMenuItems = function (m, ctx, url) {
        // Custom code to add ECB menu items....
 
        if (CurrentCustom_AddDocLibMenuItems === undefined) {
            return false;
        }
 
        return CurrentCustom_AddDocLibMenuItems(m, ctx, url);
    };
}

By checking if Custom_AddDocLibMenuItems is not Undefined and referencing the method at the start of your YourImplementationOf_AddDocLibMenuItems method, you are able to ensure any other implementation of this method is called once you are finished with it.

To have your YourImplementationOf_AddDocLibMenuItems method initiated when a page loads, add the following:

$(document).ready(function () {
    _spBodyOnLoadFunctionNames.push('YourImplementationOf_AddDocLibMenuItems()');
});

Here we use jQuery’s ready function, to add the custom method YourImplementationOf_AddDocLibMenuItems to a SharePoint array that is processed when the DOM is loaded. What this means is that the method will be executed when the page loads and subsequently the custom overload of Custom_AddDocLibMenuItems is called whenever the ECB is opened.

This entry was posted in SharePoint, SharePoint Shorts and tagged , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

4 Comments
Inline Feedbacks
View all comments
Ricky

Hi!

Thank you for this helpful tip. But where is the function ResetCustom_AddDocLibMenuItems called? I don’t find any usage of this either in js-files of SharePoint 2010 or SharePoint 2013.

Greetings from Germany
Ricky

Ricky

Great, that did the trick, thank you very much! 🙂
A last question: why are you passing an ‘url’-parameter to the functions? It seems not to be used initially…