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.

4 comments

  1. Ricky says:

    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

  2. Ricky says:

    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…

    • Stu says:

      🙂 perfect

      It’s being passed so it can be used by the method if required, not a necessary parameter, so omit if you don’t think you’ll use it.

      Stu

Leave a Reply

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

Solve the maths problem shown below before posting: *

Follow

Get every new post delivered to your Inbox

Join other followers: