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