split.min.js
5.03 KB
"use strict";(function(){var a=this,b="addEventListener",c="removeEventListener",d="getBoundingClientRect",e=a.attachEvent&&!a[b],f=a.document,g=function(){for(var a,b=["","-webkit-","-moz-","-o-"],c=0;c<b.length;c++)if(a=f.createElement("div"),a.style.cssText="width:"+b[c]+"calc(9px)",a.style.length)return b[c]+"calc"}(),h=function(a){return"string"==typeof a||a instanceof String?f.querySelector(a):a},i=function(i,j){var k,l,m,n,o,p,q,r,s=[];j="undefined"!=typeof j?j:{},j.gutterSize||(j.gutterSize=10),j.minSize||(j.minSize=100),j.snapOffset||(j.snapOffset=30),j.direction||(j.direction="horizontal"),"horizontal"==j.direction?(k="width",m="clientWidth",n="clientX",o="left",p="gutter gutter-horizontal",q="paddingLeft",r="paddingRight",j.cursor||(j.cursor="ew-resize")):"vertical"==j.direction&&(k="height",m="clientHeight",n="clientY",o="top",p="gutter gutter-vertical",q="paddingTop",r="paddingBottom",j.cursor||(j.cursor="ns-resize"));var t=function(c){var d=this,e=d.a,f=d.b;!d.dragging&&j.onDragStart&&j.onDragStart(this),c.preventDefault(),d.dragging=!0,d.move=v.bind(d),d.stop=u.bind(d),a[b]("mouseup",d.stop),a[b]("touchend",d.stop),a[b]("touchcancel",d.stop),d.parent[b]("mousemove",d.move),d.parent[b]("touchmove",d.move),e[b]("selectstart",C),e[b]("dragstart",C),f[b]("selectstart",C),f[b]("dragstart",C),e.style.userSelect="none",e.style.webkitUserSelect="none",e.style.MozUserSelect="none",e.style.pointerEvents="none",f.style.userSelect="none",f.style.webkitUserSelect="none",f.style.MozUserSelect="none",f.style.pointerEvents="none",d.gutter.style.cursor=j.cursor,d.parent.style.cursor=j.cursor,w.call(d)},u=function(){var b=this,d=b.a,e=b.b;b.dragging&&j.onDragEnd&&j.onDragEnd(this),b.dragging=!1,a[c]("mouseup",b.stop),a[c]("touchend",b.stop),a[c]("touchcancel",b.stop),b.parent[c]("mousemove",b.move),b.parent[c]("touchmove",b.move),delete b.stop,delete b.move,d[c]("selectstart",C),d[c]("dragstart",C),e[c]("selectstart",C),e[c]("dragstart",C),d.style.userSelect="",d.style.webkitUserSelect="",d.style.MozUserSelect="",d.style.pointerEvents="",e.style.userSelect="",e.style.webkitUserSelect="",e.style.MozUserSelect="",e.style.pointerEvents="",b.gutter.style.cursor="",b.parent.style.cursor=""},v=function(a){var b;this.dragging&&(b="touches"in a?a.touches[0][n]-this.start:a[n]-this.start,b<=this.aMin+j.snapOffset?b=this.aMin:b>=this.size-this.bMin-j.snapOffset&&(b=this.size-this.bMin),x.call(this,b),j.onDrag&&j.onDrag(this))},w=function(){var b=a.getComputedStyle(this.parent),c=this.parent[m]-parseFloat(b[q])-parseFloat(b[r]);this.size=this.a[d]()[k]+this.b[d]()[k]+this.aGutterSize+this.bGutterSize,this.percentage=Math.min(this.size/c*100,100),this.start=this.a[d]()[o]},x=function(a){2==j.cellCollection.length&&(this.percentage=100);var b=a/this.size*this.percentage,c=this.percentage-a/this.size*this.percentage,d=y.call(this,[b,c],this.percentage);b=d[0],c=d[1],console.log(b),console.log(c);var e=0;if(_.each(j.cellCollection.models,function(a,d){e+=a==jQuery(this.a).data("model")?b:a==jQuery(this.b).data("model")?c:a.get("width")},this),100>e){var f=100-e;b>c?c+=f:c>b&&(b+=f)}this.a.style[k]=g+"("+b+"% - 10px)",this.b.style[k]=g+"("+c+"% - 10px)",jQuery(this.a).data("width",b),jQuery(this.b).data("width",c)},y=function(a,b){var c=b-_.reduce(a,function(a,b){return a+Math.round(b)},0);return _.chain(a).map(function(b,d){return Math.round(b)+(c>d)-(d>=a.length+c)}).value()},z=function(){var a=this,b=a.a,c=a.b;b[d]()[k]<a.aMin?(b.style[k]=a.aMin-a.aGutterSize+"px",c.style[k]=a.size-a.aMin-a.aGutterSize+"px"):c[d]()[k]<a.bMin&&(b.style[k]=a.size-a.bMin-a.bGutterSize+"px",c.style[k]=a.bMin-a.bGutterSize+"px")},A=function(){var a=this,b=a.a,c=a.b;c[d]()[k]<a.bMin?(b.style[k]=a.size-a.bMin-a.bGutterSize+"px",c.style[k]=a.bMin-a.bGutterSize+"px"):b[d]()[k]<a.aMin&&(b.style[k]=a.aMin-a.aGutterSize+"px",c.style[k]=a.size-a.aMin-a.aGutterSize+"px")},B=function(a){for(var b=0;b<a.length;b++)w.call(a[b]),z.call(a[b]);for(b=a.length-1;b>=0;b--)w.call(a[b]),A.call(a[b])},C=function(){return!1},D=h(i[0]).parentNode;if(!j.sizes){var E=100/i.length;for(j.sizes=[],l=0;l<i.length;l++)j.sizes.push(E)}if(!Array.isArray(j.minSize)){var F=[];for(l=0;l<i.length;l++)F.push(j.minSize);j.minSize=F}for(l=0;l<i.length;l++){var J,L,G=h(i[l]),H=1==l,I=l==i.length-1,K=j.gutterSize;if(l>0&&(L={a:h(i[l-1]),b:G,aMin:j.minSize[l-1],bMin:j.minSize[l],dragging:!1,parent:D,isFirst:H,isLast:I,direction:j.direction},L.aGutterSize=j.gutterSize,L.bGutterSize=j.gutterSize,H&&(L.aGutterSize=j.gutterSize/2),I&&(L.bGutterSize=j.gutterSize/2)),e)J="string"==typeof j.sizes[l]||j.sizes[l]instanceof String?j.sizes[l]:j.sizes[l]+"%";else{if(l>0){var M=f.createElement("div");M.className=p,M.style[k]=j.gutterSize+"px",M[b]("mousedown",t.bind(L)),M[b]("touchstart",t.bind(L)),D.insertBefore(M,G),L.gutter=M}0!==l&&l!=i.length-1||(K=j.gutterSize/2),J="string"==typeof j.sizes[l]||j.sizes[l]instanceof String?j.sizes[l]:g+"("+j.sizes[l]+"% - "+K+"px)"}G.style[k]=J,l>0&&s.push(L)}B(s)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.Split=i):a.Split=i}).call(window);