1 // from http://www.kryogenix.org
2 // by Scott Andrew - http://scottandrew.com
3 // add an eventlistener to browsers that can do it somehow.
4 function addEvent(obj, evType, fn)
6 if (obj.addEventListener)
8 obj.addEventListener(evType, fn, false);
11 else if (obj.attachEvent)
13 var r = obj.attachEvent('on'+evType, fn);
22 function floatImages()
24 // adapted from http://www.dithered.com/javascript/browser_detect/
25 //**************************************************************//
27 var userAgent = navigator.userAgent.toLowerCase();
29 // if Mozilla 1.4 then quit
30 if ((userAgent.indexOf('gecko') != -1) && (userAgent.indexOf('gecko/') + 14 == userAgent.length) && (parseFloat(userAgent.substring(userAgent.indexOf('rv:') + 3)) == '1.4')) return;
33 if (document.all && window.Event) return;
34 //**************************************************************//
36 // check this browser can cope with what we want to do
37 if (!document.getElementById) return;
38 var blogDiv = document.getElementById('blog');
40 if (!blogDiv.offsetWidth) return;
42 blogDiv.className = (blogDiv.offsetWidth >= 500) ? "float-images" : "block-images";
45 // Blockquote citations
47 // Simon Willison's work:
48 // http://simon.incutio.com/archive/2002/12/20/#blockquoteCitations
50 // Also Dunstan Orchard's work:
51 // http://1976design.com/blog/archive/2003/11/10/updates/
52 function blockquoteCite()
54 if (!document.createElementNS)
56 document.createElementNS = function(ns, elt)
58 return document.createElement(elt);
61 quotes = document.getElementsByTagName('blockquote');
62 for (i = 0; i < quotes.length; i++)
64 var cite = quotes[i].getAttribute('cite');
65 // value of cite attribute should only contain URI, not any other
66 if ((cite) && (cite != ''))
68 newlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
69 newlink.setAttribute('href', cite);
70 newlink.className = 'cite-link';
71 newlink.appendChild(document.createTextNode(cite));
72 newdiv = document.createElementNS('http://www.w3.org/1999/xhtml', 'cite');
73 newdiv.className = 'blockquote-cite';
74 newdiv.appendChild(document.createTextNode('Source: '));
75 newdiv.appendChild(newlink);
76 quotes[i].appendChild(newdiv);
77 quotes[i].removeAttribute('cite');
82 // Ins and Del tags citations
85 if (!document.createElementNS)
87 document.createElementNS = function(ns, elt)
89 return document.createElement(elt);
92 var insdel = new Array(2);
93 insdel[0] = document.getElementsByTagName('ins');
94 insdel[1] = document.getElementsByTagName('del');
95 for (var i=0; i<insdel.length; i++)
99 for (var id=0; id<insdel[i].length; id++)
101 var isdl = insdel[i][id].getAttribute('cite');
102 if ((isdl) && (isdl != ""))
104 idlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
105 idlink.setAttribute('href', isdl);
106 idlink.className = 'cite-link ' + (i == 0 ? 'ins-cite' : 'del-cite');
107 idlink.setAttribute('title','citation of ' + (i == 0 ? 'added' : 'deleted') + ' text');
108 idlink.appendChild(document.createTextNode('#'));
109 insdel[i][id].appendChild(idlink);
110 insdel[i][id].removeAttribute('cite');
117 // Force IE not to show alternate text as tooltip
118 function noAltTooltip()
120 images = document.getElementsByTagName('img');
121 for (var i = 0; i < images.length; i++)
123 var title = images[i].getAttribute('title');
124 var alt = images[i].getAttribute('alt');
125 if ((document.all) && (alt) && (!title))
127 images[i].setAttribute('title', '');
134 // original code by Stuart Langridge 2003-11
135 // with additions to the code by other good people
136 // http://www.kryogenix.org/code/browser/nicetitle/
139 // modified by Peter Janes 2003-03-25
140 // http://peterjanes.ca/blog/archives/2003/03/25/nicetitles-for-ins-and-del
141 // added in ins and del tags
143 // modified by Dunstan Orchard 2003-11-18
144 // http://1976design.com/blog/
145 // added in accesskey information
146 // tried ever-so-hard, but couldn't work out how to do what Ethan did
148 // final genius touch by by Ethan Marcotte 2003-11-18
149 // http://www.sidesh0w.com/
150 // worked out how to delay showing the popups to make them more like the browser's own
153 var XHTMLNS = 'http://www.w3.org/1999/xhtml';
154 var CURRENT_NICE_TITLE;
157 var browser = new Browser();
159 // determine browser and version.
168 ua = navigator.userAgent;
171 if ((i = ua.indexOf(s)) >= 0)
174 this.version = parseFloat(ua.substr(i + s.length));
179 if ((i = ua.indexOf(s)) >= 0)
182 this.version = parseFloat(ua.substr(i + s.length));
186 // treat any other 'Gecko' browser as NS 6.1.
188 if ((i = ua.indexOf(s)) >= 0)
196 // 2003-11-19 sidesh0w
197 // set delay vars to emulate normal hover delay
201 // this function runs on window load
202 // it runs through all the links on the page as starts listening for actions
203 function makeNiceTitles()
205 if (!document.createElement || !document.getElementsByTagName) return;
206 if (!document.createElementNS)
208 document.createElementNS = function(ns, elt)
210 return document.createElement(elt);
217 document.links = document.getElementsByTagName('a');
219 for (var ti=0; ti<document.links.length; ti++)
221 var lnk = document.links[ti];
222 // * I added specific class names here..
225 lnk.setAttribute('nicetitle', lnk.title);
226 lnk.removeAttribute('title');
227 addEvent(lnk, 'mouseover', showNiceTitle);
228 addEvent(lnk, 'mousemove', moveNiceTitle);
229 addEvent(lnk, 'mouseout', hideNiceTitle);
230 addEvent(lnk, 'focus', showNiceTitle);
231 addEvent(lnk, 'blur', hideNiceTitle);
235 // 2003-03-25 Peter Janes
236 // do ins and del tags
237 var tags = new Array(2);
238 tags[0] = document.getElementsByTagName('ins');
239 tags[1] = document.getElementsByTagName('del');
240 for (var tt=0; tt<tags.length; tt++)
244 for (var ti=0; ti<tags[tt].length; ti++)
246 var tag = tags[tt][ti];
249 var strDate = tag.dateTime;
250 // HTML/ISO8601 date: yyyy-mm-ddThh:mm:ssTZD (Z, -hh:mm, +hh:mm)
251 var month = strDate.substring(5,7);
252 var day = strDate.substring(8,10);
261 var dtIns = new Date(strDate.substring(0,4), month-1, day, strDate.substring(11,13), strDate.substring(14,16), strDate.substring(17,19));
262 tag.setAttribute('nicetitle', (tt == 0 ? 'Added' : 'Deleted') + ' on ' + dtIns.toString());
263 addEvent(tag, 'mouseover', showNiceTitle);
264 addEvent(tag, 'mousemove', moveNiceTitle);
265 addEvent(tag, 'mouseout', hideNiceTitle);
266 addEvent(tag, 'focus', showNiceTitle);
267 addEvent(tag, 'blur', hideNiceTitle);
274 function findPosition(oLink)
276 if (oLink.offsetParent)
278 for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent)
280 posX += oLink.offsetLeft;
281 posY += oLink.offsetTop;
287 return [oLink.x, oLink.y];
291 function getParent(el, pTagName)
297 // gecko bug, supposed to be uppercase
298 else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
304 return getParent(el.parentNode, pTagName);
308 // 2003-11-19 sidesh0w
309 // trailerpark wrapper function
312 if (CURRENT_NICE_TITLE)
314 CURRENT_NICE_TITLE.style.display = '';
318 // build and show the nice titles
319 function showNiceTitle(e)
321 if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE);
322 if (!document.getElementsByTagName) return;
324 if (window.event && window.event.srcElement)
326 lnk = window.event.srcElement
328 else if (e && e.target)
334 // lnk is a textnode or an elementnode that's not ins/del
335 if (lnk.nodeType == 3 || (lnk.nodeType == 1 && lnk.tagName.toLowerCase() != 'ins' && lnk.tagName.toLowerCase() != 'del'))
337 // ascend parents until we hit a link
338 lnk = getParent(lnk, 'a');
341 nicetitle = lnk.getAttribute('nicetitle');
343 var d = document.createElementNS(XHTMLNS, 'div');
344 d.className = 'nicetitle';
345 var dc = document.createElementNS(XHTMLNS, 'div');
346 dc.className = 'nicetitle-content';
348 tnt = document.createTextNode(nicetitle);
349 pat = document.createElementNS(XHTMLNS, 'p');
350 pat.className = 'titletext';
351 pat.appendChild(tnt);
353 // 2003-11-18 Dunstan Orchard
354 // added in accesskey info
357 axs = document.createTextNode(' [' + lnk.accessKey + ']');
358 axsk = document.createElementNS(XHTMLNS, 'span');
359 axsk.className = 'accesskey';
360 axsk.appendChild(axs);
361 pat.appendChild(axsk);
367 tnd = document.createTextNode(lnk.href);
368 pad = document.createElementNS(XHTMLNS, 'p');
369 pad.className = 'destination';
370 pad.appendChild(tnd);
382 h = nicetitle.length;
385 if (nicetitle.length)
387 t = nicetitle.length;
393 if (t_pixels > STD_WIDTH)
397 else if ((STD_WIDTH > t_pixels) && (t_pixels > h_pixels))
401 else if ((STD_WIDTH > h_pixels) && (h_pixels > t_pixels))
410 d.style.width = w + 'px';
411 d.style.display = 'none';
413 document.getElementsByTagName('body')[0].appendChild(d);
415 CURRENT_NICE_TITLE = d;
419 delay = setTimeout("showDelay()", interval * 1000);
422 function moveNiceTitle(e)
424 if (!document.getElementsByTagName) return;
425 if (!CURRENT_NICE_TITLE) return;
429 X = document.body.scrollLeft + window.event.clientX;
431 else if (document.layers || document.getElementById)
435 w_title = Number(CURRENT_NICE_TITLE.style.width.replace(/^(\d+).*$/, '$1'));
436 if (w_title + X > (window.innerWidth + (document.documentElement.scrollLeft || window.pageXOffset) - 20))
438 X = (window.innerWidth + (document.documentElement.scrollLeft || window.pageXOffset) - 20) - w_title;
443 Y = document.body.scrollTop + window.event.clientY;
445 else if (document.layers || document.getElementById)
449 if (Y > (window.innerHeight + (document.documentElement.scrollTop || window.pageYOffset) - 60))
454 CURRENT_NICE_TITLE.style.left = X + 'px';
455 CURRENT_NICE_TITLE.style.top = (Y + 25) + 'px';
458 function hideNiceTitle(e)
460 // 2003-11-19 sidesh0w
462 if (delay) clearTimeout(delay);
463 if (!document.getElementsByTagName) return;
464 if (CURRENT_NICE_TITLE)
466 document.getElementsByTagName('body')[0].removeChild(CURRENT_NICE_TITLE);
467 CURRENT_NICE_TITLE = null;
471 addEvent(window, "load", floatImages);
472 addEvent(window, "resize", floatImages);
473 addEvent(window, "load", blockquoteCite);
474 addEvent(window, "load", insdelCite);
475 addEvent(window, "load", noAltTooltip);
476 addEvent(window, "load", makeNiceTitles);
478 // I'm very poor in JavaScript. Please correct me if I'm wrong.