source: branches/posledni/forum/styles/prosilver/template/styleswitcher.js

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 3.0 KB
Line 
1
2function fontsizeup(event)
3{
4 // Skip tabs; 9 being the ASCII code for a tab
5 if (event && getKeyCode(event) == 9)
6 {
7 return true;
8 }
9
10 var active = getActiveStyleSheet();
11
12 switch (active)
13 {
14 case 'A--':
15 setActiveStyleSheet('A-');
16 break;
17
18 case 'A-':
19 setActiveStyleSheet('A');
20 break;
21
22 case 'A':
23 setActiveStyleSheet('A+');
24 break;
25
26 case 'A+':
27 setActiveStyleSheet('A++');
28 break;
29
30 case 'A++':
31 setActiveStyleSheet('A');
32 break;
33
34 default:
35 setActiveStyleSheet('A');
36 break;
37 }
38
39 return false;
40}
41
42function fontsizedown(event)
43{
44 // Skip tabs
45 if (event && getKeyCode(event) == 9)
46 {
47 return true;
48 }
49
50 var active = getActiveStyleSheet();
51
52 switch (active)
53 {
54 case 'A++' :
55 setActiveStyleSheet('A+');
56 break;
57
58 case 'A+' :
59 setActiveStyleSheet('A');
60 break;
61
62 case 'A' :
63 setActiveStyleSheet('A-');
64 break;
65
66 case 'A-' :
67 setActiveStyleSheet('A--');
68 break;
69
70 case 'A--' :
71 break;
72
73 default :
74 setActiveStyleSheet('A--');
75 break;
76 }
77
78 return false;
79}
80
81function getKeyCode(event)
82{
83 // IE doesn't fire the onkeypress event for tabs
84 // Reference: http://www.quirksmode.org/js/keys.html
85
86 var code = (event.keyCode) ? event.keyCode : 0;
87
88 // Probably using FF
89 if (!code && event.charCode)
90 {
91 code = event.charCode;
92 }
93
94 return code;
95}
96
97function setActiveStyleSheet(title)
98{
99 var i, a, main;
100
101 for (i = 0; (a = document.getElementsByTagName('link')[i]); i++)
102 {
103 if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title'))
104 {
105 a.disabled = true;
106 if (a.getAttribute('title') == title)
107 {
108 a.disabled = false;
109 }
110 }
111 }
112}
113
114function getActiveStyleSheet()
115{
116 var i, a;
117
118 for (i = 0; (a = document.getElementsByTagName('link')[i]); i++)
119 {
120 if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled)
121 {
122 return a.getAttribute('title');
123 }
124 }
125
126 return null;
127}
128
129function getPreferredStyleSheet()
130{
131 return ('A-');
132}
133
134function createCookie(name, value, days)
135{
136 if (days)
137 {
138 var date = new Date();
139 date.setTime(date.getTime() + (days*24*60*60*1000));
140 var expires = '; expires=' + date.toGMTString();
141 }
142 else
143 {
144 expires = '';
145 }
146
147 document.cookie = name + '=' + value + expires + style_cookie_settings;
148}
149
150function readCookie(name)
151{
152 var nameEQ = name + '=';
153 var ca = document.cookie.split(';');
154
155 for (var i = 0; i < ca.length; i++)
156 {
157 var c = ca[i];
158
159 while (c.charAt(0) == ' ')
160 {
161 c = c.substring(1, c.length);
162 }
163
164 if (c.indexOf(nameEQ) == 0)
165 {
166 return c.substring(nameEQ.length, c.length);
167 }
168 }
169
170 return null;
171}
172
173function load_cookie()
174{
175 var cookie = readCookie('style_cookie');
176 var title = cookie ? cookie : getPreferredStyleSheet();
177 setActiveStyleSheet(title);
178}
179
180function unload_cookie()
181{
182 var title = getActiveStyleSheet();
183 createCookie('style_cookie', title, 365);
184}
185
186onload_functions.push('load_cookie()');
187onunload_functions.push('unload_cookie()');
188
189/*
190var cookie = readCookie("style");
191var title = cookie ? cookie : getPreferredStyleSheet();
192setActiveStyleSheet(title);
193*/
Note: See TracBrowser for help on using the repository browser.