views:

47

answers:

2

i want to use the mootools library to do animation & ajax in a widget i'm building.

i plan to have the widget write itself into the page so the end user just deploys a single line of javascript.

i'm concerned about the compatibility issues that may arise if my widget is used on a page which is already using another library.

short tests show problems even when enclosed in a self executing function if scriptaculous is already loaded, although jquery doesn't seem to cause a problem.

what is the best solution to this?

is there any way to load mootools in isolation so i can just use it for my purposes?

i see that jquery, whilst unfamiliar to me, is highly namespaced and therefore probably more appropriate to the task, would using that instead alleviate any potential problems?

can i just copy and paste mootools into my self executing function?

nb: the following error when using with prototype comes as a result of using mootool's setStyle method.

element.style is undefined

element.style.cssText += ';' + styles;

+1  A: 

There isn't a method to use mootools. The developers have specifically stated that they are not going to namespace mootools to run along side prototype and they squash any attempts to have the core changed to do it (see 1).

You really are just better off using either jQuery or another namespaced library (I believe both Dojo and YUI are, but I could be mistaken), or if you don't need the overhead, just build your own in good old-fashion JS.

  1. https://mootools.lighthouseapp.com/projects/2706/tickets/219-mootools-namespace
Aaron Harun
A: 

you cannot "namespace" mootools. it is a prototypical library. you seem to indicate that you are trying to use it in conjunction with prototype - which is STILL a prototypical library as of time of writing (there has been talk of them moving away from that).

basically 2 such frameworks alongside of each other will have completely unpredictable results, there are no guarantees on what library's method will take precedence on any of the prototypes that they change.

mootools can co-exist happily with jquery or any other lib that is functional. it also looks for anything already defining $ and if unavailable (say, because $ === jQuery), it reverts back to using document.id() instead.

if your page already uses scriptaculous, then you should do the effects using that (in an ideal world). next-best-thing, you can try jquery but that's nasty for the sake of a simple widget (or any 2 frameworks)

btw, the AddThis widgets used to contain mootools a while back and it did not break any pages it got embedded on so I suppose it is doable. regretfully for you, they seem to have moved to their own vanilla lib now...

Dimitar Christoff