Completely true.
"Unobstrusive" JS is nice for bigger things, but in many situations
it's overengineering.
I also kind of dislike the definition of this as "unobstrusive". If
you name a programming technique in a negative way, you're
automatically saying that other ways of achieving the result are
worse. Which they aren't in this case.
Both approaches are valid. I presonally tend to use both at the same
time, external JS when I need something in more than one place, and
inline stuff if it's just a quick fire and forget thing (when "coding
by hand", as opposed to using things like the Rails UJS plugin). I
also concur with Tom that your LOC count is a good measuring device
for this.
-Thomas
Am 14.09.2006 um 18:21 schrieb Tom Gregory:
>
> Ya know, I see comments like this fairly regularly on the list, and
> it's starting to grate a bit.
>
> There is nothing wrong with doing it the way he did. It's faster to
> code when coding by hand. It will respond to events as soon as it's
> displayed rather than after the entire page has loaded. Etc., etc.
>
> Yes, you are correct that current practice is to separate behavior
> from semantic meaning and meta-data. Yes, coding in a consistent
> style through multiple projects makes code easier to revisit. Yes,
> all of the (blee/lead)ding edge standards go so far as to suggest all
> js be in a separate file. In all of this, we forget that the "old
> ways" still work. You see, you took 5 lines to accomplish what he did
> with an inline handler.
>
> Sometimes quick and dirty is just fine (especially with an older
> DOCTYPE). Let's not be too zealous about it.
>
>
> TAG
>
> On Sep 14, 2006, at 9:58 AM, Christophe Porteneuve aka TDD wrote:
>
>>
>> Hey again,
>>
>> [EMAIL PROTECTED] a écrit :
>>> <a href="#" onclick="Effect.toggle('d3','appear'); return
>>> false;">Toggle appear</a>
>>
>> BTW, this code is, well... 'could be better, I guess, is a nice
>> way to
>> qualify it. First, the "return false" thing is dead. Dead, dead,
>> dead.
>> Second, you shouldn't put JS events in your HTML like that; you
>> should
>> use unobstrusive JS.
>>
>> For instance, you should assign this link an ID, then observe it
>> from an
>> external script file, with something such as:
>>
>>
>> function toggleLink(e) {
>> Event.stop(e);
>> Effect.toggle('d3', 'appear', { duration: 0.5 });
>> } // toggleLink
>>
>> Event.observe('yourLinkId', 'click', toggleLink);
>>
>> If you wish to reuse the toggleLink function on multiple links, for
>> multiple DIVs, you can:
>>
>> function toggleLink(e, containerId) {
>> Event.stop(e);
>> Effect.toggle(containerId, 'appear', { duration: 0.5 });
>> }
>>
>> Event.observe('yourLinkId', 'click',
>> toggleLink.bindAsEventListener('d3');
>> ...
>>
>> --
>> Christophe Porteneuve aka TDD
>> [EMAIL PROTECTED]
>>
>>>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---