Mercurial > defr > DualBlog
comparison StyleSwitcher.js @ 0:629389204276
Import initial
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Sat, 20 Oct 2007 14:15:10 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:629389204276 |
---|---|
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 createCookie("style", title, 365); | |
10 document.chosenStyleSheet = title; | |
11 } | |
12 | |
13 function getActiveStyleSheet() { | |
14 /* var i, a; | |
15 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { | |
16 if(a.getAttribute("rel").indexOf("Style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); | |
17 } | |
18 return null;*/ | |
19 return document.chosenStyleSheet; | |
20 } | |
21 | |
22 function getPreferredStyleSheet() { | |
23 var i, a; | |
24 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { | |
25 if(a.getAttribute("rel").indexOf("Style") != -1 | |
26 && a.getAttribute("rel").indexOf("Alt") == -1 | |
27 && a.getAttribute("title") | |
28 ) return a.getAttribute("title"); | |
29 } | |
30 return null; | |
31 } | |
32 | |
33 function createCookie(name,value,days) { | |
34 if (days) { | |
35 var date = new Date(); | |
36 date.setTime(date.getTime()+(days*24*60*60*1000)); | |
37 var expires = "; expires="+date.toGMTString(); | |
38 } | |
39 else expires = ""; | |
40 document.cookie = name+"="+value+expires+"; path=/"; | |
41 } | |
42 | |
43 function readCookie(name) { | |
44 var nameEQ = name + "="; | |
45 var ca = document.cookie.split(';'); | |
46 for(var i=0;i < ca.length;i++) { | |
47 var c = ca[i]; | |
48 while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
49 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | |
50 } | |
51 return null; | |
52 } | |
53 | |
54 window.onunload = function(e) { | |
55 var title = getActiveStyleSheet(); | |
56 createCookie("style", title, 365); | |
57 } |