MooTools Archives

The other day an interesting question was posted to the WebAssist forums (full thread). Basically, a user was getting some JavaScript errors when adding PowerGallery to an existing page in their site. The error was complaining about the $() function. For those unfamiliar with MooTools, the $() function is a quick way to get a reference to an element by its id – instead of using document.getElementById() – and extend it with some MooTools magic.

After using Firebug to track down the exact error, it was pretty clear what was going on. The user’s page already had jQuery on it! When they added in their PowerGallery code, it was causing a conflict. Luckily, MooTools has a way to deal with this issue. Instead of using $(), use document.id(). This function was added as part of the MooTools Dollar Safe Mode updates made in version 1.2.3. Since jQuery defines the $() function too, MooTools wasn’t redefining it (to help not break jQuery).

The fix was to replace all $() function calls with document.id() in the gallery JavaScript. Using some PowerGallery code as an example:

//change this
this.wrapper = $(el);

//to this
this.wrapper = document.id(el);

I never recommend using more than 1 framework if you can avoid it and I’d always pick MooTools as my one and only!

SortablesWhen coding the admin for PowerGallery, I used the MooTools Sortables plugin to handle the drag & drop re-ordering of the images in the gallery.

This code worked great in Firefox, Safari, and Chrome. But then I tested in good ‘ole Internet Explorer IE Sucks. Oddly enough, IE6 worked fine when I tried to drag an image around. IE7 and IE8 were a different story though. When I clicked (and held) on an image and start dragging, the image would move a few pixels then freeze in place. If I released the mouse click, the image would then follow my mouse around until I clicked again and it would drop the image where indicated. Weird stuff to say the least, and definitely not the behavior I wanted.

Continue Reading

PowerGalleryWebAssist recently released a really cool PHP solution today called PowerGallery. I was the lead engineer on this solution and it was lots of fun to code it. Am I biased since I created this thing? Of course! But I have no doubts you’ll love it too. I don’t want this to sound like a sales pitch, but I am proud of the work we put into this solution pack. I also wanted to set the stage since some of my upcoming tips are direct results of things I learned during development of PowerGallery.
 
 

Continue Reading