Yehuda Katz wrote:
> 1) Are you using Rails?
Yes :-)
> 3) Would you prefer an approach that generated JS by writing Ruby
> helpers that generated jQuery code, or an approach that made is easier
> to link up existing jQuery code into Rails?
> 4) If you've used jQuery with Rails, what issues have you run into
I'd prefer not to have helpers that generate js -- I can write javascript
myself. I'd rather see
the integration issues solved. One of the best things about rails is that it
lets you bypass all
the magic when you need to. Helpers (i.e. form_remote, etc.) can't handle every
situation, so
having accessible building blocks is crucial to me.
I realize there is a group of people who'd like to just write everything in
Ruby (i.e. get to
use javascript without having to know javascript), but I think that's a red
herring. Plus, those
concerns can be addressed by more complicated helpers, built on the more basic
ones.
Here are the main issues I've run into:
+ unobtrusively including js specific to a view
+ targeting elements on a page without adding ID's all over the place
+ concatenation, compression and caching (i.e. cache the packed version of a
bunch of scripts)
I think what I'd like (ideally) would be a basic helper (that wouldn't even
need to be
jQuery-specific) that I could call from any view which would concatenate,
compress, and cache
(fragment cache? page cache?) bits of javascript or javascript files, and add a
<script
src="..."></script> tag to the <head>. If you have a plugin (or some custom
code in an external
file) that you only use in a few places, you could include it alongside inline
script (if it was
more widely used, it would go in your application-wide js file).
So, in whatever.rhtml, do something like:
<% javascript :file => 'path/to/plugin.js' %>
<% javascript :text => %{ $('p').css('color','blue'); } %>
<p>Whatever...</p>
<% javascript :text => %{ $('p').css('font-size', '2em'); }% %>
And get:
<html>
<head>
<script type="text/javascript" src="whatever.js"></script>
</head>
<body>
<p>Whatever...</p>
</body>
</html>
In a way, what I'm picturing is very jQuery-centric -- there's a core utility,
plus plugins
(i.e. more complex, task-specific helpers).
Luke
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/