jQuery and CE

8 views
Skip to first unread message

moritz

unread,
Feb 23, 2009, 7:30:38 PM2/23/09
to CommunityEngine
It's been asked before w/o answers, so I'll try as well.

How much and where does CE make use of Prototype?

What is the feasibility of using jQuery in addition to / instead of
Prototype?

Thanks in advance for sharing your knowledge.

Chris Lee

unread,
Feb 23, 2009, 7:59:01 PM2/23/09
to communi...@googlegroups.com
It seems CE makes use of Rails' js helpers in many places. The default helpers, of course, rely on Prototype. However, you can safely use JQuery along with Prototype, calling JQuery fuctions and plugins where you need to and leaving CE's Prototype use as is.

The easy way to do this is JQuery's noConflict method, which allows you to override JQuery's default selector ($, which conflicts with Prototype's). Here's the example taken straight from the JQuery docs (http://docs.jquery.com/Using_jQuery_with_Other_Libraries):


<html>
<head>
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();

// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});

// Use Prototype with $(...), etc.
$('someid').hide();
</script>
</head>
<body></body>
</html>

Bruno Bornsztein

unread,
Feb 23, 2009, 8:04:07 PM2/23/09
to communi...@googlegroups.com
CE uses prototype a fair amount (although not excessive). All the ajax functionality, autocompletes, and lightboxes use it, as well as the UI for polls, managing photos (the custom tinyMCE photo uploader). Like Chris said, you can safely us jQuery in addition, but replacing Prototype altogether would require a little work (if someone wants to do it and can convince me it'd be better to have jQuery, I'm all ears).

Thanks,
Bruno

moritz

unread,
Feb 24, 2009, 1:18:07 AM2/24/09
to CommunityEngine
Thank you. That is very helpful.

Rj

unread,
Feb 28, 2009, 11:55:15 PM2/28/09
to CommunityEngine
On Feb 24, 10:04 am, Bruno Bornsztein <bruno.bornszt...@gmail.com>
wrote:
> CE uses prototype a fair amount (although not excessive). All the ajax
> functionality, autocompletes, and lightboxes use it, as well as the UI for
> polls, managing photos (the custom tinyMCE photo uploader). Like Chris said,
> you can safely us jQuery in addition, but replacing Prototype altogether
> would require a little work (if someone wants to do it and can convince me
> it'd be better to have jQuery, I'm all ears).

Do you explicitly call Prototype, or use Rails' helpers? I'm
wondering if jRails would help in moving CE to jQuery. jRails is a
drop-in jQuery replacement for Prototype/script.aculo.us,
http://ennerchi.com/projects/jrails gives details of the functions
that jRails takes care of but I'll list them below too, for
simplicity.

We have an existing site in production that uses jQuery and don't
really want to re-write that to Prototype (re-writing it to serve both
seems even more painful) but are interested in plugging-in CE, if we
can work out a practical method.

Any estimates on what value "a little" has in the expression
"replacing Prototype altogether would require a little work"?

Rj

jRails provides drop-in functionality for these existing Rails
methods:

* Prototype
form_remote_for, form_remote_tag, link_to_, observe_field,
observe_form, periodically_call_remote, remote_form_for,
submit_to_remote

* Scriptaculous
draggable_element, drop_receiving_element, sortable_element,
visual_effect

* RJS
hide, insert_html, remove, replace, replace_html, show, toggle

* Visual effects
Appear, Fade, Puff, BlindDown, BlindUp, BlindRight, BlindLeft,
SwitchOff, SwitchOn, SlideDown, SlideUp, DropIn, DropOut, Shake,
Pulsate, Squish, Fold, FoldOut, Grow, Shrink, Highlight.

Bruno Bornsztein

unread,
Mar 2, 2009, 4:52:04 PM3/2/09
to communi...@googlegroups.com
Do you explicitly call Prototype, or use Rails' helpers?  
Both.
 
We have an existing site in production that uses jQuery and don't
really want to re-write that to Prototype (re-writing it to serve both
seems even more painful) but are interested in plugging-in CE, if we
can work out a practical method.
The bigger issue is that switching to jQuery will leave out people who use Prototype (in the same way that jQuery folks are currently inconvenienced). So I'd like to hear some more arguments why jQuery is better before agreeing to switch over. Just the fact that some users prefer it isn't that convincing (some will always prefer Prototype).

Thanks,
Bruno

Rj

unread,
Mar 2, 2009, 7:00:28 PM3/2/09
to CommunityEngine
On Mar 3, 6:52 am, Bruno Bornsztein <bruno.bornszt...@gmail.com>
wrote:
> > Do you explicitly call Prototype, or use Rails' helpers?
>
> Both.

That's annoying :) How much hand-coded Prototype is there?


> > We have an existing site in production that uses jQuery and don't
> > really want to re-write that to Prototype (re-writing it to serve both
> > seems even more painful) but are interested in plugging-in CE, if we
> > can work out a practical method.
>
> The bigger issue is that switching to jQuery will leave out people who use
> Prototype (in the same way that jQuery folks are currently inconvenienced).
> So I'd like to hear some more arguments why jQuery is better before agreeing
> to switch over. Just the fact that some users prefer it isn't that
> convincing (some will always prefer Prototype).

I don't want to start an argument about that. We obviously have our
reasons for using jQuery (download size, project momentum) but
Prototype is certainly the incumbent in Rails. I don't know if a
project that is designed to plug into existing websites should make a
choice like that just yet. It's more work but probably it is a better
idea -- certainly more inclusive -- to leverage projects like jRails
and try to support both.

Rj

Bruno Bornsztein

unread,
Mar 2, 2009, 10:57:06 PM3/2/09
to communi...@googlegroups.com
On Mon, Mar 2, 2009 at 6:00 PM, Rj <ahr...@gmail.com> wrote:

On Mar 3, 6:52 am, Bruno Bornsztein <bruno.bornszt...@gmail.com>
wrote:
> > Do you explicitly call Prototype, or use Rails' helpers?
>
> Both.

That's annoying :)  How much hand-coded Prototype is there?
Not a ton. That I can think of, the lightboxes, some of the swfupload stuff, and the tinyMCE photo uploader plugin. A lot of the prototype stuff could be replaced with rails helpers, which could then be substituted with jRails.

From a quick look in community_enginge's javascripts dir:

application.js - most of this related to the homepage features display, which isn't even used, so it could likely be cut down
carousel.js - ditto above, I think any javascript-y display of features should be left to each user's impementation
forum.js - this is used pretty heavily in the forums area
glider.js - used for homepage features display, see above
handlers.js - used for swfupload, this would need to stay
lightbox.js - I wrote this lightbox script a long time ago, I'm sure there are better ones out there now.
prototip.js - used for the user-menu, this could really be done with CSS, I think.
rounder.js - not used in the default them, was originally used for rounded corners.
scrapbooker.js - used for the clippings bookmarklet functionality, this needs to stay
uploader.js - used for swfupload


A quick search for $(' shows there are about twenty templates that have some prototype-looking javascript in them.

I don't want to start an argument about that.  We obviously have our
reasons for using jQuery (download size, project momentum) but
Prototype is certainly the incumbent in Rails.  I don't know if a
project that is designed to plug into existing websites should make a
choice like that just yet.  It's more work but probably it is a better
idea -- certainly more inclusive -- to leverage projects like jRails
and try to support both.
 
Agreed. Prototype vs. jQuery is an argument for a different list. I like your idea of trying to use the Rails helpers as much as possible, that makes both frameworks easier to plug in.
 


Rj


moritz

unread,
Mar 6, 2009, 9:02:01 PM3/6/09
to CommunityEngine
I've tried your suggestion and some others from the jQuery page, but I
keep getting an exception in Firebug on line 871 of jquery-1.2.6.js

[Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult:
"0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://localhost:3000/javascripts/jquery-1.2.6.js?1231867032 ::
anonymous :: line 871" data: no]
var computedStyle = defaultView.getComputedStyle( elem, null );

Any clue why that could be happening?

I also don't get the jQuery behavior that I'm expecting.

On Feb 23, 4:59 pm, Chris Lee <chrislee1...@yahoo.com> wrote:

Gabriel Medina (Rha7.Com desde GMail)

unread,
Mar 7, 2009, 12:47:25 AM3/7/09
to communi...@googlegroups.com
Can you show or paste the code you're using?

Gabriel Medina (Rha7.Com desde GMail)

unread,
Mar 7, 2009, 12:58:51 AM3/7/09
to communi...@googlegroups.com
What versions of prototype and scriptaculous and jquery are you using?

Probably you need to upgrade prototype/scriptaculous to the latest version.

Watch this:
Versions Conflict

Greetings,

Gabriel M.

moritz

unread,
Mar 7, 2009, 5:52:00 PM3/7/09
to CommunityEngine
This is from the _scripts_and_styles.html.haml in my project. I
haven't had a chance to isolate and reproduce the issue.

= javascript_include_tag "jquery-1.2.6"
= javascript_include_tag "prototype", :plugin => "community_engine"
...

= javascript_include_tag "hoverIntent.min"
= javascript_include_tag "superfish"
%script{ :type => "text/javascript" }
jQuery(document).ready(function(){
jQuery("ul.sf-menu").superfish({
autoArrows: false,
dropShadows: false,
delay: 800,
pathClass: 'current'
});

jQuery(".collapsible_content").hide();
jQuery(".collapsible_head").click(function()
{
jQuery(this).parent("div").next(".collapsible_content").slideToggle
("fast");
});
});


On Mar 6, 9:47 pm, "Gabriel Medina (Rha7.Com desde GMail)"

moritz

unread,
Mar 29, 2009, 8:47:55 PM3/29/09
to CommunityEngine
Thank you. I finally got around to test it with prototype 1.6.0.3 and
the libraries from script.aculo.us 1.8.2 and it works.

On Mar 6, 10:58 pm, "Gabriel Medina (Rha7.Com desde GMail)"
<rha7....@gmail.com> wrote:
> What versions of prototype and scriptaculous and jquery are you using?
>
> Probably you need to upgrade prototype/scriptaculous to the latest version.
>
> Watch this:
> Versions Conflict<http://groups.google.com/group/jquery-en/browse_thread/thread/69cb41d...>
>
> Greetings,
>
> Gabriel M.
>

Levi Rosol

unread,
Feb 10, 2010, 11:36:48 AM2/10/10
to communi...@googlegroups.com
some interesting stats about the various js libraries:

http://www.google.com/trends?q=jquery%2C+yui%2C+dojo%2C+mootools%2C+scriptaculous&ctab=0&geo=all&date=all&sort=0

I have not used any of the js frameworks extensively, however, it seems that jQuery has a much larger plugin library, and overall, seems to be more widely used.

--
Levi Rosol
Twitter: @LeviRosol



>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CommunityEngine" group.
To post to this group, send email to communi...@googlegroups.com
To unsubscribe from this group, send email to communityengi...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/communityengine?hl=en
-~----------~----~----~----~------~----~------~--~---


Bruno Bornsztein

unread,
Feb 10, 2010, 12:48:56 PM2/10/10
to communi...@googlegroups.com
I'm in favor of moving to jQuery, my thinking is that this will be easiest to do when we do the upgrade to Rails 3.

--
You received this message because you are subscribed to the Google Groups "CommunityEngine" group.
To post to this group, send email to communi...@googlegroups.com.
To unsubscribe from this group, send email to communityengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/communityengine?hl=en.

Levi Rosol

unread,
Feb 10, 2010, 1:03:45 PM2/10/10
to communi...@googlegroups.com
awesome! this will make life a lot easier.

So, with that said, what needs to be done, and how can we help? We are planning to update SportLeeg to edge soon (so we can get the API calls in place), so at that point we could help out with the effort. I don't think it's something we want to lead though.

Is there a date when rails 3 is set to come out of beta? Are you planning to wait until then before upgrading CE? I did skim an article the other day saying swapping out proto with jQuery is fairly simple with the new plugin architecture of rails 3.

--
Levi Rosol
Twitter: @LeviRosol



Bruno Bornsztein

unread,
Feb 11, 2010, 2:43:08 PM2/11/10
to communi...@googlegroups.com
 
So, with that said, what needs to be done, and how can we help? We are planning to update SportLeeg to edge soon (so we can get the API calls in place), so at that point we could help out with the effort. I don't think it's something we want to lead though.

Not really sure yet. I'll probably start looking at it when I start looking at upgrading to Rails 3. I won't wait until Rails 3 is out of beta to update CE, but I would suggest holding off on the jQuery stuff until the (larger) Rails 3 migration is complete.

Thanks,
Bruno


rubybox

unread,
Feb 23, 2010, 6:27:41 PM2/23/10
to CommunityEngine
Jrails is not advised for it is non degradable,

There are several projects to have jquery code like nativy ruby code,
so you can just
write ror for your javascript and get cleaner syntax, netzke is one of
these projects if I remember correctly.
This would be a welcome addition to any app that needs jquery, perhaps
someone with more knowledge
expierience on this topic can share some light on " the best jquery
implementation for ror "

On Feb 11, 8:43 pm, Bruno Bornsztein <bruno.bornszt...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages