{"id":1621,"date":"2014-01-21T16:04:31","date_gmt":"2014-01-21T16:04:31","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1621"},"modified":"2014-06-30T10:44:54","modified_gmt":"2014-06-30T09:44:54","slug":"quick-tip-19","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2014\/01\/21\/quick-tip-19\/","title":{"rendered":"Custom_AddDocLibMenuItems"},"content":{"rendered":"<p><strong>SharePoint Short #19<\/strong><\/p>\n<p>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.<\/p>\n<p>For example:<\/p>\n<pre lang=\"javascript\">\r\nfunction YourImplementationOf_AddDocLibMenuItems(m, ctx, url) {\r\n    if (typeof Custom_AddDocLibMenuItems != 'undefined') {\r\n        var CurrentCustom_AddDocLibMenuItems = Custom_AddDocLibMenuItems;\r\n    }\r\n    \r\n    Custom_AddDocLibMenuItems = function (m, ctx, url) {\r\n        \/\/ Custom code to add ECB menu items....\r\n        \r\n        if (CurrentCustom_AddDocLibMenuItems === undefined) {\r\n            return false;\r\n        }\r\n        \r\n        return CurrentCustom_AddDocLibMenuItems(m, ctx, url);\r\n    };\r\n}\r\n<\/pre>\n<p>By checking if <em>Custom_AddDocLibMenuItems<\/em> is not <em>Undefined<\/em> and referencing the method at the start of your <em>YourImplementationOf_AddDocLibMenuItems<\/em> method, you are able to ensure any other implementation of this method is called once you are finished with it.<\/p>\n<p>To have your <em>YourImplementationOf_AddDocLibMenuItems<\/em> method initiated when a page loads, add the following:<\/p>\n<pre lang=\"JavaScript\">\r\n$(document).ready(function () {\r\n    _spBodyOnLoadFunctionNames.push('YourImplementationOf_AddDocLibMenuItems()');\r\n});\r\n<\/pre>\n<p>Here we use jQuery&#8217;s <a href=\"http:\/\/api.jquery.com\/ready\/\" title=\".ready()\" target=\"_blank\">ready<\/a> function, to add the custom method <em>YourImplementationOf_AddDocLibMenuItems<\/em> 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 <em>Custom_AddDocLibMenuItems<\/em> is called whenever the ECB is opened.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2014\/01\/21\/quick-tip-19\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3,44],"tags":[85,45],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-q9","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1621"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1621"}],"version-history":[{"count":10,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1621\/revisions"}],"predecessor-version":[{"id":1707,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1621\/revisions\/1707"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1621"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}