|
@@ -1,76 +1,41 @@
|
|
|
-function smf_NewsFader(oOptions)
|
|
|
+function smc_NewsFader(oOptions)
|
|
|
{
|
|
|
- this.opt = oOptions;
|
|
|
-
|
|
|
- this.oFaderHandle = document.getElementById(this.opt.sFaderControlId);
|
|
|
-
|
|
|
- // Surround each item with... anything special?
|
|
|
- this.sItemTemplate = 'sItemTemplate' in this.opt ? this.opt.sItemTemplate : '%1$s';
|
|
|
-
|
|
|
- // Fade delay (in milliseconds).
|
|
|
- this.iFadeDelay = 'iFadeDelay' in this.opt ? this.opt.iFadeDelay : 5000;
|
|
|
-
|
|
|
- // The array that contains all the lines of the news for display.
|
|
|
- this.aFaderItems = 'aFaderItems' in this.opt ? this.opt.aFaderItems : [];
|
|
|
-
|
|
|
- // Should we look for fader data, still?
|
|
|
- this.bReceivedItemsOnConstruction = 'aFaderItems' in this.opt;
|
|
|
-
|
|
|
- // The current item in smfFadeContent.
|
|
|
- this.iFadeIndex = -1;
|
|
|
-
|
|
|
- // Just make sure the page is loaded before calling the init.
|
|
|
- var fader = this;
|
|
|
- $(document).ready(function() {fader.init();});
|
|
|
-}
|
|
|
-
|
|
|
-smf_NewsFader.prototype.init = function init()
|
|
|
-{
|
|
|
- var oForeEl, oForeColor, oBackEl, oBackColor;
|
|
|
-
|
|
|
- // Did we get our fader items on construction, or should we be gathering them instead?
|
|
|
- if (!this.bReceivedItemsOnConstruction)
|
|
|
- {
|
|
|
- // Get the news from the list in boardindex
|
|
|
- var oNewsItems = this.oFaderHandle.getElementsByTagName('li');
|
|
|
-
|
|
|
- // Fill the array that has previously been created
|
|
|
- for (var i = 0, n = oNewsItems.length; i < n; i ++)
|
|
|
- this.aFaderItems[i] = oNewsItems[i].innerHTML;
|
|
|
- }
|
|
|
-
|
|
|
- // Start the fader!
|
|
|
- this.fade();
|
|
|
-}
|
|
|
-
|
|
|
-// Main fading function... called 50 times every second.
|
|
|
-smf_NewsFader.prototype.fade = function fade()
|
|
|
-{
|
|
|
- if (this.aFaderItems.length <= 1)
|
|
|
- return;
|
|
|
-
|
|
|
- var currentText;
|
|
|
- // Starting out? Set up the first item.
|
|
|
- if (this.iFadeIndex == -1)
|
|
|
- {
|
|
|
- currentText = this.sItemTemplate.replace('%1$s', this.aFaderItems[0]);
|
|
|
- this.iFadeIndex = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Go to the next item, or first if we're out of items.
|
|
|
- currentText = this.sItemTemplate.replace('%1$s', this.aFaderItems[this.iFadeIndex ++]);
|
|
|
- if (this.iFadeIndex >= this.aFaderItems.length)
|
|
|
- this.iFadeIndex = 0;
|
|
|
- }
|
|
|
-
|
|
|
- $('#' + this.opt.sFaderControlId).each(function() {
|
|
|
- temp_elem = $(this).clone().css({height: 'auto'}).appendTo('body').html(currentText);
|
|
|
- final_height = parseInt(temp_elem.height()) + parseInt($(this).css('padding-top').replace(/[^-\d\.]/g, '')) + parseInt($(this).css('padding-bottom').replace(/[^-\d\.]/g, ''));
|
|
|
- temp_elem.remove();
|
|
|
- $(this).height($(this).height());
|
|
|
- }).html(currentText).animate({height: final_height}, 'slow');
|
|
|
-
|
|
|
- // Keep going.
|
|
|
- window.setTimeout(this.opt.sSelf + '.fade();', this.iFadeDelay);
|
|
|
+ var
|
|
|
+ aFaderItems = oOptions.aFaderItems || [],
|
|
|
+ iFadeIndex = 0,
|
|
|
+ iFadeDelay = oOptions.iFadeDelay || 5000,
|
|
|
+ iFadeSpeed = oOptions.iFadeSpeed || 650,
|
|
|
+ sItemTemplate = oOptions.sItemTemplate || '%1$s',
|
|
|
+ sControlId = '#' + oOptions.sFaderControlId,
|
|
|
+
|
|
|
+ fadeIn = function ()
|
|
|
+ {
|
|
|
+ iFadeIndex++;
|
|
|
+ if (iFadeIndex >= aFaderItems.length)
|
|
|
+ iFadeIndex = 0;
|
|
|
+
|
|
|
+ $(sControlId + ' li').html(sItemTemplate.replace('%1$s', aFaderItems[iFadeIndex])).fadeTo(iFadeSpeed, 0.99, function () {
|
|
|
+ // Restore ClearType in IE.
|
|
|
+ this.style.filter = '';
|
|
|
+ fadeOut();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fadeOut = function ()
|
|
|
+ {
|
|
|
+ setTimeout(function ()
|
|
|
+ {
|
|
|
+ $(sControlId + ' li').fadeTo(iFadeSpeed, 0, fadeIn);
|
|
|
+ }, iFadeDelay);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (!aFaderItems.length)
|
|
|
+ $(sControlId + ' li').each(function ()
|
|
|
+ {
|
|
|
+ aFaderItems.push($(this).html());
|
|
|
+ });
|
|
|
+
|
|
|
+ $(sControlId).html('<li>' + sItemTemplate.replace('%1$s', aFaderItems[0]) + '</li>').show();
|
|
|
+
|
|
|
+ fadeOut();
|
|
|
}
|