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.
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
Hi Ricky,
I’ve updated the post to explain it better 😉
Cheers from Brussels 🙂
Stu
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…
🙂 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