Problem with jQuery plugins in Moodle 2.6

Moodle use as a official javascript library YUI, but jQuery is growing everyday and many developer use it, mostly because it is amazing to manipulate the DOM.

I am one of those who use jQuery to create effects inside moodle themes. I had used different libraries without any problem until Moodle 2.6 was released.

When I downloaded Moodle 2.6 and try to use a theme which I was developing something got wrong with JS when I use compressed files.

After take a look I realize that the main problem was the syntax of jQuery. If you use the most common syntax, which is:

(function(window,$,undefined){}(this,jQuery));

You could get this:

jQuery error

The solution is simple. If you download a jQuery plugins, take a look of the compressed file, if the plugins has the syntaxt that I show you before, change it to:

! function(window,$,undefined){}(this,jQuery)

As Paul Irish explain in the video about jQuery 10 Things I Learned from the jQuery Source it is not a problem

You don’t have to download the source and compressed again, you just have to delete the parentheses and add the !

A hint to find the last parentheses:

!!goes here!!(jQuery,this,0);. It is at the end of the compressed source.

You may also like...

Leave a Reply

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