| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
senior member
Join Date: Sep 2005
Location: auckland, nz
Posts: 274
|
core.js / common.js / library.js / base.js
Inspired largely by this article from dustin diaz http://www.dustindiaz.com/top-ten-javascript I was wondering what little indispensible bits of javascript does everybody have in their core.js / common.js / library.js / base.js ? heres one I always use: Code:
handy little script for those using strict doc types simply adds target="_blank" to all links with class name "external". |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,076
|
Always the top 3, and sometimes 4 and 5. - Breakout of Frames - XHTML 1.0 Strict External Links (rel tag) - SWFObject - GoogleMaps - Lightbox JS 2 Technically you should be using the "rel" tag, as what you are doing is behavioural and not presentational. Also allows you to use the "class" tag properly if required. |
|
|
|
#3 (permalink) |
|
senior member
Join Date: Sep 2005
Location: auckland, nz
Posts: 274
|
good spot, I use the class attribute as I can target such links through the css aswell as the js. For example, using a css background-image I normally give each external link a small icon to indicate that it will open in a new window - instead of having to set both the rel and class attributes to "external", i just set the class. Admittedly it's a little lazy, but it saves a bit of time... however, i'm not convinced the rel attribute is correct either. Somebody pointed this solution in an old post: http://www.456bereastreet.com/archiv...pt_version_11/ heres another useful little script, for targetting elements via css selectors: http://simon.incutio.com/archive/200...entsBySelector |
|
|
|
#4 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,076
|
Fair point, just thought id point it out incase one day you got stuck being unable to style a certain link differently, and you may of had more than one of them so you couldnt use ID. Nevermind In your first post, the link had "event" stuff. What is the add event? is that to replace the need for body onload therefore separating more of the JS from the XHTML? |
|
|
|
#5 (permalink) |
|
senior member
Join Date: Sep 2005
Location: auckland, nz
Posts: 274
|
the addEvent() and addLoadEvent() functions simply manage all your functions that are attached to the onload event - very useful if you have multiple functions. As the onload event handler can only hold one function at a time, addEvent() and addLoadEvent() effectively creates a queue of functions to be executed in order when the page loads. For external links i use the icon suggested in css mastery - its on the cover of the book http://www.cssmastery.com/ |
|
|
|
#6 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,076
|
just had yet another brain fart. Use "rel", then in the script get it to change the class (for the icon) and title (opens in new window text) attributes! That way you only have to set the rel, and hopefully you wont need to use the "class" element, and if they have JS disabled they dont see the open in new window stuff, so it doesnt look silly! |
|
|
|
#7 (permalink) | |
|
Barney army!
Join Date: Mar 2003
Location: London
Posts: 696
|
Quote:
Class is just as appropriate for behaviour as it is presentation. Luke Redpath .::. Software Engineer .::. Reevoo - Real Reviews From Real Customers
|
|
|
|
|
#8 (permalink) | |
|
Barney army!
Join Date: Mar 2003
Location: London
Posts: 696
|
Quote:
Dont forget elements can have multiple classes. Luke Redpath .::. Software Engineer .::. Reevoo - Real Reviews From Real Customers
|
|
|
![]() |