forked from ezekielaquino/Marquee3000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marquee3k-noUMD.min.js
1 lines (1 loc) · 3.39 KB
/
marquee3k-noUMD.min.js
1
'use strict';var _createClass=function(){function a(b,c){for(var e,d=0;d<c.length;d++)e=c[d],e.enumerable=e.enumerable||!1,e.configurable=!0,'value'in e&&(e.writable=!0),Object.defineProperty(b,e.key,e)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();Object.defineProperty(exports,'__esModule',{value:!0});function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var Marquee3k=function(){function a(b,c){_classCallCheck(this,a),this.element=b,this.selector=c.selector,this.speed=b.dataset.speed||0.25,this.pausable=b.dataset.pausable,this.reverse=b.dataset.reverse,this.paused=!1,this.parent=b.parentElement,this.parentProps=this.parent.getBoundingClientRect(),this.content=b.children[0],this.innerContent=this.content.innerHTML,this.wrapStyles='',this.offset=0,this._setupWrapper(),this._setupContent(),this._setupEvents(),this.wrapper.appendChild(this.content),this.element.appendChild(this.wrapper)}return _createClass(a,[{key:'_setupWrapper',value:function _setupWrapper(){this.wrapper=document.createElement('div'),this.wrapper.classList.add('marquee3k__wrapper'),this.wrapper.style.whiteSpace='nowrap'}},{key:'_setupContent',value:function _setupContent(){this.content.classList.add(this.selector+'__copy'),this.content.style.display='inline-block',this.contentWidth=this.content.offsetWidth,this.requiredReps=this.contentWidth>this.parentProps.width?2:Math.ceil((this.parentProps.width-this.contentWidth)/this.contentWidth)+1;for(var b=0;b<this.requiredReps;b++)this._createClone();this.reverse&&(this.offset=-1*this.contentWidth),this.element.classList.add('is-init')}},{key:'_setupEvents',value:function _setupEvents(){var b=this;this.element.addEventListener('mouseenter',function(){b.pausable&&(b.paused=!0)}),this.element.addEventListener('mouseleave',function(){b.pausable&&(b.paused=!1)})}},{key:'_createClone',value:function _createClone(){var b=this.content.cloneNode(!0);b.style.display='inline-block',b.classList.add(this.selector+'__copy'),this.wrapper.appendChild(b)}},{key:'animate',value:function animate(){if(!this.paused){var b=this.reverse?0>this.offset:this.offset>-1*this.contentWidth,c=this.reverse?-1:1,d=this.reverse?-1*this.contentWidth:0;b?this.offset-=this.speed*c:this.offset=d,this.wrapper.style.whiteSpace='nowrap',this.wrapper.style.transform='translate('+this.offset+'px, 0) translateZ(0)'}}},{key:'_refresh',value:function _refresh(){this.contentWidth=this.content.offsetWidth}},{key:'repopulate',value:function repopulate(b,c){if(this.contentWidth=this.content.offsetWidth,c)for(var d=Math.ceil(b/this.contentWidth)+1,e=0;e<d;e++)this._createClone()}}],[{key:'refresh',value:function refresh(b){MARQUEES[b]._refresh()}},{key:'refreshAll',value:function refreshAll(){for(var b=0;b<MARQUEES.length;b++)MARQUEES[b]._refresh()}},{key:'init',value:function init(){var k=this,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{selector:'marquee3k'};function b(){for(var l=0;l<MARQUEES.length;l++)MARQUEES[l].animate();window.requestAnimationFrame(b)}window.MARQUEES=[];for(var d=Array.from(document.querySelectorAll('.'+c.selector)),e=window.innerWidth,g=0;g<d.length;g++){var h=d[g],j=new a(h,c);MARQUEES.push(j)}b(),window.addEventListener('resize',function(){clearTimeout(f),f=setTimeout(function(){for(var l=e<window.innerWidth,m=window.innerWidth-e,n=0;n<MARQUEES.length;n++)MARQUEES[n].repopulate(m,l);e=k.innerWidth})},250)}}]),a}();exports.default=Marquee3k;