I've been using jquery and think it's awesome. Here's a snippet that lets
you apply events unobtrusively like CSS (like lowpro):
var initEvents = function(behaviors){
/* Add behaviors to the document when it's ready */
$(document).ready(function(){
var ruleAndEvent, rule, event, key, fn;
for(key in behaviors){
fn = behaviors[key];
ruleAndEvent = key.split(":");
rule = ruleAndEvent[0];
event = ruleAndEvent[1];
$(rule)[event](fn);
}
});
}
You can use it like this:
initEvents({
'a.alert_hello_world:click': function(event){
alert("Hello World!"); event.preventDefault();
},
'p.hide_myself:click': function() {
// this refers to the paragraph being clicked
$(this).hide();
}
});
Also check out the 'livequery' plugin, which attaches events to
updated DOM elements.
Unobtrusive JS is a LOT easier to maintain with lots of JS code. It's
kind of like keeping all your
CSS in external files instead of doing them inline. There are other
benefits too, like being easier
to degrade if the user doesn't have JS activated and browser caching.
- Hugh
On Jan 30, 2008 12:05 AM, Matt Aimonetti <[EMAIL PROTECTED]> wrote:
> Some of you has some specific questions about RSpec and autotest, here are
> some answers:
>
> http://railsontherun.com/2008/1/30/misc-tips-and-tricks
>
> FYI, Lowpro is being ported to JQuery, anyone using JQuery and wants to
> tell us more about why and how? What about Unobtrusive Javascript, I know
> that Ryan started doing some, anyone else?
>
> -Matt
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---