1/************************************************************************* 2 This code is from Dynamic Web Coding at dyn-web.com 3 Copyright 2004-10 by Sharon Paine 4 See Terms of Use at www.dyn-web.com/business/terms.php 5 regarding conditions under which you may use this code. 6 This notice must be retained in the code as is! 7*************************************************************************/ 8 9/* dw_sizerdx.js version date: April 2010 10 requires dw_cookies.js (Nov 2009 version) and dw_event.js 11*/ 12 13var dw_fontSizerDX = { 14 sizeUnit: "px", 15 defaultSize: 12, 16 maxSize: 26, 17 minSize: 9, 18 sizerDivId: 'sizer', // div id for sizer controls 19 queryName: "dw_fsz", // name to check query string for when passing size in URL 20 cookieLifetime: 180, // how long to keep cookie 21 22 adjustList: [], // set method populates 23 24 setDefaults: function(unit, dflt, mn, mx, sels) { 25 this.sizeUnit = unit; this.defaultSize = dflt; 26 this.maxSize = mx; this.minSize = mn; 27 if (sels) this.set(dflt, mn, mx, sels); 28 }, 29 30 set: function (dflt, mn, mx, sels) { 31 var ln = this.adjustList.length; 32 for (var i=0; sels[i]; i++) { 33 this.adjustList[ln+i] = []; 34 this.adjustList[ln+i]["sel"] = sels[i]; 35 this.adjustList[ln+i]["dflt"] = dflt; 36 this.adjustList[ln+i]["min"] = mn || this.minSize; 37 this.adjustList[ln+i]["max"] = mx || this.maxSize; 38 // hold ratio of this selector's default size to this.defaultSize for calcs in adjust fn 39 this.adjustList[ln+i]["ratio"] = this.adjustList[ln+i]["dflt"] / this.defaultSize; 40 } 41 }, 42 43 addHandlers: function () { 44 var sizerEl = document.getElementById( dw_fontSizerDX.sizerDivId ); 45 if ( !dw_fontSizerDX.sizeIncrement ) { dw_fontSizerDX.getSizeIncrement(); } 46 var links = sizerEl.getElementsByTagName('a'); 47 for (var i=0; links[i]; i++) { 48 if ( dw_Util.hasClass( links[i], 'increase') ) { 49 links[i].onclick = function () { dw_fontSizerDX.adjust( dw_fontSizerDX.sizeIncrement ); return false } 50 } else if ( dw_Util.hasClass( links[i], 'decrease') ) { 51 links[i].onclick = function () { dw_fontSizerDX.adjust( -dw_fontSizerDX.sizeIncrement ); return false } 52 } else if ( dw_Util.hasClass( links[i], 'reset') ) { 53 links[i].onclick = function () { dw_fontSizerDX.reset(); return false } 54 } 55 } 56 if (sizerEl) sizerEl.style.display = "block"; 57 }, 58 59 getSizeIncrement: function () { 60 var val = 2; 61 switch ( dw_fontSizerDX.sizeUnit ) { 62 case 'px' : val = 2; break; 63 case 'em' : val = .2; break; 64 case '%' : val = 10; break; 65 } 66 dw_fontSizerDX.sizeIncrement = val; 67 }, 68 69 init: function() { 70 if ( !document.getElementById || !document.getElementsByTagName || !document.createElement ) return; 71 var _this = dw_fontSizerDX; 72 if ( !_this.doControlsSetup ) { 73 _this.addHandlers(); 74 } else { 75 _this.setupControls(); 76 } 77 var size; 78 // check query string and cookie for fontSize 79 // check size (in case default unit changed or size passed in url out of range) 80 size = dw_Util.getValueFromQueryString( _this.queryName ); 81 if ( isNaN( parseFloat(size) ) || size > _this.maxSize || size < _this.minSize ) { 82 size = dw_Cookie.get("fontSize"); 83 if ( isNaN( parseFloat(size) ) || size > _this.maxSize || size < _this.minSize ) { 84 size = _this.defaultSize; 85 } 86 } 87 // if neither set nor setDefaults populates adjustList, apply sizes to body and td's 88 if (_this.adjustList.length == 0) _this.set( _this.defaultSize, _this.minSize, _this.maxSize, ['body', 'td'] ); 89 _this.curSize = _this.defaultSize; // create curSize property to use in calculations 90 if ( size != _this.defaultSize ) _this.adjust( size - _this.defaultSize ); 91 }, 92 93 adjust: function(n) { 94 if ( !this.curSize ) return; 95 var alist, size, list, i, j; 96 // check against max/minSize 97 if ( n > 0 ) { 98 if ( this.curSize + n > this.maxSize ) n = this.maxSize - this.curSize; 99 } else if ( n < 0 ) { 100 if ( this.curSize + n < this.minSize ) n = this.minSize - this.curSize; 101 } 102 if ( n == 0 ) return; 103 this.curSize += n; 104 // loop through adjustList, calculating size, checking max/min 105 alist = this.adjustList; 106 for (i=0; alist[i]; i++) { 107 size = this.curSize * alist[i]['ratio']; // maintain proportion 108 size = Math.max(alist[i]['min'], size); size = Math.min(alist[i]['max'], size); 109 list = dw_Util.getElementsBySelector( alist[i]['sel'] ); 110 for (j=0; list[j]; j++) { list[j].style.fontSize = size + this.sizeUnit; } 111 } 112 dw_Cookie.set( "fontSize", this.curSize, this.cookieLifetime, "/" ); 113 }, 114 115 reset: function() { 116 if ( !this.curSize ) return; 117 var alist = this.adjustList, list, i, j; 118 for (i=0; alist[i]; i++) { 119 list = dw_Util.getElementsBySelector( alist[i]['sel'] ); 120 for (j=0; list[j]; j++) { 121 // Reset adjustList elements to their default sizes 122 //list[j].style.fontSize = alist[i]['dflt'] + this.sizeUnit; 123 list[j].style.fontSize = ''; // restores original font size (unless set inline!) 124 } 125 } 126 this.curSize = this.defaultSize; 127 dw_Cookie.del("fontSize", "/"); 128 } 129 130}; 131 132///////////////////////////////////////////////////////////////////// 133// 134var dw_Util; 135if (!dw_Util) dw_Util = {}; 136 137// removes space characters from start and end of string 138dw_Util.trimString = function (str) { 139 var re = /^\s+|\s+$/g; 140 return str.replace(re, ""); 141} 142 143// removes extra space characters 144dw_Util.normalizeString = function (str) { 145 var re = /\s\s+/g; 146 return dw_Util.trimString(str).replace(re, " "); 147} 148 149dw_Util.hasClass = function (el, cl) { 150 var re = new RegExp("\\b" + cl + "\\b", "i"); 151 if ( re.test( el.className ) ) { 152 return true; 153 } 154 return false;
155} 156 157// what className attached to what element type in what container element (default: document) 158dw_Util.getElementsByClassName = function (sClass, sTag, oCont) { 159 var result = [], list, i; 160 var re = new RegExp("\\b" + sClass + "\\b", "i"); 161 oCont = oCont? oCont: document; 162 if ( document.getElementsByTagName ) { 163 if ( !sTag || sTag == "*" ) { // for ie5 164 list = oCont.all? oCont.all: oCont.getElementsByTagName("*"); 165 } else { 166 list = oCont.getElementsByTagName(sTag); 167 } 168 for (i=0; list[i]; i++) 169 if ( re.test( list[i].className ) ) result.push( list[i] ); 170 } 171 return result; 172} 173 174// resource: simon.incutio.com/archive/2003/03/25/getElementsBySelector 175dw_Util.getElementsBySelector = function (selector) { 176 if (!document.getElementsByTagName) return []; 177 var nodeList = [document], tokens, bits, list, col, els, i, j, k; 178 selector = dw_Util.normalizeString(selector); 179 tokens = selector.split(' '); 180 for (i=0; tokens[i]; i++) { 181 if ( tokens[i].indexOf('#') != -1 ) { // id 182 bits = tokens[i].split('#'); 183 var el = document.getElementById( bits[1] ); 184 if (!el) return []; 185 if ( bits[0] ) { // check tag 186 if ( el.tagName.toLowerCase() != bits[0].toLowerCase() ) return []; 187 } 188 for (j=0; nodeList[j]; j++) { // check containment 189 if ( nodeList[j] == document || dw_Util.contained(el, nodeList[j]) ) 190 nodeList = [el]; 191 else return []; 192 } 193 } else if ( tokens[i].indexOf('.') != -1 ) { // class 194 bits = tokens[i].split('.'); col = []; 195 for (j=0; nodeList[j]; j++) { 196 els = dw_Util.getElementsByClassName( bits[1], bits[0], nodeList[j] ); 197 for (k=0; els[k]; k++) { col[col.length] = els[k]; } 198 } 199 nodeList = []; 200 for (j=0; col[j]; j++) { nodeList.push(col[j]); } 201 } else { // element 202 els = []; 203 for (j = 0; nodeList[j]; j++) { 204 list = nodeList[j].getElementsByTagName(tokens[i]); 205 for (k = 0; list[k]; k++) { els.push(list[k]); } 206 } 207 nodeList = els; 208 } 209 } 210 return nodeList; 211} 212 213// obj: link or window.location 214dw_Util.getValueFromQueryString = function (name, obj) { 215 obj = obj? obj: window.location; 216 if (obj.search && obj.search.indexOf(name != -1) ) { 217 var pairs = obj.search.slice(1).split("&"); // name/value pairs 218 var set; 219 for (var i=0; pairs[i]; i++) { 220 set = pairs[i].split("="); // Check each pair for match on name 221 if ( set[0] == name && set[1] ) { 222 return set[1]; 223 } 224 } 225 } 226 return ''; 227} 228 229// returns true of oNode is contained by oCont (container) 230dw_Util.contained = function (oNode, oCont) { 231 if (!oNode) return null; // in case alt-tab away while hovering (prevent error) 232 while ( (oNode = oNode.parentNode) ) if ( oNode == oCont ) return true; 233 return false; 234}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.