123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- function smf_NewsFader(oOptions)
- {
- this.opt = oOptions;
- this.oFaderHandle = document.getElementById(this.opt.sFaderControlId);
-
- this.oFadeFrom = 'oFadeFrom' in this.opt ? this.opt.oFadeFrom : {
- r: 0,
- g: 0,
- b: 0
- };
-
- this.oFadeTo = 'oFadeTo' in this.opt ? this.opt.oFadeTo : {
- r: 255,
- g: 255,
- b: 255
- };
-
- this.sItemTemplate = 'sItemTemplate' in this.opt ? this.opt.sItemTemplate : '%1$s';
-
- this.iFadeDelay = 'iFadeDelay' in this.opt ? this.opt.iFadeDelay : 5000;
-
- this.aFaderItems = 'aFaderItems' in this.opt ? this.opt.aFaderItems : [];
-
- this.bReceivedItemsOnConstruction = 'aFaderItems' in this.opt;
-
- this.iFadeIndex = -1;
-
- this.iFadePercent = 510
-
- this.bFadeSwitch = false;
-
- setTimeout(this.opt.sSelf + '.init();', 1);
- }
- smf_NewsFader.prototype.init = function init()
- {
- var oForeEl, oForeColor, oBackEl, oBackColor;
-
- if ('currentStyle' in this.oFaderHandle)
- {
- oForeColor = this.oFaderHandle.currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
- this.oFadeFrom = {
- r: parseInt(oForeColor[1]),
- g: parseInt(oForeColor[2]),
- b: parseInt(oForeColor[3])
- };
- oBackEl = this.oFaderHandle;
- while (oBackEl.currentStyle.backgroundColor == 'transparent' && 'parentNode' in oBackEl)
- oBackEl = oBackEl.parentNode;
- oBackColor = oBackEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
- this.oFadeTo = {
- r: eval('0x' + oBackColor[1]),
- g: eval('0x' + oBackColor[2]),
- b: eval('0x' + oBackColor[3])
- };
- }
- else if (!('opera' in window) && 'defaultView' in document)
- {
- oForeEl = this.oFaderHandle;
- while (document.defaultView.getComputedStyle(oForeEl, null).getPropertyCSSValue('color') == null && 'parentNode' in oForeEl && 'tagName' in oForeEl.parentNode)
- oForeEl = oForeEl.parentNode;
- oForeColor = document.defaultView.getComputedStyle(oForeEl, null).getPropertyValue('color').match(/rgb\((\d+), (\d+), (\d+)\)/);
- this.oFadeFrom = {
- r: parseInt(oForeColor[1]),
- g: parseInt(oForeColor[2]),
- b: parseInt(oForeColor[3])
- };
- oBackEl = this.oFaderHandle;
- while (document.defaultView.getComputedStyle(oBackEl, null).getPropertyCSSValue('background-color') == null && 'parentNode' in oBackEl && 'tagName' in oBackEl.parentNode)
- oBackEl = oBackEl.parentNode;
- oBackColor = document.defaultView.getComputedStyle(oBackEl, null).getPropertyValue('background-color');
- this.oFadeTo = {
- r: parseInt(oBackColor[1]),
- g: parseInt(oBackColor[2]),
- b: parseInt(oBackColor[3])
- };
- }
-
- if (!this.bReceivedItemsOnConstruction)
- {
-
- var oNewsItems = this.oFaderHandle.getElementsByTagName('li');
-
- for (var i = 0, n = oNewsItems.length; i < n; i ++)
- this.aFaderItems[i] = oNewsItems[i].innerHTML;
- }
-
- this.oFadeRange = {
- 'r': this.oFadeFrom.r - this.oFadeTo.r,
- 'g': this.oFadeFrom.g - this.oFadeTo.g,
- 'b': this.oFadeFrom.b - this.oFadeTo.b
- };
-
- this.iFadeDelay /= 20;
-
- window.setTimeout(this.opt.sSelf + '.fade();', 20);
- }
- smf_NewsFader.prototype.fade = function fade()
- {
- if (this.aFaderItems.length <= 1)
- return;
-
- if ('readyState' in document && document.readyState != 'complete')
- {
- window.setTimeout(this.opt.sSelf + '.fade();', 20);
- return;
- }
-
- if (this.iFadeIndex == -1)
- {
- setInnerHTML(this.oFaderHandle, this.sItemTemplate.replace('%1$s', this.aFaderItems[0]));
- this.iFadeIndex = 1;
-
- if ('MozOpacity' in this.oFaderHandle.style)
- this.oFaderHandle.style.MozOpacity = '0.90';
- else if ('opacity' in this.oFaderHandle.style)
- this.oFaderHandle.style.opacity = '0.90';
-
- else if ('filter' in this.oFaderHandle.style)
- this.oFaderHandle.style.filter = 'alpha(opacity=100)';
- }
-
- if (this.iFadePercent >= 510)
- this.bFadeSwitch = !this.bFadeSwitch;
-
- else if (this.iFadePercent <= -64)
- {
- this.bFadeSwitch = !this.bFadeSwitch;
-
- setInnerHTML(this.oFaderHandle, this.sItemTemplate.replace('%1$s', this.aFaderItems[this.iFadeIndex ++]));
- if (this.iFadeIndex >= this.aFaderItems.length)
- this.iFadeIndex = 0;
- }
-
- if (this.bFadeSwitch)
- this.iFadePercent -= 255 / this.iFadeDelay * 2;
- else
- this.iFadePercent += 255 / this.iFadeDelay * 2;
-
- if (this.iFadePercent < 256 && this.iFadePercent > 0)
- {
-
- var tempPercent = this.iFadePercent / 255, rounded;
- if ('MozOpacity' in this.oFaderHandle.style)
- {
- rounded = Math.round(tempPercent * 100) / 100;
- this.oFaderHandle.style.MozOpacity = rounded == 1 ? '0.99' : rounded;
- }
- else if ('opacity' in this.oFaderHandle.style)
- {
- rounded = Math.round(tempPercent * 100) / 100;
- this.oFaderHandle.style.opacity = rounded == 1 ? '0.99' : rounded;
- }
- else
- {
- var done = false;
- if ('alpha' in this.oFaderHandle.filters)
- {
- try
- {
- this.oFaderHandle.filters.alpha.opacity = Math.round(tempPercent * 100);
- done = true;
- }
- catch (err)
- {
- }
- }
- if (!done)
- {
-
- var r = Math.ceil(this.oFadeTo.r + this.oFadeRange.r * tempPercent);
- var g = Math.ceil(this.oFadeTo.g + this.oFadeRange.g * tempPercent);
- var b = Math.ceil(this.oFadeTo.b + this.oFadeRange.b * tempPercent);
-
- this.oFaderHandle.style.color = 'rgb(' + r + ', ' + g + ', ' + b + ')';
- }
- }
- }
-
- window.setTimeout(this.opt.sSelf + '.fade();', 20);
- }
|