(function($) { $.fn.extend({ ticker: function() { $(this).parent().hide(); return; var tickerTable =$(this).find("table:first"); var tickerBody =$(this).find(".ticker-body:first"); var tickerControls =$(this).find(".ticker-controls:first"); var tmrTickerEffect = null; var tmrNextTicker = null; var tmrType=null; var tmrAutoScroll=null; var currentTickerIndex = 0; var tickerObj = null; var isAnimating = true; var currentCharPos=0; var processingClick = false; var tempButton = null; if(duration==-1) { return; } setTimeout(function() { tickerComplete(true); }, 100); tickerControls.find('td').on('click', function() { var cmd = $(this).attr('id'); // Ensure only one button is processed at a time to avoid race conditions if (processingClick == false) { processingClick = true; tempButton = $(this); // De-activate button mouse over style tickerControls.find('td').removeClass('ui-state-active'); tickerControls.find('td').off('mouseenter mouseleave'); // Remember position of mouse tickerControls.find('td').on('mouseenter', function() { tempButton = $(this); }).on('mouseleave', function() { tempButton = null; }); if ((cmd == "next" || cmd == "previous") && isAnimating) stopAnimation(); if (cmd == "play" && !isAnimating) { $(this).hide(); $(this).parent().find('#stop').show(); tempButton = $(this).parent().find('#stop'); setTimeout(function() { tickerComplete(true); }, 100); isAnimating = true; } else if (cmd == "stop" && isAnimating) { stopAnimation(); tempButton = $(this).parent().find('#play'); } else if (cmd == "next") showNext(); else if (cmd == "previous") showPrevious(); setTimeout(function() { processingClick = false; // Re-activate mouse currently over styles if (tempButton != null) { tempButton.addClass('ui-state-active'); } tickerControls.find('td').on('mouseenter', function() { $(this).addClass('ui-state-active'); }).on('mouseleave', function() { $(this).removeClass('ui-state-active'); }); }, 1000); } }); tickerControls.find('td').on('mouseenter', function() { $(this).addClass('ui-state-active'); }).on('mouseleave', function() { $(this).removeClass('ui-state-active'); }); tickerBody.on('mouseup', function() { if(tickerData[currentTickerIndex].link.length>0) { setTimeout(function() { window.open(tickerData[currentTickerIndex].link); }, 100); } }); function stopAnimation() { tickerControls.find('#stop').hide(); tickerControls.find('#play').show(); if (tmrTickerEffect != null) clearTimeout(tmrTickerEffect); if (tmrNextTicker != null) { clearTimeout(tmrNextTicker); tmrNextTicker = null; } if (tmrType != null) clearTimeout(tmrType); showTickerItem(); autoScroll(); isAnimating = false; currentCharPos=0; } function moveNext() { currentTickerIndex += 1; if (currentTickerIndex >= tickerData.length) currentTickerIndex = 0; } function showNext() { currentTickerIndex += 1; if (currentTickerIndex >= tickerData.length) currentTickerIndex = 0; showTickerItem(); autoScroll(); } function showPrevious() { currentTickerIndex -= 1; if (currentTickerIndex < 0) currentTickerIndex = tickerData.length - 1; showTickerItem(); autoScroll(); } function showTickerItem() { var tickerTitle = tickerBody.find('.ticker-title-text:first'); var tickerText = tickerBody.find('.ticker-text:first').find('span:first'); tickerTitle.html(tickerData[currentTickerIndex].title); tickerText.html(tickerData[currentTickerIndex].description); /* Center ticker text*/ var ah = tickerText.height(); var ph = tickerText.parent().height(); var mh = 0; if(ph>ah) mh=(ph - ah) / 2; tickerText.css('margin-top', mh); } function autoScroll() { if(tmrAutoScroll !=null) clearTimeout(tmrAutoScroll); var tickerText = tickerBody.find('.ticker-text:first').find('span:first'); if(tickerText.height()-3>tickerText.parent().height()) { tickerText.parent().scrollTop(0); tickerText.parent().stop(true,false); tmrAutoScroll=setTimeout(function() { tickerText.parent().animate({scrollTop:tickerText.height() }, 3000); },1500); } } function tickerComplete(immediateStart) { if (isAnimating) { tmrTickerEffect = setTimeout(function() { tickerBody.find('.ticker-text:first').find('span:first').html(""); //tickerBody.hide(); //tickerBody.show('blind',{},500); }, immediateStart == true ? 0 : parseFloat(delay) - 500); tmrNextTicker = setTimeout(function() { var tickerText = tickerBody.find('.ticker-text:first').find('span:first'); if (effect == "typewriter") { moveNext(); setTimeout(function() { tickerBody.find('.ticker-title-text:first').html(tickerData[currentTickerIndex].title); type(); }, 100); } else { showNext(); tickerText.hide(); tickerText.show(duration, effect, {}); setTimeout(function() { tickerComplete() }, 100); } }, immediateStart == true ? 500 : parseFloat(delay)); } } function type() { var tickerText = tickerBody.find('.ticker-text:first').find('span:first'); tickerText.html(tickerData[currentTickerIndex].description.substr(0, currentCharPos++)+" _"); /* Center ticker text*/ var ah = tickerText.height(); var ph = tickerText.parent().height(); var mh = 0; if(ph>ah) mh=(ph - ah) / 2; tickerText.css('margin-top', mh); //tickerText.parent().scrollLeft(tickerText.width()); //tickerText.parent().animate({ scrollLeft: tickerText.width() }, 500); tickerText.parent().scrollTop(tickerText.height()); if (currentCharPos < tickerData[currentTickerIndex].description.length + 1) { tmrType=setTimeout(function() { type(); }, duration); } else { tickerText.html(tickerData[currentTickerIndex].description); tmrType=null; currentCharPos=0; tickerComplete(false); } } } }); })(jQuery);