i am dustin diaz

a JavaScriptr...

boosh.

don't worry about it.

Enhance your Sweet Titles

Now although I've promised myself I wouldn't be releasing anymore updates to the Sweet Titles package, but I thought I'd post one little trick for those wanting personalize them for your own website. Of course there are endless hacks you can do to the script to make it your own (which is what this is all about!), so here is one of mine.

Clip internal URL's

One thing I'll definitely be adding to this site within due time is this little modification which will trim your host name from the 'href' inside the toolTip. This is extreamly helpful for internal links - those links that point to other parts of your own website. First things first, locate this line within the tipShow() method

tipShow() method of the sweetTitles Object

if ( anch.nodeName.toLowerCase() == 'a' ) {

... code here

} // end of if statement
And now what we're going to do is replace the entire block with the following piece of code:

Replacement code for Sweet Titles

if ( anch.nodeName.toLowerCase() == 'a' ) {

	var host = location.hostname.toString();

	var pattern = new RegExp("(http://?)"+host,"gi");

	var fullPath = anch.href.toString();

	var path = fullPath.replace(pattern,'');

	addy = (path.length > 25 ? path.toString().substring(0,25)+"..." : path);

	var access = ( anch.accessKey ? " ["+anch.accessKey+"]" : "" );

}
With the above code, we've now trimmed out URL's that would have looked like this:
  • http://www.dustindiaz.com/udasss/
  • http://dustindiaz.com/sweet-titles/
  • http://www.dustindiaz.com/downloads/ajax-contact.zip
to look like this:
  • /udasss/
  • /sweet-titles/
  • /downloads/ajax-contact.zip

Which in practicality, is all you need to know! Anyone else want to share a tip? Please post code on your own sandBox, and not in the comments (it'll look ugly and I don't feel like playing clean up).

this is who i am

Hi, my name is Dustin Diaz and I'm an Engineer @ObviousCorp. Previously @Twitter, @Google, and @Yahoo, author of Strobist® Info co-author of JavaScript Design Patterns, co-creator of the Ender JavaScript Framework, a Photographer, and an amateur Mixologist. This is my website. Welcome!

On this site I write about JavaScript. You can also follow along with my open-source work on Github.

This site is optimized and works best in Microsoft Internet Explorer 6.