1function smf_NewsFader(oOptions) 2{ 3 this.opt = oOptions; 4 5 this.oFaderHandle = document.getElementById(this.opt.sFaderControlId); 6 7 // Fade from... what text color? Default to black. 8 this.oFadeFrom = 'oFadeFrom' in this.opt ? this.opt.oFadeFrom : { 9 r: 0, 10 g: 0, 11 b: 0 12 }; 13 14 // To which background color? Default to white. 15 this.oFadeTo = 'oFadeTo' in this.opt ? this.opt.oFadeTo : { 16 r: 255, 17 g: 255, 18 b: 255 19 }; 20 21 // Surround each item with... anything special? 22 this.sItemTemplate = 'sItemTemplate' in this.opt ? this.opt.sItemTemplate : '%1$s'; 23 24 // Fade delay (in milliseconds). 25 this.iFadeDelay = 'iFadeDelay' in this.opt ? this.opt.iFadeDelay : 5000; 26 27 // The array that contains all the lines of the news for display. 28 this.aFaderItems = 'aFaderItems' in this.opt ? this.opt.aFaderItems : []; 29 30 // Should we look for fader data, still? 31 this.bReceivedItemsOnConstruction = 'aFaderItems' in this.opt; 32 33 // The current item in smfFadeContent. 34 this.iFadeIndex = -1; 35 36 // Percent of fade (-64 to 510). 37 this.iFadePercent = 510 38 39 // Direction (in or out). 40 this.bFadeSwitch = false; 41 42 // Just make sure the page is loaded before calling the init. 43 setTimeout(this.opt.sSelf + '.init();', 1); 44} 45 46smf_NewsFader.prototype.init = function init() 47{ 48 var oForeEl, oForeColor, oBackEl, oBackColor; 49 50 // Try to find the fore- and background colors. 51 var modern_browser = 'MozOpacity' in this.oFaderHandle.style || 'Opacity' in this.oFaderHandle.style || 'filter' in this.oFaderHandle.style; 52 if ('currentStyle' in this.oFaderHandle && !modern_browser) 53 { 54 oForeColor = this.oFaderHandle.currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/); 55 this.oFadeFrom = { 56 r: parseInt(oForeColor[1]), 57 g: parseInt(oForeColor[2]), 58 b: parseInt(oForeColor[3]) 59 }; 60 61 oBackEl = this.oFaderHandle; 62 while (oBackEl.currentStyle.backgroundColor == 'transparent' && 'parentNode' in oBackEl) 63 oBackEl = oBackEl.parentNode; 64 65 oBackColor = oBackEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/); 66 this.oFadeTo = { 67 r: eval('0x' + oBackColor[1]), 68 g: eval('0x' + oBackColor[2]), 69 b: eval('0x' + oBackColor[3]) 70 }; 71 } 72 else if (!('opera' in window) && 'defaultView' in document && !modern_browser) 73 { 74 oForeEl = this.oFaderHandle; 75 while (document.defaultView.getComputedStyle(oForeEl, null).getPropertyCSSValue('color') == null && 'parentNode' in oForeEl && 'tagName' in oForeEl.parentNode) 76 oForeEl = oForeEl.parentNode; 77 78 oForeColor = document.defaultView.getComputedStyle(oForeEl, null).getPropertyValue('color').match(/rgb\((\d+), (\d+), (\d+)\)/); 79 this.oFadeFrom = { 80 r: parseInt(oForeColor[1]), 81 g: parseInt(oForeColor[2]), 82 b: parseInt(oForeColor[3]) 83 }; 84 85 oBackEl = this.oFaderHandle; 86 while (document.defaultView.getComputedStyle(oBackEl, null).getPropertyCSSValue('background-color') == null && 'parentNode' in oBackEl && 'tagName' in oBackEl.parentNode) 87 oBackEl = oBackEl.parentNode; 88 89 oBackColor = document.defaultView.getComputedStyle(oBackEl, null).getPropertyValue('background-color'); 90 this.oFadeTo = { 91 r: parseInt(oBackColor[1]), 92 g: parseInt(oBackColor[2]), 93 b: parseInt(oBackColor[3]) 94 }; 95 } 96 97 // Did we get our fader items on construction, or should we be gathering them instead? 98 if (!this.bReceivedItemsOnConstruction) 99 { 100 // Get the news from the list in boardindex 101 var oNewsItems = this.oFaderHandle.getElementsByTagName('li'); 102 103 // Fill the array that has previously been created 104 for (var i = 0, n = oNewsItems.length; i < n; i ++) 105 this.aFaderItems[i] = oNewsItems[i].innerHTML; 106 } 107 108 // The ranges to fade from for R, G, and B. (how far apart they are.) 109 this.oFadeRange = { 110 'r': this.oFadeFrom.r - this.oFadeTo.r, 111 'g': this.oFadeFrom.g - this.oFadeTo.g, 112 'b': this.oFadeFrom.b - this.oFadeTo.b 113 }; 114 115 // Divide by 20 because we are doing it 20 times per one ms. 116 this.iFadeDelay /= 20; 117 118 // Start the fader! 119 window.setTimeout(this.opt.sSelf + '.fade();', 20); 120} 121 122// Main fading function... called 50 times every second. 123smf_NewsFader.prototype.fade = function fade() 124{ 125 if (this.aFaderItems.length <= 1) 126 return; 127 128 // A fix for Internet Explorer 4: wait until the document is loaded so we can use setInnerHTML(). 129 if ('readyState' in document && document.readyState != 'complete') 130 { 131 window.setTimeout(this.opt.sSelf + '.fade();', 20); 132 return; 133 } 134 135 // Starting out? Set up the first item. 136 if (this.iFadeIndex == -1) 137 { 138 setInnerHTML(this.oFaderHandle, this.sItemTemplate.replace('%1$s', this.aFaderItems[0])); 139 this.iFadeIndex = 1; 140 141 // In Mozilla, text jumps around from this when 1 or 0.5, etc... 142 if ('MozOpacity' in this.oFaderHandle.style) 143 this.oFaderHandle.style.MozOpacity = '0.90'; 144 else if ('opacity' in this.oFaderHandle.style) 145 this.oFaderHandle.style.opacity = '0.90'; 146 // In Internet Explorer, we have to define this to use it. 147 else if ('filter' in this.oFaderHandle.style) 148 this.oFaderHandle.style.filter = 'alpha(opacity=100)'; 149 } 150 151 // Are we already done fading in? If so, fade out. 152 if (this.iFadePercent >= 510) 153 this.bFadeSwitch = !this.bFadeSwitch; 154 155 // All the way faded out? 156 else if (this.iFadePercent <= -64) 157 { 158 this.bFadeSwitch = !this.bFadeSwitch; 159 160 // Go to the next item, or first if we're out of items. 161 setInnerHTML(this.oFaderHandle, this.sItemTemplate.replace('%1$s', this.aFaderItems[this.iFadeIndex ++])); 162 if (this.iFadeIndex >= this.aFaderItems.length) 163 this.iFadeIndex = 0; 164 } 165 166 // Increment or decrement the fade percentage. 167 if (this.bFadeSwitch) 168 this.iFadePercent -= 255 / this.iFadeDelay * 2; 169 else
170 this.iFadePercent += 255 / this.iFadeDelay * 2; 171 172 // If it's not outside 0 and 256... (otherwise it's just delay time.) 173 if (this.iFadePercent < 256 && this.iFadePercent > 0) 174 { 175 // Easier... also faster... 176 var tempPercent = this.iFadePercent / 255, rounded; 177 178 if ('MozOpacity' in this.oFaderHandle.style) 179 { 180 rounded = Math.round(tempPercent * 100) / 100; 181 this.oFaderHandle.style.MozOpacity = rounded == 1 ? '0.99' : rounded; 182 } 183 else if ('opacity' in this.oFaderHandle.style) 184 { 185 rounded = Math.round(tempPercent * 100) / 100; 186 this.oFaderHandle.style.opacity = rounded == 1 ? '0.99' : rounded; 187 } 188 else 189 { 190 var done = false; 191 if ('alpha' in this.oFaderHandle.filters) 192 { 193 try 194 { 195 this.oFaderHandle.filters.alpha.opacity = Math.round(tempPercent * 100); 196 done = true; 197 } 198 catch (err) 199 { 200 } 201 } 202 203 if (!done) 204 { 205 // Get the new R, G, and B. (it should be bottom + (range of color * percent)...) 206 var r = Math.ceil(this.oFadeTo.r + this.oFadeRange.r * tempPercent); 207 var g = Math.ceil(this.oFadeTo.g + this.oFadeRange.g * tempPercent); 208 var b = Math.ceil(this.oFadeTo.b + this.oFadeRange.b * tempPercent); 209 210 // Set the color in the style, thereby fading it. 211 this.oFaderHandle.style.color = 'rgb(' + r + ', ' + g + ', ' + b + ')'; 212 } 213 } 214 } 215 216 // Keep going. 217 window.setTimeout(this.opt.sSelf + '.fade();', 20); 218}
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.