1/** 2 * @fileoverview TextResizeDetector 3 * 4 * Detects changes to font sizes when user changes browser settings 5 * <br>Fires a custom event with the following data:<br><br> 6 * iBase : base font size 7 * iDelta : difference in pixels from previous setting<br> 8 * iSize : size in pixel of text<br> 9 * 10 * @author Lawrence Carvalho [email protected] 11 * @version 1.0 12 */ 13 14/** 15 * @constructor 16 */ 17TextResizeDetector = function () { 18 var el = null; 19 var iIntervalDelay = 200; 20 var iInterval = null; 21 var iCurrSize = -1; 22 var iBase = -1; 23 var aListeners = []; 24 var createControlElement = function () { 25 el = document.createElement('span'); 26 el.id = 'textResizeControl'; 27 el.innerHTML = ' '; 28 el.style.position = "absolute"; 29 el.style.left = "-9999px"; 30 var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID); 31 // insert before firstChild 32 if (elC) { 33 elC.insertBefore(el,elC.firstChild); 34 } 35 iBase = iCurrSize = TextResizeDetector.getSize(); 36 }; 37 38 function _stopDetector() { 39 window.clearInterval(iInterval); 40 iInterval = null; 41 }; 42 function _startDetector() { 43 if (!iInterval) { 44 iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay); 45 } 46 }; 47 48 function _detect() { 49 var iNewSize = TextResizeDetector.getSize(); 50 51 if (iNewSize !== iCurrSize) { 52 for (var i = 0; i < aListeners.length; i++) { 53 aListnr = aListeners[i]; 54 var oArgs = { iBase: iBase,iDelta:((iCurrSize != -1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize : iCurrSize = iNewSize}; 55 if (!aListnr.obj) { 56 aListnr.fn('textSizeChanged',[oArgs]); 57 } 58 else { 59 aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]); 60 } 61 } 62 63 } 64 return iCurrSize; 65 }; 66 var onAvailable = function () { 67 68 if (!TextResizeDetector.onAvailableCount_i ) { 69 TextResizeDetector.onAvailableCount_i = 0; 70 } 71 72 if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) { 73 TextResizeDetector.init(); 74 if (TextResizeDetector.USER_INIT_FUNC){ 75 TextResizeDetector.USER_INIT_FUNC(); 76 } 77 TextResizeDetector.onAvailableCount_i = null; 78 } 79 else { 80 if (TextResizeDetector.onAvailableCount_i < 600) { 81 TextResizeDetector.onAvailableCount_i++; 82 setTimeout(onAvailable,200) 83 } 84 } 85 }; 86 setTimeout(onAvailable,500); 87 88 return { 89 /* 90 * Initializes the detector 91 * 92 * @param {String} sId The id of the element in which to create the control element 93 */ 94 init: function () { 95 createControlElement(); 96 _startDetector(); 97 }, 98 /** 99 * Adds listeners to the ontextsizechange event. 100 * Returns the base font size 101 * 102 */ 103 addEventListener:function (fn,obj,bScope) { 104 aListeners[aListeners.length] = { 105 fn: fn, 106 obj: obj 107 } 108 return iBase; 109 }, 110 /** 111 * performs the detection and fires textSizeChanged event 112 * @return the current font size 113 * @type {integer} 114 */ 115 detect:function () { 116 return _detect(); 117 }, 118 /** 119 * Returns the height of the control element 120 * 121 * @return the current height of control element 122 * @type {integer} 123 */ 124 getSize:function () { 125 var iSize; 126 return el.offsetHeight; 127 }, 128 /** 129 * Stops the detector 130 */ 131 stopDetector:function () { 132 return _stopDetector(); 133 }, 134 /* 135 * Starts the detector 136 */ 137 startDetector:function () { 138 return _startDetector(); 139 } 140 } 141}(); 142 143TextResizeDetector.TARGET_ELEMENT_ID = 'doc'; 144TextResizeDetector.USER_INIT_FUNC = null;
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.