xscroll-master.min.js 1.8 KB

1
  1. define(function(e,r,t){"use strict";var o=e("./util"),n=e("./base"),i=e("./xscroll"),s=function(e){s.superclass.constructor.call(this,e),this.init(e)};return o.extend(s,n,{init:function(e){var r=this;return r.userConfig=o.mix({selector:".xscroll"},e),r},get:function(e){var r=this;if(e)for(var t=0,o=r.xscrolls.length;t<o;t++)if(r.xscrolls[t].renderTo.id===e)return r.xscrolls[t]},getElPos:function(){for(var e=this,r=[],t=document.querySelectorAll(e.userConfig.selector),o=0;o<t.length;o++){var n=t[o].querySelector(".xs-content");r.push({el:t[o],containerWidth:n.offsetWidth,containerHeight:n.offsetHeight,width:t[o].offsetWidth,height:t[o].offsetHeight})}return r},render:function(){var e=this,r=function(e,r){if(e&&r)for(var t=0,o=r.length;t<o;t++)if(r[t].renderTo===e)return r[t]},t=document.querySelectorAll(e.userConfig.selector),o=e.getElPos();for(var n in e.xscrolls)e.xscrolls[n].destroy();e.xscrolls=[];for(var n=0;n<t.length;n++)e.xscrolls.push(new i({renderTo:t[n],containerWidth:o[n].containerWidth,containerHeight:o[n].containerHeight,width:o[n].width,height:o[n].height}).render());for(var n=0,s=e.xscrolls.length;n<s;n++)for(var l=e.xscrolls[n].renderTo.querySelectorAll(e.userConfig.selector),c=0;c<l.length;c++){var h=r(l[c],e.xscrolls);h&&e.xscrolls[n].controller&&e.xscrolls[n].controller.add(h)}return e._bindEvt(),e},_bindEvt:function(){var e=this;window.addEventListener("resize",function(r){setTimeout(function(){for(var r=e.getElPos(),t=0,o=e.xscrolls.length;t<o;t++){var n=e.xscrolls[t];n.userConfig.containerWidth=r[t].containerWidth,n.userConfig.containerHeight=r[t].containerHeight,n.userConfig.width=r[t].width,n.userConfig.height=r[t].height,n.boundry.refresh({width:n.userConfig.width,height:n.userConfig.height}),n.boundryCheck(0),n.render()}},0)},e)}}),"object"==typeof t&&t.exports?void(t.exports=s):window.XScrollMaster=s});