baseline
[omp.pkp.sfu.ca.git] / lib / pkp / js / sizer.js
blob12852d3f8988a78e43f663acda66a933feab07b4
1 /**
2 * sizer.js
4 * Copyright (c) 2000-2009 John Willinsky
5 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
7 * Font sizer JavaScript functions.
9 * $Id: sizer.js,v 1.4 2009/04/08 21:34:54 asmecher Exp $
12 function getStylesheets() {
13 var linkNodes, styleNodes, x, sheets = [];
14 if (!window.ScriptEngine && navigator.__ice_version ) {
15 return document.styleSheets;
17 if (document.getElementsByTagName) {
18 linkNodes = document.getElementsByTagName('link');
19 styleNodes = document.getElementsByTagName('style');
20 } else if (document.styleSheets && document.all) {
21 linkNodes = document.all.tags('LINK');
22 styleNodes = document.all.tags('STYLE');
23 } else {
24 return [];
26 for (x = 0; linkNodes[x]; x++) {
27 var rel = linkNodes[x].rel ? linkNodes[x].rel : linkNodes[x].getAttribute ? linkNodes[x].getAttribute('rel') : '';
28 if (typeof(rel) == 'string' && rel.toLowerCase().indexOf('style') != -1) {
29 sheets[sheets.length] = linkNodes[x];
32 for (x = 0; styleNodes[x]; x++) {
33 var rel = styleNodes[x].rel ? styleNodes[x].rel : styleNodes[x].getAttribute ? styleNodes[x].getAttribute('rel') : '';
34 if (typeof(rel) == 'string' && rel.toLowerCase().indexOf('style') != -1) {
35 sheets[sheets.length] = styleNodes[x];
38 return sheets;
41 /**
42 * Set the font size to the named stylesheet.
43 * Thanks to www.alistsapart.com for the basic design.
45 function setFontSize(size) {
46 var s = getStylesheets();
47 for (var i=0; i < s.length; i++) {
48 if (s[i].getAttribute("rel").indexOf("style") != -1 && s[i].getAttribute("title")) {
49 s[i].disabled = true;
50 if(s[i].getAttribute("title") == size) s[i].disabled = false;
55 /**
56 * Get the current font size.
57 * Thanks to www.alistapart.com for the basic design.
59 function getFontSize() {
60 var s = getStylesheets();
61 for (var i=0; i < s.length; i++) {
62 if(s[i].getAttribute("rel").indexOf("style") != -1 && s[i].getAttribute("title") && !s[i].disabled) return s[i].getAttribute("title");
64 return null;
67 function getPreferredFontSize() {
68 var s = getStylesheets();
69 for (var i=0; i < s.length; i++) {
70 if(s[i].getAttribute("rel").indexOf("style") != -1 && s[i].getAttribute("rel").indexOf("alt") == -1 && s[i].getAttribute("title")) return s[i].getAttribute("title");
72 return null;
75 window.onload = function(e) {
76 var cookie = readCookie("font-size");
77 var size = cookie ? cookie : getPreferredFontSize();
78 setFontSize(size);
81 window.onunload = function(e) {
82 var size = getFontSize();
83 createCookie("font-size", size, 365);