| [ Index ] |
|
Code source de e107 0.7.8 |
1 function setActiveStyleSheet(title) { 2 var i, a, main; 3 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { 4 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { 5 a.disabled = true; 6 if(a.getAttribute("title") == title) a.disabled = false; 7 } 8 } 9 } 10 11 function getActiveStyleSheet() { 12 var i, a; 13 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { 14 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); 15 } 16 return null; 17 } 18 19 function getPreferredStyleSheet() { 20 var i, a; 21 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { 22 if(a.getAttribute("rel").indexOf("style") != -1 23 && a.getAttribute("rel").indexOf("alt") == -1 24 && a.getAttribute("title") 25 ) return a.getAttribute("title"); 26 } 27 return null; 28 } 29 30 function createCookie(name,value,days) { 31 if (days) { 32 var date = new Date(); 33 date.setTime(date.getTime()+(days*24*60*60*1000)); 34 var expires = "; expires="+date.toGMTString(); 35 } 36 else expires = ""; 37 document.cookie = name+"="+value+expires+"; path=/"; 38 } 39 40 function readCookie(name) { 41 var nameEQ = name + "="; 42 var ca = document.cookie.split(';'); 43 for(var i=0;i < ca.length;i++) { 44 var c = ca[i]; 45 while (c.charAt(0)==' ') c = c.substring(1,c.length); 46 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 47 } 48 return null; 49 } 50 51 window.onload = function(e) { 52 var cookie = readCookie("style"); 53 var title = cookie ? cookie : getPreferredStyleSheet(); 54 setActiveStyleSheet(title); 55 } 56 57 window.onunload = function(e) { 58 var title = getActiveStyleSheet(); 59 createCookie("style", title, 365); 60 } 61 62 var cookie = readCookie("style"); 63 var title = cookie ? cookie : getPreferredStyleSheet(); 64 setActiveStyleSheet(title); 65 66 67 68 // from http://www.kryogenix.org 69 // by Scott Andrew - http://scottandrew.com 70 // add an eventlistener to browsers that can do it somehow. 71 function addEvent(obj, evType, fn) 72 { 73 if (obj.addEventListener) 74 { 75 obj.addEventListener(evType, fn, false); 76 return true; 77 } 78 else if (obj.attachEvent) 79 { 80 var r = obj.attachEvent('on'+evType, fn); 81 return r; 82 } 83 else 84 { 85 return false; 86 } 87 } 88 89 function floatImages() 90 { 91 // adapted from http://www.dithered.com/javascript/browser_detect/ 92 //**************************************************************// 93 // sniff user agent 94 var userAgent = navigator.userAgent.toLowerCase(); 95 96 // if Mozilla 1.4 then quit 97 if ((userAgent.indexOf('gecko') != -1) && (userAgent.indexOf('gecko/') + 14 == userAgent.length) && (parseFloat(userAgent.substring(userAgent.indexOf('rv:') + 3)) == '1.4')) return; 98 99 // if Opera then quit 100 if (document.all && window.Event) return; 101 //**************************************************************// 102 103 // check this browser can cope with what we want to do 104 if (!document.getElementById) return; 105 var blogDiv = document.getElementById('blog'); 106 if (!blogDiv) return; 107 if (!blogDiv.offsetWidth) return; 108 109 blogDiv.className = (blogDiv.offsetWidth >= 500) ? "float-images" : "block-images"; 110 } 111 112 // Blockquote citations 113 114 // Simon Willison's work: 115 // http://simon.incutio.com/archive/2002/12/20/#blockquoteCitations 116 117 // Also Dunstan Orchard's work: 118 // http://1976design.com/blog/archive/2003/11/10/updates/ 119 function blockquoteCite() 120 { 121 if (!document.createElementNS) 122 { 123 document.createElementNS = function(ns, elt) 124 { 125 return document.createElement(elt); 126 } 127 } 128 quotes = document.getElementsByTagName('blockquote'); 129 for (i = 0; i < quotes.length; i++) 130 { 131 var cite = quotes[i].getAttribute('cite'); 132 // value of cite attribute should only contain URI, not any other 133 if ((cite) && (cite != '')) 134 { 135 newlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a'); 136 newlink.setAttribute('href', cite); 137 newlink.className = 'cite-link'; 138 newlink.appendChild(document.createTextNode(cite)); 139 newdiv = document.createElementNS('http://www.w3.org/1999/xhtml', 'cite'); 140 newdiv.className = 'blockquote-cite'; 141 newdiv.appendChild(document.createTextNode('Source: ')); 142 newdiv.appendChild(newlink); 143 quotes[i].appendChild(newdiv); 144 quotes[i].removeAttribute('cite'); 145 } 146 } 147 } 148 149 // Ins and Del tags citations 150 function insdelCite() 151 { 152 if (!document.createElementNS) 153 { 154 document.createElementNS = function(ns, elt) 155 { 156 return document.createElement(elt); 157 } 158 } 159 var insdel = new Array(2); 160 insdel[0] = document.getElementsByTagName('ins'); 161 insdel[1] = document.getElementsByTagName('del'); 162 for (var i=0; i<insdel.length; i++) 163 { 164 if (insdel[i]) 165 { 166 for (var id=0; id<insdel[i].length; id++) 167 { 168 var isdl = insdel[i][id].getAttribute('cite'); 169 if ((isdl) && (isdl != "")) 170 { 171 idlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a'); 172 idlink.setAttribute('href', isdl); 173 idlink.className = 'cite-link ' + (i == 0 ? 'ins-cite' : 'del-cite'); 174 idlink.setAttribute('title','citation of ' + (i == 0 ? 'added' : 'deleted') + ' text'); 175 idlink.appendChild(document.createTextNode('#')); 176 insdel[i][id].appendChild(idlink); 177 insdel[i][id].removeAttribute('cite'); 178 } 179 } 180 } 181 } 182 } 183 184 // Force IE not to show alternate text as tooltip 185 function noAltTooltip() 186 { 187 images = document.getElementsByTagName('img'); 188 for (var i = 0; i < images.length; i++) 189 { 190 var title = images[i].getAttribute('title'); 191 var alt = images[i].getAttribute('alt'); 192 if ((document.all) && (alt) && (!title)) 193 { 194 images[i].setAttribute('title', ''); 195 } 196 } 197 } 198 199 // Nice Titles 200 201 // original code by Stuart Langridge 2003-11 202 // with additions to the code by other good people 203 // http://www.kryogenix.org/code/browser/nicetitle/ 204 // thank you, sir 205 206 // modified by Peter Janes 2003-03-25 207 // http://peterjanes.ca/blog/archives/2003/03/25/nicetitles-for-ins-and-del 208 // added in ins and del tags 209 210 // modified by Dunstan Orchard 2003-11-18 211 // http://1976design.com/blog/ 212 // added in accesskey information 213 // tried ever-so-hard, but couldn't work out how to do what Ethan did 214 215 // final genius touch by by Ethan Marcotte 2003-11-18 216 // http://www.sidesh0w.com/ 217 // worked out how to delay showing the popups to make them more like the browser's own 218 219 // set the namespace 220 var XHTMLNS = 'http://www.w3.org/1999/xhtml'; 221 var CURRENT_NICE_TITLE; 222 223 // browser sniff 224 var browser = new Browser(); 225 226 // determine browser and version. 227 function Browser() 228 { 229 var ua, s, i; 230 231 this.isIE = false; 232 this.isNS = false; 233 this.version = null; 234 235 ua = navigator.userAgent; 236 237 s = 'MSIE'; 238 if ((i = ua.indexOf(s)) >= 0) 239 { 240 this.isIE = true; 241 this.version = parseFloat(ua.substr(i + s.length)); 242 return; 243 } 244 245 s = 'Netscape6/'; 246 if ((i = ua.indexOf(s)) >= 0) 247 { 248 this.isNS = true; 249 this.version = parseFloat(ua.substr(i + s.length)); 250 return; 251 } 252 253 // treat any other 'Gecko' browser as NS 6.1. 254 s = 'Gecko'; 255 if ((i = ua.indexOf(s)) >= 0) 256 { 257 this.isNS = true; 258 this.version = 6.1; 259 return; 260 } 261 } 262 263 // 2003-11-19 sidesh0w 264 // set delay vars to emulate normal hover delay 265 var delay; 266 var interval = 0.60; 267 268 // this function runs on window load 269 // it runs through all the links on the page as starts listening for actions 270 function makeNiceTitles() 271 { 272 if (!document.createElement || !document.getElementsByTagName) return; 273 if (!document.createElementNS) 274 { 275 document.createElementNS = function(ns, elt) 276 { 277 return document.createElement(elt); 278 } 279 } 280 281 // do regular links 282 if (!document.links) 283 { 284 document.links = document.getElementsByTagName('a'); 285 } 286 for (var ti=0; ti<document.links.length; ti++) 287 { 288 var lnk = document.links[ti]; 289 // * I added specific class names here.. 290 if (lnk.title) 291 { 292 lnk.setAttribute('nicetitle', lnk.title); 293 lnk.removeAttribute('title'); 294 addEvent(lnk, 'mouseover', showDelay); 295 addEvent(lnk, 'mouseout', hideNiceTitle); 296 addEvent(lnk, 'focus', showDelay); 297 addEvent(lnk, 'blur', hideNiceTitle); 298 } 299 } 300 301 // 2003-03-25 Peter Janes 302 // do ins and del tags 303 var tags = new Array(2); 304 tags[0] = document.getElementsByTagName('ins'); 305 tags[1] = document.getElementsByTagName('del'); 306 for (var tt=0; tt<tags.length; tt++) 307 { 308 if (tags[tt]) 309 { 310 for (var ti=0; ti<tags[tt].length; ti++) 311 { 312 var tag = tags[tt][ti]; 313 if (tag.dateTime) 314 { 315 var strDate = tag.dateTime; 316 // HTML/ISO8601 date: yyyy-mm-ddThh:mm:ssTZD (Z, -hh:mm, +hh:mm) 317 var month = strDate.substring(5,7); 318 var day = strDate.substring(8,10); 319 if (month[0] == '0') 320 { 321 month = month[1]; 322 } 323 if (day[0] == '0') 324 { 325 day = day[1]; 326 } 327 var dtIns = new Date(strDate.substring(0,4), month-1, day, strDate.substring(11,13), strDate.substring(14,16), strDate.substring(17,19)); 328 tag.setAttribute('nicetitle', (tt == 0 ? 'Added' : 'Deleted') + ' on ' + dtIns.toString()); 329 addEvent(tag, 'mouseover', showDelay); 330 addEvent(tag, 'mouseout', hideNiceTitle); 331 addEvent(tag, 'focus', showDelay); 332 addEvent(tag, 'blur', hideNiceTitle); 333 } 334 } 335 } 336 } 337 } 338 339 function findPosition(oLink) 340 { 341 if (oLink.offsetParent) 342 { 343 for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent) 344 { 345 posX += oLink.offsetLeft; 346 posY += oLink.offsetTop; 347 } 348 return [posX, posY]; 349 } 350 else 351 { 352 return [oLink.x, oLink.y]; 353 } 354 } 355 356 function getParent(el, pTagName) 357 { 358 if (el == null) 359 { 360 return null; 361 } 362 // gecko bug, supposed to be uppercase 363 else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) 364 { 365 return el; 366 } 367 else 368 { 369 return getParent(el.parentNode, pTagName); 370 } 371 } 372 373 // 2003-11-19 sidesh0w 374 // trailerpark wrapper function 375 function showDelay(e) 376 { 377 if (window.event && window.event.srcElement) 378 { 379 lnk = window.event.srcElement 380 } 381 else if (e && e.target) 382 { 383 lnk = e.target 384 } 385 if (!lnk) return; 386 387 // lnk is a textnode or an elementnode that's not ins/del 388 if (lnk.nodeType == 3 || (lnk.nodeType == 1 && lnk.tagName.toLowerCase() != 'ins' && lnk.tagName.toLowerCase() != 'del')) 389 { 390 // ascend parents until we hit a link 391 lnk = getParent(lnk, 'a'); 392 } 393 394 delay = setTimeout("showNiceTitle(lnk)", interval * 1000); 395 } 396 397 // build and show the nice titles 398 function showNiceTitle(link) 399 { 400 if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE); 401 if (!document.getElementsByTagName) return; 402 403 nicetitle = lnk.getAttribute('nicetitle'); 404 405 var d = document.createElementNS(XHTMLNS, 'div'); 406 d.className = 'nicetitle'; 407 var dc = document.createElementNS(XHTMLNS, 'div'); 408 dc.className = 'nicetitle-content'; 409 d.appendChild(dc); 410 tnt = document.createTextNode(nicetitle); 411 pat = document.createElementNS(XHTMLNS, 'p'); 412 pat.className = 'titletext'; 413 pat.appendChild(tnt); 414 415 // 2003-11-18 Dunstan Orchard 416 // added in accesskey info 417 if (lnk.accessKey) 418 { 419 axs = document.createTextNode(' [' + lnk.accessKey + ']'); 420 axsk = document.createElementNS(XHTMLNS, 'span'); 421 axsk.className = 'accesskey'; 422 axsk.appendChild(axs); 423 pat.appendChild(axsk); 424 } 425 dc.appendChild(pat); 426 427 if (lnk.href) 428 { 429 tnd = document.createTextNode(lnk.href); 430 pad = document.createElementNS(XHTMLNS, 'p'); 431 pad.className = 'destination'; 432 pad.appendChild(tnd); 433 dc.appendChild(pad); 434 } 435 436 STD_WIDTH = 300; 437 438 if (lnk.href) 439 { 440 h = lnk.href.length; 441 } 442 else 443 { 444 h = nicetitle.length; 445 } 446 447 if (nicetitle.length) 448 { 449 t = nicetitle.length; 450 } 451 452 h_pixels = h*6; 453 t_pixels = t*10; 454 455 if (h_pixels > STD_WIDTH) 456 { 457 w = h_pixels; 458 } 459 else if ((STD_WIDTH>t_pixels) && (t_pixels>h_pixels)) 460 { 461 w = t_pixels; 462 } 463 else if ((STD_WIDTH>t_pixels) && (h_pixels>t_pixels)) 464 { 465 w = h_pixels; 466 } 467 else 468 { 469 w = STD_WIDTH; 470 } 471 472 d.style.width = w + 'px'; 473 474 mpos = findPosition(lnk); 475 mx = mpos[0]; 476 my = mpos[1]; 477 478 d.style.left = (mx+15) + 'px'; 479 d.style.top = (my+35) + 'px'; 480 481 if (window.innerWidth && ((mx+w) > window.innerWidth)) 482 { 483 d.style.left = (window.innerWidth - w - 25) + 'px'; 484 } 485 if (document.body.scrollWidth && ((mx+w) > document.body.scrollWidth)) 486 { 487 d.style.left = (document.body.scrollWidth - w - 25) + 'px'; 488 } 489 490 document.getElementsByTagName('body')[0].appendChild(d); 491 492 CURRENT_NICE_TITLE = d; 493 } 494 495 function hideNiceTitle(e) 496 { 497 // 2003-11-19 sidesh0w 498 // clearTimeout 499 if (delay) clearTimeout(delay); 500 if (!document.getElementsByTagName) return; 501 if (CURRENT_NICE_TITLE) 502 { 503 document.getElementsByTagName('body')[0].removeChild(CURRENT_NICE_TITLE); 504 CURRENT_NICE_TITLE = null; 505 } 506 } 507 508 addEvent(window, "load", floatImages); 509 addEvent(window, "resize", floatImages); 510 addEvent(window, "load", blockquoteCite); 511 addEvent(window, "load", insdelCite); 512 addEvent(window, "load", noAltTooltip); 513 addEvent(window, "load", makeNiceTitles); 514 515 // I'm very poor in JavaScript. Please correct me if I'm wrong. 516 517 518 519 520 521 522 523 524
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |