{"id":296,"date":"2010-11-06T10:27:18","date_gmt":"2010-11-06T18:27:18","guid":{"rendered":"http:\/\/singchan.com\/?p=296"},"modified":"2010-11-06T10:27:29","modified_gmt":"2010-11-06T18:27:29","slug":"sharepoint-2010-var-conflict-between-cmssitemanager-js-and-jquery","status":"publish","type":"post","link":"https:\/\/singchan.com\/wordpress\/2010\/11\/06\/sharepoint-2010-var-conflict-between-cmssitemanager-js-and-jquery\/","title":{"rendered":"SharePoint 2010: var $ conflict between CMSSiteManager.js and jQuery"},"content":{"rendered":"<p>I ran into an issue recently on a SharePoint 2010 project where a page containing a Thumbnails list view was throwing a JavaScript error. I actually took the wrong path troubleshooting this and burned through a lot of time as a result. I had incorrectly assumed the error had something to do with our custom master page.<\/p>\n<p>Turns out the <em>CMSSiteManager.js<\/em> library that is used by the Thumbnails list view is also using the <strong>$<\/strong> variable! Argh!<\/p>\n<p>Good thing the plug-in pattern we use only calls $ internally and not globally&#8230;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n(function($) {\r\n  \/\/ plug-in goodness here...\r\n})(jQuery);\r\n<\/pre>\n<p>Unfortunately our scripts for invoking the plug-ins was referencing <strong>$<\/strong>&#8230; \ud83d\ude41<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$(document).ready(function(){\r\n  $('.foo').samplePlugin();\r\n});\r\n<\/pre>\n<p>A quick replacement of <strong>$<\/strong> to <strong>jQuery<\/strong> did the trick:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\njQuery(document).ready(function(){\r\n  jQuery('.foo').samplePlugin();\r\n});\r\n<\/pre>\n<p>If you have large blocks of inline jQuery code on your page, you&#8217;ll probably want to use jQuery.noConflict():<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\njQuery.noConflict()(function() { \r\n    \/\/ code using $ as alias to jQuery\r\n});\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I ran into an issue recently on a SharePoint 2010 project where a page containing a Thumbnails list view was throwing a JavaScript error. I actually took the wrong path troubleshooting this and burned through a lot of time as a result. I had incorrectly assumed the error had something to do with our custom [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,95,43],"tags":[44,149,147,138,164,166,91,145,42,148,146],"class_list":["post-296","post","type-post","status-publish","format-standard","hentry","category-javascript","category-jquery","category-sharepoint-development","tag-44","tag-cmssitemanager-js","tag-conflict","tag-error","tag-javascript","tag-jquery","tag-js","tag-list","tag-sharepoint","tag-thumbnail","tag-view"],"_links":{"self":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":4,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":302,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/posts\/296\/revisions\/302"}],"wp:attachment":[{"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/singchan.com\/wordpress\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->