Enhance your Sweet Titles
Now although I've promised myself I wouldn't be releasing anymore updates to theSweet Titlespackage, 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() methodtipShow() 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
- /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).
recent
- Matador: The Obvious MVC Framework for Node
- Sandboxing JavaScript
- Crouching Ender, hidden command
- Ender.js - The open submodule library
- Qwery - The Tiny Selector Engine
- Klass
- Smallest DOMReady code, ever.
- $script.js - Another JavaScript loader
- About that slowness on Twitter...
- Autocomplete Fuzzy Matching
- JavaScript Cache Provider
- JavaScript Animate
- Asynchronous method queue chaining in JavaScript
- Something changed
- Unofficial Twitter Widget Documentation
i am dustin diaz

