1

Anybody know? I'd really like to pull it out & use jquery, but if the core Varien js is using it...

1
  • Thx guys - I was looking to lessen the js load, so the goal was to remove scriptaculous' bells and whistles and replace them if/as needed with jquery funcs (which we're already using on another part of the site). I would assume that prototype is in there for good reason, but wanted to see if anybody knew specifically what scriptaculous was doing so I could pull it out if I needed to.
    – dbcn
    Commented Sep 17, 2010 at 15:39

4 Answers 4

7

Scriptaculous is an add-on to Prototype, which is the actual framework that Magento is using. In a sense it is to Prototype what JQueryUI is to JQuery. So I don't believe you'd be looking to replace both. It be a very large task and probably not worth the effort. I actually found it easier to learn prototype than to go through the large amount of inline JavaScript (BAD MAGENTO) and replace it with JQuery.

Anyway, to answer your question, it's used all over the place in Magento. I believe it's most noticeable in the admin since it has a somewhat sophisticated interface. Pretty much anywhere you see Zooming, Sliders, Drag and Drop, etc. you can blame Scriptaculous. Nearly everything else JS related will be prototype.

2

Ok, Prototype is a javascript framework similar to jQuery in respect to the fact that it handles most of the ajax, dom manipulation etc and generally just making working with javascript much more simple and concise - eliminating a lot of cross browser issues with little effort.

Script.aculo.us is being used for the interface side, i.e. all the nice loaders, sliders, drag and drop in the admin section etc. This is all being handled with script.aculo.us.

Sure jQuery can probably handle this but cannot simple replace Magentos use of Prototype and Scriptaculous with jQuery. Good luck to you if you try.

Magento uses javascript very heavily (too heavily) and there are tons of inline javascript throughout the entire site.

What you can do though is accept that all of this javascript is in place for you to use. If you want to add new functionality to the site then you are free to use jQuery but dont try to undo what has been done in another library / framework.

If you must use jQuery then all you need do is add the following line to your page.xml layout file:

<action method="addJs"><script>path to your jquery</script></action>

its around line 38 and can be found in the default section and so affects almost every page.

and then obviously the same again for any of your own javascript files you create.

With regards to the inline javascript that magento is producing, a lot of it is based on onclick events and the lieks so you use jQuery to remove those events with syntax similar to the following:

$('.el').removeAttr('onclick');

for example, if you want to remove the javascript from the add to cart button you would use:

$('.btn-cart').removeAttr('onclick');

and then bind your own events to that button.

As alway.removeAttr('onclick');

Hope this helps.

Drew

2

I had wondered this in the beginning when first developing with Magento. jQuery is more popular, with a larger community and a huge source of plugs available. To have to go and pick up and learn a new Javascript library like Prototype or Scriptaculous is time consuming and unnecessary.

I discovered on the Magento course the reason behind this. In the beginning (years ago) when they first were developing the Magento platform, the only reliable, robust and stable Javascript library available was Prototype. jQuery was still in its infancy and wasn't popular as it is today nor was it stable enough. Which is why they chose to adopt Prototype. Till this day as previous comments above said it would take too long and maybe unnecessary to completely remove Prototype scripts. The platform relies on it heavily.

However there has been talks that the next major release of Magento would have jQuery library in its core. Whether this will happen it remains to be seen.

1

You can still implement jQuery, just make sure to use the no conflict function.

1
  • 3
    That doesn't really answer the question about what Scriptaculous is used for. Adding more JS frameworks to an already bogged down system isn't really a great solution.
    – Joe Mastey
    Commented Sep 10, 2010 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.