How To: Replace Prototype with jQuery

29 views
Skip to first unread message

Boris Masis

unread,
Aug 27, 2008, 5:06:33 PM8/27/08
to Lovd by Less
Hi guys,

I just did a little bit of work to remove prototype/scriptaculous from
Lovd By Less and replace it with jQuery/jQuery UI. jQuery is much
lighter than Prototype and already used in Lovd By Less. Following
these instructions will also greatly reduce the file size of the
javascript includes on your Lovd By Less install.


1. Install jRails, a drop-in jQuery replacement for Rails from
http://ennerchi.com/projects/jrails. jRails essentially re-routes
rails helpers to use jQuery instead of prototype.

On windows you would run the following in your Lovd By Less root
folder to install jRails:
ruby script\plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails


2. Modify the headers in your app\views\layouts\application.html.erb
file and app\views\layouts\plain.html.erb file to remove prototype/
scriptaculous and reference jQuery. I'm also using the google ajax API
to serve jQuery which reduces server load and allows for the
posibility of your user already having the library cached.

Your headers in the application.html.erb and plain.html.erb should
look like this:

<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.2.6");
google.load("jqueryui", "1.5.2");
</script>
<%= javascript_include_tag 'jrails', 'application', 'thickbox',
'truncator', :cache=>true %>


3. Modify your public\javascripts\application.js file and add the
following at the top:

// jQuery definition
jQuery.noConflict();
jq = jQuery;
$ = jQuery;
$$ = jQuery;


4. That's it, there's no step 4.


I'm new to Lovd by Less, and clicking around so far I haven't noticed
any issues with jRails. All of the effects seem to work. Long term it
would be great to re-write the RJS helpers as stand-alone javascipt,
but for now, this solution seems to work.

- Boris
http://www.borism.net

Caveman82

unread,
Aug 29, 2008, 1:14:36 PM8/29/08
to Lovd by Less
thanks Boris! This just happened to be on my todo list!

On Aug 27, 5:06 pm, Boris Masis <boris.ma...@gmail.com> wrote:
> Hi guys,
>
> I just did a little bit of work to remove prototype/scriptaculous from
> Lovd By Less and replace it with jQuery/jQuery UI. jQuery is much
> lighter than Prototype and already used in Lovd By Less. Following
> these instructions will also greatly reduce the file size of the
> javascript includes on your Lovd By Less install.
>
> 1. Install jRails, a drop-in jQuery replacement for Rails fromhttp://ennerchi.com/projects/jrails. jRails essentially re-routes
> rails helpers to use jQuery instead of prototype.
>
> On windows you would run the following in your Lovd By Less root
> folder to install jRails:
> ruby script\plugin installhttp://ennerchi.googlecode.com/svn/trunk/plugins/jrails

Boris Masis

unread,
Oct 14, 2008, 3:06:56 PM10/14/08
to Lovd by Less
One more thing, don't forget to restart your server after following
these steps :)

- Boris

On Aug 27, 5:06 pm, Boris Masis <boris.ma...@gmail.com> wrote:
> Hi guys,
>
> I just did a little bit of work to remove prototype/scriptaculous from
> Lovd By Less and replace it with jQuery/jQuery UI. jQuery is much
> lighter than Prototype and already used in Lovd By Less. Following
> these instructions will also greatly reduce the file size of the
> javascript includes on your Lovd By Less install.
>
> 1. Install jRails, a drop-in jQuery replacement for Rails fromhttp://ennerchi.com/projects/jrails. jRails essentially re-routes
> rails helpers to use jQuery instead of prototype.
>
> On windows you would run the following in your Lovd By Less root
> folder to install jRails:
> ruby script\plugin installhttp://ennerchi.googlecode.com/svn/trunk/plugins/jrails
Reply all
Reply to author
Forward
0 new messages