Thursday, February 7, 2013

Thumbnail view does not work with jQuery

I started using the thumnail view on a site that I was building for a customer. All of a sudden my jQuery script stopped working, but just on the thumbnail view page. After some digging I found that the thumbnail view resets the meaning of $, which is essential in writing jQuery scripts. Thanks a lot Microsoft!

The solution is to wrap all your jQuery scripts with the following function definition:

(function ($) {

    // Your custom jQuery code

})(jQuery);

This will work for your own scripts, but if you have imported third party script libraries that does not wrap their code properly, they will fail.

Yet another day in SharePoint paradise...