;( function( $, window, document, undefined ) { "use strict"; var name = "newsTicker", defaults = { tickerSpeed: 2, autoPlay: true, stopHover: true }; function NewsTicker( el, opts ) { var $nt = this; $nt.options = {}; var elem = $(el), titl = elem.children(".ticker-title"), news = elem.children(".ticker-news"), unor = news.children("ul"), list = unor.children("li"), btns = elem.children(".ticker-buttons"), prev = btns.find(".ticker-prev"), next = btns.find(".ticker-next"), paus = btns.find(".icon-pause").parent(), nTr = !1, nFa = !0, ntPosition = function () { if (0 < titl.length && (news.css({left: titl.outerWidth()})), 0 < btns.length) { var btnsWidth = btns.outerWidth(); news.css({right: btnsWidth}); } var titleWidth = 0; list.each(function () { titleWidth += $(this).outerWidth() }), titleWidth += 10, unor.css({width: titleWidth}) }, ntTicker = function () { var el = parseFloat(unor.css("marginLeft")); el -= $nt.options.tickerSpeed / 2, unor.css({marginLeft: el}), el <= -unor.find("li:first-child").outerWidth() && ( unor.find("li:first-child").insertAfter(unor.find("li:last-child")), unor.css({marginLeft: 0}) ), !1 === nTr && ( window.requestAnimationFrame && requestAnimationFrame(ntTicker) || setTimeout(ntTicker, 16) ) }, ntNext = function () { unor.stop().animate({ marginLeft: -unor.find("li:first-child").outerWidth() }, 300, function () { unor.find("li:first-child").insertAfter(unor.find("li:last-child")), unor.css({marginLeft: 0}), nFa = !0 }) }, ntPrev = function () { ( 0 <= parseInt(unor.css("marginLeft"), 10) && (unor.css({ "margin-left": -unor.find("li:last-child").outerWidth() }), unor.find("li:last-child").insertBefore(unor.find("li:first-child"))), unor.stop().animate({marginLeft: 0}, 300, function () { nFa = !0 }) ) }, ntAutoPlay = function () { if (list.length == 1) { $nt.options.autoPlay = false, btns.hide() } if (nTr = !1, $nt.options.autoPlay) { ntTicker(); } }; $nt.init = function () { if ( $nt.options = $.extend({}, defaults, opts), ntPosition(), ntAutoPlay() ) var btns; $nt.options.autoPlay ? paus.find("span").removeClass("icon-play").addClass("icon-pause") : paus.find("span").removeClass("icon-pause").addClass("icon-play"), elem.on("mouseleave", function (el) { var ntft = $(document.elementFromPoint(el.clientX, el.clientY)).parents( ".news-ticker" )[0]; $(this)[0] !== ntft && ( !0 === $nt.options.stopHover ? !0 === $nt.options.autoPlay && $nt.autoPlay() : !0 === $nt.options.autoPlay && !0 === nTu && $nt.autoPlay() ) }), elem.on("mouseenter", function () { !0 === $nt.options.stopHover && $nt.pause() }), next.on("click", function () { nFa && (nFa = !1, $nt.pause(), $nt.next()) }), prev.on("click", function () { nFa && (nFa = !1, $nt.pause(), $nt.prev()) }), paus.on("click", function () { nFa && ( paus.find("span").hasClass("icon-pause") ? (paus.find("span").removeClass("icon-pause").addClass("icon-play"), $nt.stop()) : ( $nt.options.autoPlay = !0, paus.find("span").removeClass("icon-play").addClass("icon-pause") ) ) }); }, $nt.pause = function () { nTr = !0, clearInterval() }, $nt.stop = function () { nTr = !0, $nt.options.autoPlay = false }, $nt.autoPlay = function () { ntAutoPlay() }, $nt.next = function () { ntNext(); }, $nt.prev = function () { ntPrev(); }, $nt.init() } $.fn[name] = function ( opts ) { return this.each(function () { if (!$.data(this, name)) { $.data(this, name, new NewsTicker( this, opts )); } }); }; } )( jQuery, window, document );