-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathscroller.min.js
1 lines (1 loc) · 12.7 KB
/
scroller.min.js
1
(function(d){var g={extend:function(h,i){i.prototype=Object.create(h.prototype);i.prototype.constructor=h;return i},clone:function(i){if(null==i||"object"!=typeof i){return i}var j=i.constructor();for(var h in i){if(i.hasOwnProperty(h)){j[h]=i[h]}}return j}};function b(h){this.fragment=null;this.div=null;this.innerDdiv=null;this.direction=h.direction||null;this.interval=h.interval||0;this.amount=h.amount||0;this.width=h.width||0;this.height=h.amount||0;this.textAlign=h.textAlign||"center";this.upperBound=h.upperBound||9;this.forceFallback=h.forceFallback||false;this.mode=h._mode||a.MODE.COUNTUP;this.stepSize=Math.ceil((this.amount+1)*1/10)||2;this.stepInterval=0;this.step=1;this.startNum=1;this.endNum=1;this.nextNum=1;this.firstChild=null;this.lastChild=null;this.count=0}b.prototype=(function(){return{init:function(){this.fragment=document.createDocumentFragment();this.div=document.createElement("div");this.div.className="scroller";this.div.setAttribute("style","position:relative;overflow:hidden;width:"+this.width+"px;text-align:"+this.textAlign+";height:"+(this.height)+"px;line-height:"+this.height+"px;");this.innerDiv=document.createElement("div");this.innerDiv.className="scroller-inner-pane";this.innerDiv.setAttribute("style","position:absolute;width:"+this.width+"px;text-align:"+this.textAlign+";top:0;");this.firstChild=document.createElement("span");this.firstChild.className="scroller-span";this.firstChild.setAttribute("style","position:absolute;height:"+this.height+"px;line-height:"+this.height+"px;left:0px;top:0px;width:"+this.width+"px;");this.innerDiv.appendChild(this.firstChild);this.lastChild=document.createElement("span");this.lastChild.className="scroller-span";this.lastChild.setAttribute("style","position:absolute;height:"+this.height+"px;line-height:"+this.height+"px;left:0px;width:"+this.width+"px;");switch(this.direction){case a.DIRECTION.UP:this.innerDiv.appendChild(this.lastChild);this.lastChild.style.top=this.height+"px";break;case a.DIRECTION.DOWN:this.innerDiv.insertBefore(this.lastChild,this.firstChild);this.lastChild.style.top=(-this.height)+"px";break}this.div.appendChild(this.innerDiv);this.fragment.appendChild(this.div);this.innerInit();return this},innerInit:function(){},start:function(i,h){i=parseInt(i);h=parseInt(h);this.startNum=i;this.endNum=h;this.nextNum=this.startNum;if(this.mode==a.MODE.COUNTDOWN){if(i!=h){this.step=(this.endNum>this.startNum)?(this.startNum+(this.upperBound+1)-this.endNum):(this.startNum-this.endNum)}else{this.step=Number.MAX_VALUE}}else{if(i!=h){this.step=(this.endNum<this.startNum)?(this.endNum+(this.upperBound+1)-this.startNum):(this.endNum-this.startNum)}else{this.step=Number.MAX_VALUE}}this.firstChild.innerHTML=this.startNum;this.lastChild.innerHTML=this.nextNum;this.innerStart();this.iterate()},innerStart:function(){},iterate:function(){if(this.nextNum!=this.endNum||this.lastChild.innerHTML!=this.endNum){if(this.nextNum==this.endNum){this.nextNum=parseInt(this.lastChild.innerHTML)}if(this.mode==a.MODE.COUNTDOWN){this.nextNum=(this.nextNum==0)?this.upperBound:(this.nextNum-1)}else{this.nextNum=(this.nextNum==this.upperBound)?0:(this.nextNum+1)}this.innerIterate()}},innerIterate:function(){},scroll:function(){},stop:function(){},revalidate:function(){this.nextNum=parseInt(this.nextNum);this.endNum=parseInt(this.endNum);if(this.nextNum==this.endNum){return}if(this.mode==a.MODE.COUNTDOWN){if(this.nextNum!=this.endNum){this.step=(this.endNum>this.nextNum)?(this.nextNum+(this.upperBound+1)-this.endNum):(this.nextNum-this.endNum)}else{this.step=Number.MAX_VALUE}}else{if(this.nextNum!=this.endNum){this.step=(this.endNum<this.nextNum)?(this.endNum+(this.upperBound+1)-this.nextNum):(this.endNum-this.nextNum)}else{this.step=Number.MAX_VALUE}}this.innerRevalidate()},innerRevalidate:function(){},resetPosition:function(){this.innerDiv.style.top="0px";this.innerDiv.offsetHeight},getPanel:function(){return this.fragment},setEndNum:function(h){this.endNum=h},setMode:function(h){this.mode=h}}})();function c(h){b.call(this,h)}g.extend(b,c);c.prototype._props={};c.prototype._cssPropMap={"transition-timing-function":"TransitionTimingFunction","transition-duration":"TransitionDuration",transform:"Transform"};c.prototype._set=function(o,k,n){if(this._props[k]){o.style.setProperty(this._props[k],n,"important")}else{var m="-webkit- -moz- -ms- -o-".split(" ");c.prototype._props[k]=k;for(var j=0,h=m.length;j<h;++j){var p=m[j].replace(/-/g,"");p=(p=="moz")?"Moz":p;var l=p+c.prototype._cssPropMap[k];if(o.style[l]!==undefined){c.prototype._props[k]=m[j]+k;break}}this._set(o,k,n)}};c.prototype._addEventListener=function(k,i){var j={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",MSTransition:"msTransitionEnd",OTransition:"oTransitionEnd",transition:"transitionend"};for(var h in j){if(k.style[h]!==undefined){k.addEventListener(j[h],function(m){var l=k.style.transitionDuration||k.style.webkitTransitionDuration;if(l!="0ms"){i.stop()}},false);break}}};c.prototype.innerInit=function(){this._addEventListener(this.innerDiv,this);this._set(this.innerDiv,"transition-timing-function","linear")};c.prototype.innerStart=function(){this.stepInterval=Math.max(1,Math.floor(this.interval*1/this.step));if(this.direction==a.DIRECTION.UP){this.amount=-this.amount}};c.prototype.innerIterate=function(){this.firstChild.innerHTML=this.lastChild.innerHTML;this.lastChild.innerHTML=this.nextNum;this.lastChild.offsetHeight;var h=this;setTimeout(function(){h.scroll()},0)};c.prototype.scroll=function(){var i=1+(Math.random()/100000);var j="translateY("+this.amount+"px) scaleX("+i+")";var h=(this.stepInterval)+"ms";this._set(this.innerDiv,"transition-duration",h);this._set(this.innerDiv,"transform",j)};c.prototype.stop=function(){var i=1+(Math.random()/100000);var k="translateY(0px) scaleX("+i+")";var h="0ms";this.firstChild.innerHTML=this.lastChild.innerHTML;this.lastChild.offsetHeight;this.nextNum=parseInt(this.lastChild.innerHTML);this._set(this.innerDiv,"transition-duration",h);this._set(this.innerDiv,"transform",k);var j=this;setTimeout(function(){j.iterate()},1)};c.prototype.innerRevalidate=function(){this.stepInterval=Math.max(1,Math.floor(this.interval*1/this.step))};function e(h){b.call(this,h);this.scrolledAmount=0;this.scrollID=null}g.extend(b,e);e.prototype.innerStart=function(){this.stepInterval=Math.ceil((this.interval*this.stepSize)/(this.amount*this.step))};e.prototype.innerIterate=function(){this.firstChild.innerHTML=this.lastChild.innerHTML;this.lastChild.innerHTML=this.nextNum;this.lastChild.offsetHeight;this.scroll()};e.prototype.scroll=function(){var h=this.innerDiv.style;var j=parseInt(h.top);switch(this.direction){case a.DIRECTION.UP:h.top=(j-this.stepSize)+"px";break;case a.DIRECTION.DOWN:h.top=(j+this.stepSize)+"px";break;default:break}this.scrolledAmount+=this.stepSize;if(this.scrolledAmount<this.amount){this.stepSize=Math.min(this.stepSize,(this.amount-this.scrolledAmount));var i=this;this.scrollID=setTimeout(function(){i.scroll()},this.stepInterval)}else{if(this.scrollID!=null){clearTimeout(this.scrollID)}this.stop();this.iterate()}};e.prototype.stop=function(){this.scrolledAmount=0;this.firstChild.innerHTML=this.lastChild.innerHTML;this.resetPosition()};e.prototype.innerRevalidate=function(){this.stepInterval=Math.ceil((this.interval*this.stepSize)/(this.amount*this.step))};var f=(function(){var h=i("transform");function i(j){var m=false,l="Webkit Moz ms O Khtml".split(" "),o=document.createElement("div"),n=null;j=j.toLowerCase();if(o.style[j]!==undefined){m=true}if(m===false){n=j.charAt(0).toUpperCase()+j.substr(1);for(var k=0;k<l.length;k++){if(o.style[l[k]+n]!==undefined){m=true;break}}}return m}return{createScrollPanel:function(j){if(h&&!j.forceFallback){return new c(j)}else{return new e(j)}}}})();var a=(function(){var j=0;function k(l){this.scrollPanelArray=[];this.props=l;this.scrollPane=document.createElement("div");this.table=null;this.beginNum=0;this.endNum=0;this.css=null;this.width=this.props.width;this.init(0,0)}k.prototype={init:function(m,o){this.clear();this.oldCountArray=[];this.newCountArray=[];this.scrollPanelArray=[];this.beginNum=m;this.endNum=o;m=m+"";o=o+"";var q=m.length,r=o.length;for(var p=0;p<q;++p){this.oldCountArray.push(m.charAt(p))}for(var p=0;p<r;++p){this.newCountArray.push(o.charAt(p))}var u=Math.abs(q-r);var l=Math.max(q,r);if(q>r){for(var p=1;p<=u;++p){this.newCountArray.unshift("0")}}else{if(q<r){for(var p=1;p<=u;++p){this.oldCountArray.unshift("0")}}}var n=document.createDocumentFragment();this.table=document.createElement("table");this.table.className="scroller-table";this.table.setAttribute("style","margin:auto;");if(this.css!=null){this.setStyle(this.css)}var s=Math.floor(this.width/l);this.props._mode=(this.beginNum>this.endNum)?a.MODE.COUNTDOWN:a.MODE.COUNTUP;this.props.width=s;this.innerInit(l);n.appendChild(this.table);this.scrollPane.appendChild(n);for(var p=0,t=this.oldCountArray.length;p<t;++p){this.scrollPanelArray[p].start(this.oldCountArray[p],this.oldCountArray[p])}},innerInit:function(m){var l=0;if(this.props.separatorType!==a.SEPARATOR.NONE){l=this.props.separatorType+1-m%(this.props.separatorType)}var p=document.createElement("tr");for(var n=0;n<m;++n){var s=document.createElement("td");var r=f.createScrollPanel(this.props).init();this.scrollPanelArray.push(r);s.appendChild(r.getPanel());p.appendChild(s);if(this.props.separatorType!=a.SEPARATOR.NONE&&(n+l)%this.props.separatorType===0&&(n+1)<m){var s=document.createElement("td");var q=document.createElement("div");q.className="scroller-separator-pane";var o=document.createElement("span");o.className="scroller-span";o.innerHTML=this.props.separator;q.setAttribute("style","height:"+(this.props.amount+10)+"px;line-height:"+this.props.amount+"px;left:0px;top:0px;vertical-align:middle;");q.appendChild(o);s.appendChild(q);p.appendChild(s)}}this.table.appendChild(p)},appendTo:function(l){l.appendChild(this.scrollPane);return this},getScrollPanels:function(){return this.scrollPanelArray},setStyle:function(o){this.css=o;if(typeof o==="string"){var l=o.split(";");for(var n in l){var q=l[n].split(":");var m=q[0];var p=(q.length==2)?q[1]:"";if(!this.isUnmodifiableStyle(m)){this.table.style[m]=p}}}else{if(typeof o==="object"){for(var r in o){this.table.style[r]=o[r]}}}},isUnmodifiableStyle:function(n){var l=["position","overflow"];for(var m in l){if(n.toLowerCase()===l[m]){return true}}return false},start:function(m){var l=0;if(typeof m==="number"){l=parseInt(m)+""}else{l=m.trim().replace(/,/g,"")}this.init(m,m)},scrollTo:function(o){var n=(o+"").trim().replace(/,:/g,"");if(n.length!=this.newCountArray.length){this.init(this.endNum,n)}else{this.beginNum=this.endNum;this.oldCountArray=this.newCountArray;this.endNum=n;this.newCountArray=[];this.props._mode=(this.beginNum>this.endNum)?a.MODE.COUNTDOWN:a.MODE.COUNTUP;for(var m=0,l=n.length;m<l;++m){this.newCountArray.push(n.charAt(m))}}this.refresh()},scrollFromTo:function(m,l){var m=(m+"").trim().replace(/,:/g,"");var l=(l+"").trim().replace(/,:/g,"");this.start(m);this.scrollTo(l)},refresh:function(){var l=this;setTimeout(function(){for(var n=0,m=l.oldCountArray.length;n<m;++n){if(l.props._mode!==undefined){l.scrollPanelArray[n].setMode(l.props._mode)}l.scrollPanelArray[n].setEndNum(l.newCountArray[n]);l.scrollPanelArray[n].revalidate();l.scrollPanelArray[n].iterate()}},1)},clear:function(){while(this.scrollPane.firstChild){this.scrollPane.removeChild(this.scrollPane.firstChild)}}};function i(l){k.call(this,l)}g.extend(k,i);i.prototype.innerInit=function(m){var t=this.props.separatorType+1-m%(this.props.separatorType);var q=document.createElement("tr");for(var p=0;p<m;++p){var n=document.createElement("td");var r=g.clone(this.props);if(p%2==0){if(p==0){r.upperBound=2}else{r.upperBound=5}}var o=f.createScrollPanel(r).init();this.scrollPanelArray.push(o);n.appendChild(o.getPanel());q.appendChild(n);if((p+t)%r.separatorType===0&&(p+1)<m){var n=document.createElement("td");var l=document.createElement("div");var s=document.createElement("span");s.className="scroller-span";s.innerHTML=r.separator;l.setAttribute("style","height:"+(r.amount+10)+"px;line-height:"+r.amount+"px;left:0px;top:0px;vertical-align:middle;");l.appendChild(s);n.appendChild(l);q.appendChild(n)}}this.table.appendChild(q)};var h=(function(){return{createScrollerImpl:function(l){var m=null;switch(l.separatorType){case a.SEPARATOR.TIME:m=new i(l);break;case a.SEPARATOR.THOUSAND:default:m=new k(l);break}return m}}})();return{DIRECTION:{UP:1,DOWN:2},SEPARATOR:{NONE:0,TIME:2,THOUSAND:3},MODE:{COUNTUP:0,COUNTDOWN:1},getNewInstance:function(l){j++;l=l||{};l.direction=l.direction||a.DIRECTION.UP;l.interval=l.interval||5000;l.width=l.width||400;l.amount=l.amount||250;l.separatorType=l.separatorType||a.SEPARATOR.NONE;l.separator=l.separator||"";l.textAlign=l.textAlign||"center";l.forceFallback=l.forceFallback||false;return h.createScrollerImpl(l)},getScrollerSize:function(){return j}}})();d.Scroller=a})(window);