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', showDelay);
228 addEvent(lnk, 'mouseout', hideNiceTitle);
229 addEvent(lnk, 'focus', showDelay);
230 addEvent(lnk, 'blur', hideNiceTitle);
234 // 2003-03-25 Peter Janes
235 // do ins and del tags
236 var tags = new Array(2);
237 tags[0] = document.getElementsByTagName('ins');
238 tags[1] = document.getElementsByTagName('del');
239 for (var tt=0; tt<tags.length; tt++)
243 for (var ti=0; ti<tags[tt].length; ti++)
245 var tag = tags[tt][ti];
248 var strDate = tag.dateTime;
249 // HTML/ISO8601 date: yyyy-mm-ddThh:mm:ssTZD (Z, -hh:mm, +hh:mm)
250 var month = strDate.substring(5,7);
251 var day = strDate.substring(8,10);
260 var dtIns = new Date(strDate.substring(0,4), month-1, day, strDate.substring(11,13), strDate.substring(14,16), strDate.substring(17,19));
261 tag.setAttribute('nicetitle', (tt == 0 ? 'Added' : 'Deleted') + ' on ' + dtIns.toString());
262 addEvent(tag, 'mouseover', showDelay);
263 addEvent(tag, 'mouseout', hideNiceTitle);
264 addEvent(tag, 'focus', showDelay);
265 addEvent(tag, 'blur', hideNiceTitle);
272 function findPosition(oLink)
274 if (oLink.offsetParent)
276 for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent)
278 posX += oLink.offsetLeft;
279 posY += oLink.offsetTop;
285 return [oLink.x, oLink.y];
289 function getParent(el, pTagName)
295 // gecko bug, supposed to be uppercase
296 else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
302 return getParent(el.parentNode, pTagName);
306 // 2003-11-19 sidesh0w
307 // trailerpark wrapper function
308 function showDelay(e)
310 if (window.event && window.event.srcElement)
312 lnk = window.event.srcElement
314 else if (e && e.target)
320 // lnk is a textnode or an elementnode that's not ins/del
321 if (lnk.nodeType == 3 || (lnk.nodeType == 1 && lnk.tagName.toLowerCase() != 'ins' && lnk.tagName.toLowerCase() != 'del'))
323 // ascend parents until we hit a link
324 lnk = getParent(lnk, 'a');
327 delay = setTimeout("showNiceTitle(lnk)", interval * 1000);
330 // build and show the nice titles
331 function showNiceTitle(link)
333 if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE);
334 if (!document.getElementsByTagName) return;
336 nicetitle = lnk.getAttribute('nicetitle');
338 var d = document.createElementNS(XHTMLNS, 'div');
339 d.className = 'nicetitle';
340 var dc = document.createElementNS(XHTMLNS, 'div');
341 dc.className = 'nicetitle-content';
343 tnt = document.createTextNode(nicetitle);
344 pat = document.createElementNS(XHTMLNS, 'p');
345 pat.className = 'titletext';
346 pat.appendChild(tnt);
348 // 2003-11-18 Dunstan Orchard
349 // added in accesskey info
352 axs = document.createTextNode(' [' + lnk.accessKey + ']');
353 axsk = document.createElementNS(XHTMLNS, 'span');
354 axsk.className = 'accesskey';
355 axsk.appendChild(axs);
356 pat.appendChild(axsk);
362 tnd = document.createTextNode(lnk.href);
363 pad = document.createElementNS(XHTMLNS, 'p');
364 pad.className = 'destination';
365 pad.appendChild(tnd);
377 h = nicetitle.length;
380 if (nicetitle.length)
382 t = nicetitle.length;
388 if (h_pixels > STD_WIDTH)
392 else if ((STD_WIDTH>t_pixels) && (t_pixels>h_pixels))
396 else if ((STD_WIDTH>t_pixels) && (h_pixels>t_pixels))
405 d.style.width = w + 'px';
407 mpos = findPosition(lnk);
411 d.style.left = (mx+15) + 'px';
412 d.style.top = (my+35) + 'px';
414 if (window.innerWidth && ((mx+w) > window.innerWidth))
416 d.style.left = (window.innerWidth - w - 25) + 'px';
418 if (document.body.scrollWidth && ((mx+w) > document.body.scrollWidth))
420 d.style.left = (document.body.scrollWidth - w - 25) + 'px';
423 document.getElementsByTagName('body')[0].appendChild(d);
425 CURRENT_NICE_TITLE = d;
428 function hideNiceTitle(e)
430 // 2003-11-19 sidesh0w
432 if (delay) clearTimeout(delay);
433 if (!document.getElementsByTagName) return;
434 if (CURRENT_NICE_TITLE)
436 document.getElementsByTagName('body')[0].removeChild(CURRENT_NICE_TITLE);
437 CURRENT_NICE_TITLE = null;
441 addEvent(window, "load", floatImages);
442 addEvent(window, "resize", floatImages);
443 addEvent(window, "load", blockquoteCite);
444 addEvent(window, "load", insdelCite);
445 addEvent(window, "load", noAltTooltip);
446 addEvent(window, "load", makeNiceTitles);
448 // I'm very poor in JavaScript. Please correct me if I'm wrong.