diff options
author | bnewbold <bnewbold@manus.(none)> | 2007-06-30 03:23:00 -0400 |
---|---|---|
committer | bnewbold <bnewbold@manus.(none)> | 2007-06-30 03:23:00 -0400 |
commit | 6951eb85239f386c8a0b6fd4051f5fbc1d8a77e0 (patch) | |
tree | fff1aa978025b227e8ad6222fb50af191379dabd /static/style/styleswitcher.js | |
parent | fed6d5930825914e07095cf2c330add257088bfb (diff) | |
download | bnewnet-6951eb85239f386c8a0b6fd4051f5fbc1d8a77e0.tar.gz bnewnet-6951eb85239f386c8a0b6fd4051f5fbc1d8a77e0.zip |
added hack-ish style tweaking controls
TODO: add font selector styles, make it all work, cookies?
Diffstat (limited to 'static/style/styleswitcher.js')
-rw-r--r-- | static/style/styleswitcher.js | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/static/style/styleswitcher.js b/static/style/styleswitcher.js new file mode 100644 index 0000000..981a6ca --- /dev/null +++ b/static/style/styleswitcher.js @@ -0,0 +1,184 @@ +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; + } + } +} + +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() { + 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("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"); + } + return null; +} + +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 createCookie(name,value,days) { + if (days) { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; +} + +function readCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); + } + return null; +} + +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 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); + +function swapstyle(thing) { + stuffset = true; + switch(thing){ + case 'font': + if(document.getElementById('style_font_first').innerHTML == 'a'){ + document.getElementById('style_font_first').innerHTML = 'A' + document.getElementById('style_font_second').innerHTML = 'a' + setActiveFontStyleSheet('font-sans') + } else { + document.getElementById('style_font_first').innerHTML = 'a' + document.getElementById('style_font_second').innerHTML = 'A' + setActiveFontStyleSheet('font-serif') + } + break; + case 'site': + if(document.getElementById('style_site').innerHTML == 'sane'){ + document.getElementById('style_site').innerHTML = 'nuts' + setActiveSiteStyleSheet('site-nuts') + } else { + document.getElementById('style_site').innerHTML = 'sane' + setActiveSiteStyleSheet('site-sane') + } + break; + case 'width': + if(document.getElementById('style_width').innerHTML == 'fixed'){ + document.getElementById('style_width').innerHTML = 'flexy' + setActiveWidthStyleSheet('width-flexy') + } else { + document.getElementById('style_width').innerHTML = 'fixed' + setActiveWidthStyleSheet('width-fixed') + } + break; + + } +} |