aboutsummaryrefslogtreecommitdiffstats
path: root/static/style/styleswitcher.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/style/styleswitcher.js')
-rw-r--r--static/style/styleswitcher.js172
1 files changed, 46 insertions, 126 deletions
diff --git a/static/style/styleswitcher.js b/static/style/styleswitcher.js
index 981a6ca..ddc2846 100644
--- a/static/style/styleswitcher.js
+++ b/static/style/styleswitcher.js
@@ -1,85 +1,36 @@
-function setActiveSiteStyleSheet(title) {
- var i, a, main;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
- if(a.getAttribute("title").indexOf("site") != 1) a.disabled = true;
- if(a.getAttribute("title") == title) a.disabled = false;
- }
- }
-}
-function setActiveWidthStyleSheet(title) {
- var i, a, main;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
- if(a.getAttribute("title").indexOf("width") != 1) a.disabled = true;
- if(a.getAttribute("title") == title) a.disabled = false;
- }
- }
-}
-function setActiveFontStyleSheet(title) {
- var i, a, main;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
- if(a.getAttribute("title").indexOf("font") != 1) a.disabled = true;
- if(a.getAttribute("title") == title) a.disabled = false;
- }
- }
-}
+var fontStyle = 'serif';
+var siteStyle = 'sane';
+var widthStyle = 'fixed';
-function getActiveSiteStyleSheet() {
- var i, a;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled && a.getAttribute("title").indexOf("site") != -1) return a.getAttribute("title");
- }
- return null;
-}
-function getActiveFontStyleSheet() {
+function setStyleSheet() {
var i, a;
+ var styleName = '' + widthStyle + '-' + siteStyle + '-' + fontStyle
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled && a.getAttribute("title").indexOf("font") != -1) return a.getAttribute("title");
- }
- return null;
-}
-function getActiveWidthStyleSheet() {
- var i, a;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled && a.getAttribute("title").indexOf("width") != -1) return a.getAttribute("title");
+ if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
+ {
+ if(a.getAttribute("title").indexOf(styleName) != -1) a.disabled = false;
+ else a.disabled = true;
+ }
}
- return null;
+ createCookie("style", styleName, 100);
}
-function getPreferredSiteStyleSheet() {
- var i, a;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1
- && a.getAttribute("rel").indexOf("alt") == -1
- && a.getAttribute("title")
- && a.getAttribute("title").indexOf("site") != -1
- ) return a.getAttribute("title");
- }
- return null;
-}
-function getPreferredFontStyleSheet() {
- var i, a;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1
- && a.getAttribute("rel").indexOf("alt") == -1
- && a.getAttribute("title")
- && a.getAttribute("title").indexOf("font") != -1
- ) return a.getAttribute("title");
- }
- return null;
-}
-function getPreferredWidthStyleSheet() {
- var i, a;
- for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
- if(a.getAttribute("rel").indexOf("style") != -1
- && a.getAttribute("rel").indexOf("alt") == -1
- && a.getAttribute("title")
- && a.getAttribute("title").indexOf("width") != -1
- ) return a.getAttribute("title");
- }
- return null;
+function parseStyleCookie(cookie) {
+ names = cookie.split('-')
+ widthStyle = names[0]
+ if(widthStyle == 'flexy') {
+ document.getElementById('style_width').innerHTML = 'flexy'
+ }
+ siteStyle = names[1]
+ if(siteStyle == 'nuts') {
+ document.getElementById('style_site').innerHTML = 'nuts'
+ }
+ fontStyle = names[2]
+ if(fontStyle == 'sans') {
+ document.getElementById('style_font_first').innerHTML = 'A'
+ document.getElementById('style_font_second').innerHTML = 'a'
+ }
+ setStyleSheet()
}
function createCookie(name,value,days) {
@@ -104,81 +55,50 @@ function readCookie(name) {
}
window.onload = function(e) {
- var cookie = readCookie("sitestyle");
- var title = cookie ? cookie : getPreferredSiteStyleSheet();
- setActiveSiteStyleSheet(title);
- if(title.indexOf('nuts') != -1) {
- document.getElementById('style_site').innerHTML = 'nuts'
- }
- var cookie = readCookie("fontstyle");
- var title = cookie ? cookie : getPreferredFontStyleSheet();
- setActiveFontStyleSheet(title);
- if(title.indexOf('sans') != -1) {
- document.getElementById('style_font_first').innerHTML = 'A'
- document.getElementById('style_font_second').innerHTML = 'a'
- }
- var cookie = readCookie("widthstyle");
- var title = cookie ? cookie : getPreferredWidthStyleSheet();
- setActiveWidthStyleSheet(title);
- if(title.indexOf('flexy') != -1) {
- document.getElementById('style_width').innerHTML = 'flexy'
- }
-}
-
-window.onunload = function(e) {
- if (stuffset == true) {
- var title = getActiveSiteStyleSheet();
- createCookie("sitestyle", title, 365);
- title = getActiveFontStyleSheet();
- createCookie("fontstyle", title, 365);
- title = getActiveWidthStyleSheet();
- createCookie("widthstyle", title, 365);
- }
+ var cookie = readCookie("style");
+ if(cookie) parseStyleCookie(cookie);
}
-var stuffset = false
-var cookie = readCookie("sitestyle");
-var title = cookie ? cookie : getPreferredSiteStyleSheet();
-setActiveSiteStyleSheet(title);
-var cookie = readCookie("fontstyle");
-var title = cookie ? cookie : getPreferredFontStyleSheet();
-setActiveFontStyleSheet(title);
-var cookie = readCookie("widthstyle");
-var title = cookie ? cookie : getPreferredFontStyleSheet();
-setActiveFontStyleSheet(title);
+/* var cookie = readCookie("style"); */
+/* parseStyleCookie(cookie) */
function swapstyle(thing) {
stuffset = true;
switch(thing){
case 'font':
- if(document.getElementById('style_font_first').innerHTML == 'a'){
+ if(document.getElementById('style_font_first').innerHTML.indexOf('a') != -1){
document.getElementById('style_font_first').innerHTML = 'A'
document.getElementById('style_font_second').innerHTML = 'a'
- setActiveFontStyleSheet('font-sans')
+ fontStyle = 'sans'
+ setStyleSheet()
} else {
document.getElementById('style_font_first').innerHTML = 'a'
document.getElementById('style_font_second').innerHTML = 'A'
- setActiveFontStyleSheet('font-serif')
+ fontStyle = 'serif'
+ setStyleSheet()
}
break;
case 'site':
- if(document.getElementById('style_site').innerHTML == 'sane'){
+ if(document.getElementById('style_site').innerHTML.indexOf('sane') != -1){
document.getElementById('style_site').innerHTML = 'nuts'
- setActiveSiteStyleSheet('site-nuts')
+ siteStyle = 'nuts'
+ setStyleSheet()
} else {
document.getElementById('style_site').innerHTML = 'sane'
- setActiveSiteStyleSheet('site-sane')
+ siteStyle = 'sane'
+ setStyleSheet()
}
break;
case 'width':
- if(document.getElementById('style_width').innerHTML == 'fixed'){
+ if(document.getElementById('style_width').innerHTML.indexOf('fixed') != -1){
document.getElementById('style_width').innerHTML = 'flexy'
- setActiveWidthStyleSheet('width-flexy')
+ widthStyle = 'flexy'
+ setStyleSheet()
} else {
document.getElementById('style_width').innerHTML = 'fixed'
- setActiveWidthStyleSheet('width-fixed')
+ widthStyle = 'fixed'
+ setStyleSheet()
}
break;
-
}
}