|
1 /* |
|
2 Author: wpdesigner7 |
|
3 Modified by mg12 |
|
4 Update: 2009/08/13 |
|
5 */ |
|
6 (function() { |
|
7 |
|
8 function setActiveStyleSheet(title) { |
|
9 var i, a, main; |
|
10 for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) { |
|
11 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { |
|
12 a.disabled = true; |
|
13 if(a.getAttribute("title") == title) { |
|
14 a.disabled = false; |
|
15 } |
|
16 } |
|
17 } |
|
18 } |
|
19 |
|
20 function getActiveStyleSheet() { |
|
21 var i, a; |
|
22 for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) { |
|
23 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) { |
|
24 return a.getAttribute("title"); |
|
25 } |
|
26 } |
|
27 return null; |
|
28 } |
|
29 |
|
30 function getPreferredStyleSheet() { |
|
31 var i, a; |
|
32 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { |
|
33 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { |
|
34 return a.getAttribute("title"); |
|
35 } |
|
36 } |
|
37 return null; |
|
38 } |
|
39 |
|
40 function createCookie(name,value,days) { |
|
41 if (days) { |
|
42 var date = new Date(); |
|
43 date.setTime(date.getTime()+(days*24*60*60*1000)); |
|
44 var expires = "; expires="+date.toGMTString(); |
|
45 } |
|
46 else expires = ""; |
|
47 document.cookie = name+"="+value+expires+"; path=/"; |
|
48 } |
|
49 |
|
50 function readCookie(name) { |
|
51 var nameEQ = name + "="; |
|
52 var ca = document.cookie.split(';'); |
|
53 for(var i = 0; i < ca.length; i++) { |
|
54 var c = ca[i]; |
|
55 while(c.charAt(0)==' ') { |
|
56 c = c.substring(1, c.length); |
|
57 } |
|
58 if(c.indexOf(nameEQ) == 0) { |
|
59 var cookieStyle = c.substring(nameEQ.length, c.length); |
|
60 for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) { |
|
61 if(a.getAttribute("title") == cookieStyle) { |
|
62 return cookieStyle; |
|
63 } |
|
64 } |
|
65 } |
|
66 } |
|
67 return null; |
|
68 } |
|
69 |
|
70 window.onload = function(e) { |
|
71 var cookie = readCookie("style"); |
|
72 var title = cookie ? cookie : getPreferredStyleSheet(); |
|
73 setActiveStyleSheet(title); |
|
74 } |
|
75 |
|
76 window.onunload = function(e) { |
|
77 var title = getActiveStyleSheet(); |
|
78 createCookie("style", title, 365); |
|
79 } |
|
80 |
|
81 var cookie = readCookie("style"); |
|
82 var title = cookie ? cookie : getPreferredStyleSheet(); |
|
83 setActiveStyleSheet(title); |
|
84 |
|
85 window['TSS'] = {}; |
|
86 window['TSS']['setActiveStyleSheet'] = setActiveStyleSheet; |
|
87 |
|
88 })(); |