forked from vaakash/jquery-easy-ticker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.easy-ticker.min.js
1 lines (1 loc) · 7.98 KB
/
jquery.easy-ticker.min.js
1
(function(e,d,b,g){var c="easyTicker",f={mode:"easing",needFocus:false,direction:"up",easing:"linear",speed:"slow",interval:2000,dummy:{use:true,height:100,html:"li"},height:"auto",visible:0,mousePause:1,controls:{up:"",down:"",toggle:"",playText:"Play",stopText:"Stop"}};function a(h,j){var q=this;q.opts=e.extend({},f,j);q.elem=e(h);q.targ=e(h).children(":first-child");q.timer=0;q.mHover=0;q.winFocus=1;q.counter=0;q.run=false;q.queue={};q.queue.add=new Array;q.queue.remove=new Array;q.queue.update=new Array;q.callback={first:g,last:g};q.dummy={init:0,current:0};v();l();e([d,b]).off("focus.jqet").on("focus.jqet",function(){q.winFocus=1}).off("blur.jqet").on("blur.jqet",function(){q.winFocus=0});if(q.opts.mousePause==1){q.elem.mouseenter(function(){q.timerTemp=q.timer;u()}).mouseleave(function(){if(q.timerTemp!==0){l()}});return(true)}e(q.opts.controls.up).on("click",function(s){s.preventDefault();x("up");return(true)});e(q.opts.controls.down).on("click",function(s){s.preventDefault();x("down");return(true)});e(q.opts.controls.toggle).on("click",function(s){s.preventDefault();if(q.timer==0){l()}else{u()}return(true)});function v(){q.run=true;if(q.opts.dummy.use){q.dummy.init=Math.floor(e(d).height()/q.opts.dummy.height)+1;q.dummy.current=q.dummy.init;if(q.dummy.current<=q.targ.children().length){q.dummy.init=0;q.dummy.current=q.dummy.init}else{q.dummy.init=q.dummy.current-q.targ.children().length;q.dummy.current=q.dummy.init}var s=0;while(s<q.dummy.current){var B=e("<"+q.opts.dummy.html+">",{html:" ",data:{dummy:true},style:"height: "+q.opts.dummy.height+"px"});q.targ.prepend(B);s++}}q.elem.children().css("margin",0).children().css("margin",0);if(q.opts.direction=="up"){q.targ.children().each(function(){if(!e(this).data("dummy")){e(this).attr("itemno",q.counter);e(this).data("itemno",q.counter);q.counter++}})}else{q.targ.children().each(function(){if(!e(this).data("dummy")){q.counter++;e(this).attr("itemno",q.targ.children().length-q.counter);e(this).data("itemno",q.targ.children().length-q.counter)}})}q.elem.css({position:"relative",height:q.opts.height,overflow:"hidden"});q.targ.css({position:"absolute",margin:0});setInterval(function(){m()},100);return(true)}function l(){switch(q.opts.mode){case"easing":q.timer=setInterval(function(){if(q.winFocus==1||!q.opts.needFocus){t(q.opts.direction)}},q.opts.interval);break;case"continuous":if(q.winFocus==1||!q.opts.needFocus){t(q.opts.direction)}break}q.run=true;e(q.opts.controls.toggle).addClass("et-run").html(q.opts.controls.stopText);return(true)}function u(){clearInterval(q.timer);q.timer=0;q.run=false;e(q.opts.controls.toggle).removeClass("et-run").html(q.opts.controls.playText);return(true)}function t(E){if(!q.run){return(false)}var F,C,D,B;if(!q.elem.is(":visible")){return}if(E=="up"){C="-=";D="appendTo";B=q.targ.children(":first-child")}else{C="+=";D="prependTo";B=q.targ.children(":last-child")}var s=B.outerHeight();q.targ.stop(true,true).animate({top:C+s+"px"},q.opts.speed,q.opts.easing,function(){B.hide(function(){if(e(this).data("itemno")>=0){if(typeof(q.callback.last)=="function"){q.callback.last.call(this,B)}}})[D](q.targ).fadeIn(function(){if(e(this).data("itemno")>=0){if(typeof(q.callback.first)=="function"){q.callback.first.call(this,B)}}});q.targ.css("top",0);m();p();if(q.opts.mode=="continuous"){t(E)}});return(true)}function p(){var s=q.opts.direction;if(s=="up"){sel=":last-child"}else{sel=":first-child"}var F=q.targ.children(sel);if(q.targ.children(":last-child").data("dummy")){if(q.dummy.current<e(h).find(":data(dummy)").length){q.targ.children(":last-child").remove()}if(q.dummy.init>q.targ.children().length){var B=e("<"+q.opts.dummy.html+">",{html:" ",data:{dummy:true},style:"height: "+q.opts.dummy.height+"px"});q.targ.append(B);q.dummy.current++}}if(q.queue.add){if(s=="up"){if(F.data("itemno")==w()){e.each(q.queue.add,function(H,G){if(typeof(G)=="object"){q.targ.append(G[0]);itemEl=q.targ.children('[itemno="'+H+'"]').eq(0);if(typeof(G[1])=="function"){G[1].call(itemEl,H,e(itemEl))}if(typeof(q.callback.first)=="function"){q.callback.first.call(itemEl,e(itemEl))}}delete q.queue.add[H]})}}else{if(F.data("itemno")==k()){e.each(q.queue.add.reverse(),function(H,G){if(typeof(G)=="object"){q.targ.append(G[0]);itemEl=q.targ.children('[itemno="'+H+'"]').eq(0);if(typeof(G[1])=="function"){G[1].call(itemEl,H,e(itemEl))}if(typeof(q.callback.first)=="function"){q.callback.first.call(itemEl,e(itemEl))}}delete q.queue.add[H]})}}var E=new Array;e.each(q.queue.add,function(H,G){if(typeof(G)=="object"){if(typeof(G[0])=="object"){E[H]=G}}});q.queue.add=E}if(q.queue.remove){itemLast=q.targ.children(":last-child");if(typeof(q.queue.remove[itemLast.data("itemno")])=="object"){data=q.queue.remove[itemLast.data("itemno")];itemHtml=data[0];e(itemHtml).remove();if(typeof(data[1])=="function"){data[1].call(this,itemLast.data("itemno"),true)}delete q.queue.remove[itemLast.data("itemno")]}var D=new Array;e.each(q.queue.remove,function(H,G){if(typeof(G)=="object"){if(typeof(G[0])=="object"){D[H]=G}}});q.queue.remove=D}if(q.queue.update){itemLast=q.targ.children(":last-child");if(typeof(q.queue.update[itemLast.data("itemno")])=="object"){data=q.queue.update[itemLast.data("itemno")];itemCurrent=itemLast;e(itemCurrent).replaceWith(data[0]);if(typeof(data[1])=="function"){data[1].call(this,data[0])}delete q.queue.update[itemLast.data("itemno")]}var C=new Array;e.each(q.queue.update,function(H,G){if(typeof(G)=="object"){if(typeof(G[0])=="object"){C[H]=G}}});q.queue.update=C}return(true)}function w(){var s;q.targ.children().each(function(){if(typeof(s)=="undefined"){s=e(this).data("itemno")}if(s>e(this).data("itemno")){s=e(this).data("itemno")}});return(s)}function k(){var s;q.targ.children().each(function(){if(typeof(s)=="undefined"){s=e(this).data("itemno")}if(s<e(this).data("itemno")){s=e(this).data("itemno")}});return(s)}function x(s){u();if(s=="up"){t("up")}else{t("down")}return(true)}function A(){var s=0;var B=q.elem.css("display");q.elem.css("display","block");q.targ.children().each(function(){s+=e(this).outerHeight()});q.elem.css({display:B,height:s});return(true)}function n(B){var s=0;q.targ.children(":lt("+q.opts.visible+")").each(function(){s+=e(this).outerHeight()});if(B==1){q.elem.stop(true,true).animate({height:s},q.opts.speed)}else{q.elem.css("height",s)}return(true)}function m(){if(q.opts.height=="auto"&&q.opts.visible!=0){anim=arguments.callee.caller.name=="init"?0:1;n(anim)}else{if(q.opts.height=="auto"){A()}}return(true)}function y(s){if(typeof(s)=="function"){q.callback.first=s}}function i(s){if(typeof(s)=="function"){q.callback.last=s}}function r(B,s,C){s=s||false;newItem=e.parseHTML(B);e(newItem).attr("itemno",q.counter);e(newItem).data("itemno",q.counter);e(newItem).css({margin:0});if(s){q.queue.add[q.counter]=new Array(newItem,C)}else{q.targ.append(newItem);if(typeof(C)=="function"){C.call(this,q.counter,B)}}if(q.dummy.current>0){q.dummy.current--}q.counter++;return(e(newItem))}function z(C,s,D){s=s||false;var B=false;q.targ.children().each(function(){if(e(this).data("itemno")==C){if(s){if(typeof(q.queue.remove[e(this).data("itemno")])=="object"){B=false}else{q.queue.remove[e(this).data("itemno")]=new Array(e(this),D);B=true}}else{if(typeof(q.queue.remove[e(this).data("itemno")])=="object"){delete q.queue.remove[e(this).data("itemno")]}e(this).remove();B=true;if(typeof(D)=="function"){D.call(this,C,true)}}}});return(B)}function o(C,B,s,D){s=s||false;itemNew=e.parseHTML(B);e(itemNew).attr("itemno",C);e(itemNew).data("itemno",C);e(itemNew).css({margin:0});if(s){q.queue.update[C]=new Array(itemNew,D)}else{itemCurrent=q.targ.children('[itemno="'+C+'"]').eq(0);e(itemCurrent).replaceWith(itemNew);if(typeof(D)=="function"){D.call(this,C,itemCurrent)}}}return{onFirst:function(s){return(y(s))},onLast:function(s){return(i(s))},add:function(B,s,C){return(r(B,s,C))},remove:function(B,s,C){return(z(B,s,C))},update:function(C,B,s,D){return(o(C,B,s,D))},up:function(){return(x("up"))},down:function(){return(x("down"))},start:l,stop:u,options:q.opts}}e.fn[c]=function(h){return this.each(function(){if(!e.data(this,c)){e.data(this,c,new a(this,h))}})}})(jQuery,window,document);