source: trunk/www.guidonia.net/wp/wp-content/themes/facebook/js/switch.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 1.8 KB
RevLine 
[44]1function 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
11function 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
19function 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
30function 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
40function 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
51window.onload = function(e) {
52 var cookie = readCookie("style");
53 var title = cookie ? cookie : getPreferredStyleSheet();
54 setActiveStyleSheet(title);
55}
56
57window.onunload = function(e) {
58 var title = getActiveStyleSheet();
59 createCookie("style", title, 365);
60}
61
62var cookie = readCookie("style");
63var title = cookie ? cookie : getPreferredStyleSheet();
64setActiveStyleSheet(title);
Note: See TracBrowser for help on using the repository browser.