From 868db1c2de7d157ddea21d0d49d975d4fe554ef6 Mon Sep 17 00:00:00 2001 From: Tarasov Artyom Date: Wed, 11 Jan 2017 10:47:27 -0500 Subject: [PATCH] #41 Fixed scrolling breakes resizable element (Dirty!) --- dist/angular-dnd.js | 14 +++++++++++--- dist/angular-dnd.min.js | 4 ++-- src/core.js | 10 +++++++++- src/directives/dndResizable.js | 4 ++-- 4 files changed, 24 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/core.js mode change 100644 => 100755 src/directives/dndResizable.js diff --git a/dist/angular-dnd.js b/dist/angular-dnd.js index d097163..d87a7ab 100644 --- a/dist/angular-dnd.js +++ b/dist/angular-dnd.js @@ -602,9 +602,17 @@ extend($.prototype, { var ret, position, parents = this.dndClosest(); var self = this[0]; + var selfIndex = parents.index(self); + if (selfIndex >= 0) { + if ($(self).hasClass("angular-dnd-resizable-handle")) { + selfIndex++; + } + parents.splice(0, selfIndex + 1); + } + var parentExists = false; forEach(parents, function(element) { - if (!parentExists && element !== self) { + if (!parentExists) { position = $(element).dndCss('position'); if (position === 'absolute' || position === 'relative' || position === 'fixed') { @@ -2233,7 +2241,7 @@ module.directive('dndResizable', ['$parse', '$timeout', function($parse, $timeou local.inverseRotateMatrix = local.rotateMatrix.inverse(); local.parentRect = local.$parent.dndClientRect(); - var axis = api.getBorderedAxis(), crect = $el.dndClientRect(), srect = local.rect = $el.dndStyleRect(); + var axis = api.getRelBorderedAxis(), crect = $el.dndClientRect(), srect = local.rect = $el.dndStyleRect(); local.borders = api.getBorders(); local.startAxis = axis; @@ -2260,7 +2268,7 @@ module.directive('dndResizable', ['$parse', '$timeout', function($parse, $timeou if (!local.started) return; - var axis = api.getBorderedAxis(); + var axis = api.getRelBorderedAxis(); var vector = Point(axis).minus(local.startAxis).transform(local.inverseRotateMatrix); var scale = {x:1,y:1}; diff --git a/dist/angular-dnd.min.js b/dist/angular-dnd.min.js index 5e19c4a..9bb1998 100644 --- a/dist/angular-dnd.min.js +++ b/dist/angular-dnd.min.js @@ -1,2 +1,2 @@ -!function(a,b,c,d){"use strict";function e(){}function f(){return!1}function g(){return!0}function h(a,b){return function(){b.apply(a,arguments)}}function i(a){return a*(Math.PI/180)}function j(a){return a*(180/Math.PI)}function k(a,b,c){return bc?c:b}function l(a){var c=a.data("events");return c!==b?c:(c=t.data(a,"events"),c!==b?c:(c=t._data(a,"events"),c!==b?c:(c=t._data(a[0],"events"),c!==b?c:b)))}function m(a,b,c,d){3===arguments.length&&"boolean"!=typeof c&&(d=c,c=!1);var e;return function(){var f=arguments;d=d||this,c&&!e&&a.apply(d,f),clearTimeout(e),e=setTimeout(function(){c||a.apply(d,f),e=null},b)}}function n(a,b,c){var d,e;return function(){d||(e=arguments,c=c||this,a.apply(c,e),d=setTimeout(function(){d=null},b))}}function o(a,b){isNaN(b)&&(b=0);var c=Math.pow(10,b);return Math.round(a*c)/c}var p,q,r,s="0.1.24",t=a.element,u=(t(c),t(d)),v={mode:!1,helpers:{}},w=a.forEach,x=a.extend;!function(){c.console=c.console||{log:e,info:e,warn:e,error:e}}(),function(){var a=navigator.userAgent;/webkit\//i.test(a)?(p="-webkit-transform",q="-webkit-transform-origin",r="webkitMatchesSelector"):/gecko\//i.test(a)?(p="-moz-transform",q="-moz-transform-origin",r="mozMatchesSelector"):/trident\//i.test(a)?(p="-ms-transform",q="ms-transform-origin",r="msMatchesSelector"):/presto\//i.test(a)?(p="-o-transform",q="-o-transform-origin",r="oMatchesSelector"):(p="transform",q="transform-origin",r="matches")}();var y=function(){function a(a,b){"object"==typeof a&&(b=a.y||a.top,a=a.x||a.left),this.x=a||0,this.y=b||0}return a.prototype={equal:function(b){return b instanceof a||(b=new a(b)),this.x===b.x&&this.y===b.y},plus:function(b){return b instanceof a||(b=new a(b)),new a(this.x+b.x,this.y+b.y)},minus:function(b){return b instanceof a||(b=new a(b)),new a(this.x-b.x,this.y-b.y)},scale:function(b){return new a(this.x*b,this.y*b)},magnitude:function(){return this.distance(new a(0,0),this)},distance:function(b){return b instanceof a||(b=new a(b)),Math.sqrt(Math.pow(this.x-b.x,2)+Math.pow(this.y-b.y,2))},angle:function(a,b){var c=Math.atan2(a.y-this.y,a.x-this.x);return b===!0&&(c*=180/Math.PI),c},deltaAngle:function(a,c,d){c=c===b?{x:0,y:0}:c;var e=this.angle(c)-a.angle(c);return e<0&&(e=2*Math.PI+e),d===!0&&(e*=180/Math.PI),e},transform:function(a){return a.transformPoint(this)},deltaTransform:function(a){return a.deltaTransformPoint(this)},rotate:function(a,b){var c=(new z).rotate(a,b);return this.transform(c)},getAsCss:function(){return{top:this.y,left:this.x}}},function(b,c){return new a(b,c)}}(),z=function(){function a(a,c,d,e,f,g){this.a=a!==b?a:1,this.b=c||0,this.c=d||0,this.d=e!==b?e:1,this.tx=f||0,this.ty=g||0}a.prototype={concat:function(b){return new a(this.a*b.a+this.c*b.b,this.b*b.a+this.d*b.b,this.a*b.c+this.c*b.d,this.b*b.c+this.d*b.d,this.a*b.tx+this.c*b.ty+this.tx,this.b*b.tx+this.d*b.ty+this.ty)},inverse:function(){var b=this.a*this.d-this.b*this.c;return new a(this.d/b,-this.b/b,-this.c/b,this.a/b,(this.c*this.ty-this.d*this.tx)/b,(this.b*this.tx-this.a*this.ty)/b)},rotate:function(b,c){var d=new a(Math.cos(b),Math.sin(b),-Math.sin(b),Math.cos(b));return c&&(d=this.translate(c.x,c.y).concat(d).translate(-c.x,-c.y)),this.concat(d)},scale:function(b,c,d){c=c||b;var e=new a(b,0,0,c);return d&&(e=e.translate(d.x,d.y).translate(-d.x,-d.y)),e},translate:function(b,c){var d=new a(1,0,0,1,b,c);return this.concat(d)},transformPoint:function(a){return new y(this.a*a.x+this.c*a.y+this.tx,this.b*a.x+this.d*a.y+this.ty)},deltaTransformPoint:function(a){return new y(this.a*a.x+this.c*a.y,this.b*a.x+this.d*a.y)},toStyle:function(){var a=o(this.a,3),b=o(this.b,3),c=o(this.c,3),d=o(this.d,3),e=o(this.tx,3),f=o(this.ty,3),g="matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")";return"matrix(1, 0, 0, 1, 0, 0)"===g?"none":g}};var c=function(b,c,d,e,f,g){return new a(b,c,d,e,f,g)};return c.IDENTITY=new a,c.HORIZONTAL_FLIP=new a(-1,0,0,1),c.VERTICAL_FLIP=new a(1,0,0,-1),c}(),A=function(){function a(a,b,c,d){this.tl=a,this.tr=b,this.bl=c,this.br=d}a.prototype={applyMatrix:function(c,d){var e,f,g,h,i=new z(1,0,0,1,d.x,d.y),j=new z(1,0,0,1,-d.x,-d.y);return d!==b?(e=this.tl.transform(j).transform(c).transform(i),f=this.tr.transform(j).transform(c).transform(i),g=this.bl.transform(j).transform(c).transform(i),h=this.br.transform(j).transform(c).transform(i)):(e=this.tl.transform(c),f=this.tr.transform(c),g=this.bl.transform(c),h=this.br.transform(c)),new a(e,f,g,h)},width:function(){var a=this.tl.x-this.tr.x,b=this.tl.y-this.tr.y;return Math.sqrt(a*a+b*b)},height:function(){var a=this.tl.x-this.bl.x,b=this.tl.y-this.bl.y;return Math.sqrt(a*a+b*b)},client:function(){var a=Math.min(this.tl.y,this.tr.y,this.bl.y,this.br.y),b=Math.min(this.tl.x,this.tr.x,this.bl.x,this.br.x),c=Math.max(this.tl.y,this.tr.y,this.bl.y,this.br.y)-a,d=Math.max(this.tl.x,this.tr.x,this.bl.x,this.br.x)-b;return{top:o(a,1),left:o(b,1),height:o(c,1),width:o(d,1),bottom:o(a+c,1),right:o(b+d,1)}},getAngle:function(a){var b=this.tl.y-this.tr.y,c=this.tl.x-this.tr.x;return 180*Math.tan(c/b)/Math.PI}};var c=function(b,c,d,e){var f=arguments;return"object"==typeof f[0]&&(c=f[0].top,b=f[0].left,d=f[0].width,e=f[0].height),new a(new y(b,c),new y(b+d,c),new y(b,c+e),new y(b+d,c+e))};return c.fromPoints=function(b,c,d,e){return new a(b,c,d,e)},c}();x(t.prototype,{dndDisableSelection:function(){this.on("dragstart selectstart",f).dndCss({"-moz-user-select":"none","-khtml-user-select":"none","-webkit-user-select":"none","-o-user-select":"none","-ms-user-select":"none","user-select":"none"})},dndEnableSelection:function(){this.off("dragstart selectstart",f).dndCss({"-moz-user-select":"auto","-khtml-user-select":"auto","-webkit-user-select":"auto","-o-user-select":"auto","-ms-user-select":"auto","user-select":"auto"})},dndClientRect:function(){if(this[0]){var a=this[0]===c?{top:0,bottom:0,left:0,right:0,width:0,height:0}:this[0].getBoundingClientRect();return{bottom:a.bottom,height:a.height,left:a.left,right:a.right,top:a.top,width:a.width}}},dndStyleRect:function(){var a=this.dndCss(["width","height","top","left"]),b=parseFloat(a.width),c=parseFloat(a.height),d="auto"===a.top?0:parseFloat(a.top),e="auto"===a.left?0:parseFloat(a.left);return{top:d,right:e+b,bottom:d+c,left:e,width:b,height:c}},dndGetParentScrollArea:function(){var a,b,e,f,g,h,i,j=[],k=this.dndClosest();d.documentElement;return w(k,function(c){i=t(c).dndCss(["padding-top","padding-right","padding-bottom","padding-left"]),a=c.scrollWidth,b=c.clientWidth,e=c.scrollHeight,f=c.clientHeight,h=parseFloat(i["padding-top"])+parseFloat(i["padding-bottom"]),g=parseFloat(i["padding-left"])+parseFloat(i["padding-right"]),a-g===b&&e-h===f||j.push(c)}),j.push(c),t(j)},dndGetFirstNotStaticParent:function(){var a,b,c=this.dndClosest(),e=this[0],f=!1;return w(c,function(c){f||c===e||(b=t(c).dndCss("position"),"absolute"!==b&&"relative"!==b&&"fixed"!==b||(a=c,f=!0))}),a||(a=d.documentElement),t(a)},dndClosest:function(a){a=a||"*";for(var b=this[0],c=[];b;)b[r](a)&&c.push(b),b=b.parentElement;return t(c)},dndGetAngle:function(a){var b=this.dndCss(p);if("none"===b||""===b)return 0;var c=b.split("(")[1].split(")")[0].split(","),d=c[0],e=c[1],f=Math.atan2(e,d);return f=f<0?f+=2*Math.PI:f,a?Math.round(180*f/Math.PI):f},dndCloneByStyles:function(){for(var b=[],d=0,e=this.length;d-1&&this.get().splice(b,1)},has:function(a){return this.get().indexOf(a)>-1},add:function(a){if(!this.has(a)){this.get().push(a);var b=this;t(a).on("$destroy",function(){b.remove(a)})}}},a}(),i=function(){function a(a,b){this.el=a,this.$el=t(a),this.listeners={dragstart:[],drag:[],dragend:[],dragenter:[],dragover:[],dragleave:[],drop:[]},this.regions=new g(b),this.layer=function(){return b},this.setCurrentManipulator(null)}var b=["dragstart","drag","dragend","dragenter","dragover","dragleave","drop"],h=["dragstart","drag","dragend"],i=["dragenter","dragover","dragleave","drop"];h.has=i.has=function(a){return this.indexOf(a)>-1};var j;return j="ontouchstart"in d.documentElement?{start:"touchstart",move:"touchmove",end:"touchend",cancel:"touchcancel"}:"pointerEnabled"in c.navigator?{start:"pointerdown",move:"pointermove",end:"pointerup",cancel:"pointercancel"}:"msPointerEnabled"in c.navigator?{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp",cancel:"MSPointerCancel"}:{start:"touchstart",move:"touchmove",end:"touchend",cancel:"touchcancel"},a.prototype={_isEmptyListeners:function(a){if(a instanceof Array){for(var b=0;b0)return!1;return!0},addListener:function(a,d){return b.indexOf(a)===-1?(console.error("jquery.dnd: invalid event name - ",a),this):(this.listeners[a].push(d),i.has(a)?this.regions.add(this.el):!h.has(a)||this.mouse||this.touch||("onmousedown"in c&&(this.mouse=new e(this)),("ontouchstart"in c||"onmsgesturechange"in c)&&(this.touch=new f(this,j))),this)},removeListener:function(a,b){var c=arguments;if(0===c.length)for(var d in this.listeners)this.listeners[d].length=0;else if(1===c.length)this.listeners[a].length=0;else for(var e=this.listeners[a],f=0;f-1&&c.splice(a,1)},getTarget:function(){return c[0]},isTarget:function(){return this.getTarget()===this},start:function(){this.started=!0,this.targets=[],this.asPoint=!1,this.api=new j(this),this.$scrollareas=this.dnd.$el.dndGetParentScrollArea(),this.$reference=this.dnd.$el.dndGetFirstNotStaticParent(),this.$scrollareas.on("scroll",this.onscroll),this.dnd.trigger("dragstart",this.api)},onscroll:function(){this.clearCache(),this.dnd.trigger("drag",this.api)},getCache:function(a){return this.cache[a]},setCache:function(a,b){return this.cache[a]=b},clearCache:function(){this.cache={}},stop:function(){if(this.$scrollareas.off("scroll",this.onscroll),this.targets.length)for(var a=0,b=this.targets.length;ab.left&&a.xb.top&&a.y=b.left&&a.right<=b.right&&(b.top<=a.bottom&&a.bottom<=b.bottom||b.bottom>=a.top&&a.top>=b.top||a.top<=b.top&&a.bottom>=b.bottom)||a.top>=b.top&&a.bottom<=b.bottom&&(b.left<=a.right&&a.right<=b.right||b.right>=a.left&&a.left>=b.left||a.left<=b.left&&a.right>=b.right)||a.top>=b.top&&a.right<=b.right&&a.bottom<=b.bottom&&a.left>=b.left},progress:function(b){this.event=b,this.started||this.start();var c=this.getCache("regions");c||(c=this.setCache("regions",this.prepareRegions()),v.mode&&this.showRegioins()),this.dnd.trigger("drag",this.api);for(var d=this.asPoint?this._isTriggerByPoint.bind(this,this.getBorderedAxis()):this._isTriggerByRect.bind(this,a.element(this.dnd.el).dndClientRect()),e=[],f=[],g=[],h=0;h').dndCss({position:"absolute"});return b.prototype={init:function(a){return delete this.start,delete this.element,this.api=a,this.ready=!1,"clone"===this.templateUrl?this.createElementByClone():this.createElementByTemplate(),this.wrap().appendTo(t(d.body)),this.scope.$root&&this.scope.$root.$$phase||this.scope.$apply(),a.setReferenceElement(d.body),this.initBorderOffset(),this},createTemplateByUrl:function(b){return b=a.isFunction(b)?b():b,f.get(b,{cache:i}).then(function(a){this.template=a.data,this._offset=y(),this.ready=!0}.bind(this))},createElementByClone:function(){return this.element=this.mainElement.dndCloneByStyles().dndCss("position","static"),this._offset=y(this.mainElement.dndClientRect()).minus(this.api.getBorderedAxis()),this.ready=!0,this},createElementByTemplate:function(){return this.element=g(this.template)(this.scope),this},wrap:function(){return c.html(""),c.append(this.element),this},appendTo:function(a){return a.append(c),this},initBorderOffset:function(){var a=this.api.getBorderedAxis();if("clone"===this.templateUrl){var b=this.mainElement.dndClientRect();this.borderOffset={top:a.y-b.top,left:a.x-b.left,bottom:a.y-b.top-b.height,right:a.x-b.left-b.width}}else{var b=c.dndClientRect();this.borderOffset={top:0,left:0,bottom:-b.height,right:-b.width}}},updatePosition:function(){var a=this.api.getRelBorderedAxis(this.borderOffset).plus(this._offset);c.dndCss(a.getAsCss())},destroy:function(){this.element.remove()}},b}();return{require:["?dndRect","?dndModel","?dndContainment"],scope:!0,link:k}}]),B.directive("dndDroppable",["$parse","$timeout",function(a,c){return{require:"?dndModel",scope:!0,link:function(c,d,e,f){function g(a){var d=a.droplocal={};a.dropmodel=f?f.get():f,d.droppable=l(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),d.droppable=d.droppable===b||d.droppable,d.droppable&&(n(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),c.$root&&c.$root.$$phase||c.$apply())}function h(a){var b=a.droplocal;b.droppable&&(o(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),c.$root&&c.$root.$$phase||c.$apply())}function i(a){var d=a.droplocal;d.droppable&&(p(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),a.dropmodel=b,c.$root&&c.$root.$$phase||c.$apply())}function j(a){var b=a.droplocal;b.droppable&&q(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a})}var k={layer:"common"},l=a(e.dndDroppable),m=x({},k,a(e.dndDroppableOpts)(c)||{}),n=a(e.dndOnDragenter),o=a(e.dndOnDragover),p=a(e.dndOnDragleave),q=a(e.dndOnDrop),r={};m.layer=m.layer||k.layer,r[m.layer+".dragenter"]=g,r[m.layer+".dragover"]=h,r[m.layer+".dragleave"]=i,r[m.layer+".drop"]=j,d.dndBind(r)}}}]),B.directive("dndRotatable",["$parse","$timeout",function(c,e){function f(f,g,h,k){function l(c){var e=c.local={};if(e.rotatable=r(f),e.rotatable=e.rotatable===b||e.rotatable,e.rotatable||c.unTarget(),c.isTarget()){e.started=!0,c.setBounderElement(p?p.get():a.element(d.body));var h=c.getRelBorderedAxis();e.srect=g.dndStyleRect(),e.currAngle=g.dndGetAngle(),e.startPoint=y(h),e.borders=c.getBorders(),e.center=y(e.srect).plus(y(e.srect.width/2,e.srect.height/2)),f.$rotated=!0,t(f),f.$root&&f.$root.$$phase||f.$apply()}}function m(a){var b=a.local;if(b.started){var c=a.getRelBorderedAxis(),d=y(c).deltaAngle(b.startPoint,b.center),e=j(b.currAngle+d);e=Math.round(e/s.step)*s.step;var h=i(e),k=z().rotate(h),l=A(b.center.x-b.srect.width/2,b.center.y-b.srect.height/2,b.srect.width,b.srect.height).applyMatrix(k,b.center).client(),m=a.getReferencePoint();b.borders&&(l.left+m.xb.borders.right+1||l.top+m.y+l.height>b.borders.bottom+1)||(o?o.update("transform",k.toStyle()):g.dndCss("transform",k.toStyle()),u(f),f.$root&&f.$root.$$phase||f.$apply())}}function n(a){var b=a.local;b.started&&(v(f),e(function(){f.$rotated=!1}))}var o=k[0],p=k[1],q={step:5},r=c(h.dndRotatable),s=x({},q,c(h.dndRotatableOpts)(f)||{}),t=c(h.dndOnRotatestart),u=c(h.dndOnRotate),v=c(h.dndOnRotateend),w=g.dndCss("position");"fixed"!=w&&"absolute"!=w&&"relative"!=w&&(w="relative",g.dndCss("position",w));var B=a.element('
');g.append(B),f.$rotated=!1;var C={"$$rotatable.dragstart":l,"$$rotatable.drag":m,"$$rotatable.dragend":n};B.dndBind(C)}return{require:["?dndRect","?dndContainment"],scope:!0,link:f}}]),B.directive("dndResizable",["$parse","$timeout",function(c,e){function f(b){return a.element("
").addClass("angular-dnd-resizable-handle angular-dnd-resizable-handle-"+b)}function g(a,b){return b="object"==typeof b?b:{x:1,y:1},new y(a.left+a.width*b.x/2,a.top+a.height*b.y/2)}function h(h,i,j,l){function m(c){function f(c){var e=c.local={};if(e.resizable=q(h),e.resizable=e.resizable===b||e.resizable,e.resizable||c.unTarget(),c.isTarget()){c.setBounderElement(o?o.get():a.element(d.body)),e.started=!0,e.$parent=i.parent(),e.rads=i.dndGetAngle(),e.rotateMatrix=z.IDENTITY.rotate(e.rads),e.inverseRotateMatrix=e.rotateMatrix.inverse(),e.parentRect=e.$parent.dndClientRect();var f=c.getBorderedAxis(),g=i.dndClientRect(),j=e.rect=i.dndStyleRect();e.borders=c.getBorders(),e.startAxis=f,e.minScaleX=r.minWidth/j.width,e.minScaleY=r.minHeight/j.height,e.maxScaleX=r.maxWidth/j.width,e.maxScaleY=r.maxHeight/j.height,e.deltaX=g.left-j.left+g.width/2-j.width/2,e.deltaY=g.top-j.top+g.height/2-j.height/2,h.$resized=!0,s(h),h.$root&&h.$root.$$phase||h.$apply()}}function j(a){var b=a.local;if(b.started){var d=a.getBorderedAxis(),e=y(d).minus(b.startAxis).transform(b.inverseRotateMatrix),f={x:1,y:1},j=b.rect.width,l=b.rect.height,m=b.rect.top,o=b.rect.left;switch(c){case"n":f.y=(l-e.y)/l;break;case"e":f.x=(j+e.x)/j;break;case"s":f.y=(l+e.y)/l;break;case"w":f.x=(j-e.x)/j;break;case"ne":f.x=(j+e.x)/j,f.y=(l-e.y)/l;break;case"se":f.x=(j+e.x)/j,f.y=(l+e.y)/l;break;case"sw":f.x=(j-e.x)/j,f.y=(l+e.y)/l;break;case"nw":f.x=(j-e.x)/j,f.y=(l-e.y)/l}f.x=k(b.minScaleX,f.x,b.maxScaleX),f.y=k(b.minScaleY,f.y,b.maxScaleY);var p,q=g(b.rect),r=g(b.rect,f);switch(c){case"n":p=y(o,m+l*f.y).rotate(b.rads,r).minus(y(o,m+l).rotate(b.rads,q));break;case"e":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"s":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"w":p=y(o+j*f.x,m).rotate(b.rads,r).minus(y(o+j,m).rotate(b.rads,q));break;case"ne":p=y(o,m+l*f.y).rotate(b.rads,r).minus(y(o,m+l).rotate(b.rads,q));break;case"se":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"sw":p=y(o+j*f.x,m).rotate(b.rads,r).minus(y(o+j,m).rotate(b.rads,q));break;case"nw":p=y(o+j*f.x,m+l*f.y).rotate(b.rads,r).minus(y(o+j,m+l).rotate(b.rads,q))}var s={};s.width=j*f.x,s.height=l*f.y,s.left=o-p.x,s.top=m-p.y;var u=y(s.left+b.deltaX+s.width/2,s.top+b.deltaY+s.height/2),v=A(s.left+b.deltaX,s.top+b.deltaY,s.width,s.height).applyMatrix(b.rotateMatrix,u).client();b.borders&&(v.left+1b.borders.right||v.bottom-1>b.borders.bottom)||(n?n.update(s):i.dndCss(s),t(h),h.$root&&h.$root.$$phase||h.$apply())}}function l(a){var b=a.local;b.started&&(u(h),e(function(){h.$resized=!1}))}return{"$$resizable.dragstart":f,"$$resizable.drag":j,"$$resizable.dragend":l}}var n=l[0],o=l[1],p={handles:"ne, se, sw, nw, n, e, s, w",minWidth:20,minHeight:20,maxWidth:1e4,maxHeight:1e4},q=c(j.dndResizable),r=x({},p,c(j.dndResizableOpts)(h)||{}),s=c(j.dndOnResizestart),t=c(j.dndOnResize),u=c(j.dndOnResizeend),v=i.dndCss("position");"fixed"!==v&&"absolute"!==v&&"relative"!==v&&(v="relative",i.dndCss("position",v));for(var w=r.handles.replace(/\s/g,"").split(","),B=0;B0||(a.$sortable.model={list:i(c)},a.$sortable.insertBefore=!0,d.append(a.placeholder[0]))},d.dndBind(j)}function e(a,b,c){}return e.$inject=["$scope","$element","$attrs"],{scope:!0,link:d,controller:e}}]),B.directive("dndSortable",["$parse","$compile",function(b,c){function d(a,b,c){return Object.getOwnPropertyNames(a).map(function(c){return[c,a[c]].join(b)}).join(c)}function f(a){return"{"+d(a,":",",")+"}"}function g(a){return d(a,'="','" ')+'"'}function h(c,d){var e=c[0].nodeName.toLowerCase(),h=d.ngRepeat||"",i=h.match(j);if(!i)throw"dnd-sortable-item requires ng-repeat as dependence";var k=i[1],l=i[2];k=k.match(/^(?:(\s*[\$\w]+)|\(\s*([\$\w]+)\s*,\s*([\$\w]+)\s*\))$/);var m={item:"item: "+(k[3]||k[1])+", ",list:"list: "+l.replace(/\s\|(.)+$/g,"")+", ",index:"index: $index"},n=a.extend({layer:"'common'",handle:"''"},b(d.dndSortableOpts)()),o={"ng-transclude":"","dnd-draggable":"","dnd-draggable-opts":f({helper:"'clone'",useAsPoint:!0,layer:n.layer,handle:n.handle}), -"dnd-droppable":"","dnd-droppable-opts":f({layer:n.layer}),"dnd-on-dragstart":"$$onDragStart($api, $dropmodel, $dragmodel)","dnd-on-dragend":"$$onDragEnd($api, $dropmodel, $dragmodel)","dnd-on-dragover":"$$onDragOver($api, $dropmodel, $dragmodel)","dnd-on-drag":"$$onDrag($api, $dropmodel, $dragmodel)","dnd-model":"{"+m.item+m.list+m.index+"}"};return"<"+e+" "+g(o)+">"}function i(c,d,f,g){function h(a,b,c){var e=d.dndClientRect();return(l?(b.x-e.left)/e.width:(b.y-e.top)/e.height)>.5}function i(a,b,c,d){d=d||b,d.splice(c,0,b.splice(a,1)[0])}var j=(g[0],d.dndCss(["float","display"])),k=d[0].parentNode,l=/left|right|inline/.test(j.float+j.display),m=b(f.dndModel)||e,n=b(f.dndOnSortstart),o=b(f.dndOnSort),p=b(f.dndOnSortchange),q=b(f.dndOnSortend);b(f.dndOnSortenter),b(f.dndOnSortleave);c.$$onDragStart=function(a){n(c),a.placeholder=d.clone(),d.addClass("ng-hide"),a.placeholder.addClass("angular-dnd-placeholder"),k.insertBefore(a.placeholder[0],d[0]),a.$sortable={},a.clearCache(),c.$root&&c.$root.$$phase||c.$apply()},c.$$onDragOver=function(b,e,f){var g=a.isDefined(b.$sortable);if(g){var i=h(b.getDragTarget(),b.getBorderedAxis());i?k.insertBefore(b.placeholder[0],d[0].nextSibling):k.insertBefore(b.placeholder[0],d[0]);var j=m(c);p===a.noop||b.$sortable.model&&b.$sortable.model.index===j.index||(p(c),c.$root&&c.$root.$$phase||c.$apply()),b.$sortable.model=j,b.$sortable.insertBefore=!i,b.clearCache()}},c.$$onDragEnd=function(a){if(d.removeClass("ng-hide"),a.placeholder.remove(),a.$sortable.model){var b=c.$index,e=a.$sortable.model.index,f=m(c).list,g=a.$sortable.model.list;g===f?e=c.left&&a.right<=c.right&&(c.top<=a.bottom&&a.bottom<=c.bottom||c.bottom>=a.top&&a.top>=c.top||a.top<=c.top&&a.bottom>=c.bottom)||a.top>=c.top&&a.bottom<=c.bottom&&(c.left<=a.right&&a.right<=c.right||c.right>=a.left&&a.left>=c.left||a.left<=c.left&&a.right>=c.right)||a.top>=c.top&&a.right<=c.right&&a.bottom<=c.bottom&&a.left>=c.left}}function d(a){this.$element=a}return c.$inject=["$scope","$attrs","$element"],d.prototype={getClient:function(){return this.$element.dndClientRect()}},{restrict:"A",require:["dndSelectable","^dndLassoArea","?dndRect"],controller:c,scope:!0,link:function(a,b,c,e){function f(){e[1].remove(e[0]),a.$root&&a.$root.$$phase||a.$apply()}a.$dndSelectable=e[0];var g=e[2];e[0].rectCtrl=g?g:new d(b),e[1].add(e[0]),b.on("$destroy",f)}}}]),B.directive("dndRect",["$parse",function(a){function c(c,g,h){function i(a){var c;a="object"==typeof a?a:{};for(var e=0;e-1},c.$inject=["$scope","$attrs","$element"],{restrict:"A",controller:c}}]),B.directive("dndModel",["$parse",function(a){function b(b,c){var d=a(c.dndModel),e=d.assign;this.set=function(a){e(b,a)},this.get=function(){return d(b)}}return b.$inject=["$scope","$attrs"],{restrict:"A",controller:b}}]),B.directive("dndLassoArea",["DndLasso","$parse","$timeout","dndKey",function(a,c,d,e){function f(){var a=[],c={};this.data=function(){return c},this.add=function(b){a.push(b)},this.remove=function(b){for(var c=0;c").dndCss({position:"absolute",left:-99999,top:-99999,opacity:0,"z-index":-9999});return t(d.body).append(h),{restrict:"A",link:function(a,d,e){function h(c){c=c===b?{}:c;var h=d.dndCss(["font-size","font-family","font-weight","text-transform","border-top","border-right","border-bottom","border-left","padding-top","padding-right","padding-bottom","padding-left"]),i=c.text==b?d.text()||d.val():c.text,j=[];c.width===b&&j.push("width"),c.height===b&&j.push("height"),j.length&&(j=d.dndCss(j));for(var l in j){var m=j[l];if("%"==m[m.length-1])return;c[l]=j[l]}var n=f(i,h),o=g(d,0,0);if(!n.width||!n.height)return void d.dndCss("font-size","");o.width=parseFloat(c.width),o.height=parseFloat(c.height);var p=o.height/n.height,q=o.width/n.width,r=a.$eval(e.dndFittextMax),s=a.$eval(e.dndFittextMin);s==b&&(s=0),r==b&&(r=Number.POSITIVE_INFINITY);var t=p.95&&t<=1||t>=1&&t<1.05)){var u=t*parseFloat(h["font-size"]);u=k(s,u,r),d.dndCss("font-size",u+"px")}}a.$watch(e.dndFittext,n(function(a){h(a)}),!0),t(c).on("resize",function(){h()})}}}]),B.directive("dndKeyModel",["$parse","dndKey",function(a,c){return{restrict:"A",link:function(d,e,f){var g=a(f.dndKeyModel),h=g.assign;d.$watch(function(){return c.get()},function(a,c){a!==b&&h(d,a)})}}}]),B.directive("dndContainment",["$parse",function(a){function b(b,c,d){var e=a(c.dndContainment);this.get=function(){var a=e(d);return a?b.dndClosest(a).eq(0):b.parent()}}return b.$inject=["$element","$attrs","$scope"],{restrict:"EAC",controller:b}}]),B.factory("dndKey",["$rootScope",function(a){function b(){}function c(b){var c=b.keyCode;f(b),e.indexOf(c)>-1||(e.push(c),a.$digest())}function d(b){var c=b.keyCode,d=e.indexOf(c);d!==-1&&(e.splice(d,1),a.$digest())}var e=[];b.prototype={get:function(){return e},isset:function(a){var b=e.indexOf(a);return b!==-1}};var f=m(d,1e3);return u.on("keydown",c),u.on("keyup",d),new b}]),B.factory("DndLasso",[function(){function a(a){this.getRect=function(){return this.isActive?a.rect:b},this.getClientRect=function(){return this.isActive?f.dndClientRect():b},this.isActive=function(){return a.active}}function c(b){var c=b.isTarget(),d=new a(this);this.isTarget=function(){return c},this.handler=function(){return d},this.getEvent=function(){return b.getEvent()}}function e(a){function b(b){var d=b.local=new c(b);return d.isTarget()?(d.active=!0,i.trigger("start",d.handler()),b.setReferenceElement(a.$el),b.setBounderElement(a.$el),d.startAxis=b.getRelBorderedAxis(),f.removeAttr("class style").removeClass("ng-hide").addClass(a.className),void a.$el.append(f)):void i.trigger("start",d.handler())}function e(b){var c=b.local;if(!c.active)return void i.trigger("drag",c.handler());var d=b.getRelBorderedAxis().minus(c.startAxis),e={top:c.startAxis.y,left:c.startAxis.x,width:d.x,height:d.y};e.width<0&&(e.width=-e.width,e.left=e.left-e.width),e.height<0&&(e.height=-e.height,e.top=e.top-e.height),c.rect=e,e.top+=a.offsetY,e.left+=a.offsetX,f.dndCss(e),i.trigger("drag",c.handler())}function h(a){var b=a.local;return b.active?(f.addClass("ng-hide"),t(d.body).append(f),void i.trigger("end",b.handler())):void i.trigger("end",b.handler())}var i=this;a=x({},g,a);var j={"$$lasso.dragstart":b,"$$lasso.drag":e,"$$lasso.dragend":h};a.$el.dndBind(j),this.destroy=function(){a.$el.dndUnbind()};var k={};this.on=function(a,b){k[a]=k[a]||[],k[a].push(b)},this.trigger=function(a,b){k[a]=k[a]||[],b=b||"string"==typeof b?[b]:[],k[a].forEach(function(a){a.apply(this,b)})}}var f=t("
").dndCss({position:"absolute"}),g={className:"angular-dnd-lasso",offsetX:0,offsetY:0};return e}]),B.factory("EventEmitter",[function(){function a(){var a={};this.on=function(b,c){a[b]=a[b]||[],a[b].push(c)},this.off=function(b,c){if(a[b])for(var d=0,e=a[b].length;dc?c:b}function l(a){var c=a.data("events");return c!==b?c:(c=t.data(a,"events"),c!==b?c:(c=t._data(a,"events"),c!==b?c:(c=t._data(a[0],"events"),c!==b?c:b)))}function m(a,b,c,d){3===arguments.length&&"boolean"!=typeof c&&(d=c,c=!1);var e;return function(){var f=arguments;d=d||this,c&&!e&&a.apply(d,f),clearTimeout(e),e=setTimeout(function(){c||a.apply(d,f),e=null},b)}}function n(a,b,c){var d,e;return function(){d||(e=arguments,c=c||this,a.apply(c,e),d=setTimeout(function(){d=null},b))}}function o(a,b){isNaN(b)&&(b=0);var c=Math.pow(10,b);return Math.round(a*c)/c}var p,q,r,s="0.1.24",t=a.element,u=(t(c),t(d)),v={mode:!1,helpers:{}},w=a.forEach,x=a.extend;!function(){c.console=c.console||{log:e,info:e,warn:e,error:e}}(),function(){var a=navigator.userAgent;/webkit\//i.test(a)?(p="-webkit-transform",q="-webkit-transform-origin",r="webkitMatchesSelector"):/gecko\//i.test(a)?(p="-moz-transform",q="-moz-transform-origin",r="mozMatchesSelector"):/trident\//i.test(a)?(p="-ms-transform",q="ms-transform-origin",r="msMatchesSelector"):/presto\//i.test(a)?(p="-o-transform",q="-o-transform-origin",r="oMatchesSelector"):(p="transform",q="transform-origin",r="matches")}();var y=function(){function a(a,b){"object"==typeof a&&(b=a.y||a.top,a=a.x||a.left),this.x=a||0,this.y=b||0}return a.prototype={equal:function(b){return b instanceof a||(b=new a(b)),this.x===b.x&&this.y===b.y},plus:function(b){return b instanceof a||(b=new a(b)),new a(this.x+b.x,this.y+b.y)},minus:function(b){return b instanceof a||(b=new a(b)),new a(this.x-b.x,this.y-b.y)},scale:function(b){return new a(this.x*b,this.y*b)},magnitude:function(){return this.distance(new a(0,0),this)},distance:function(b){return b instanceof a||(b=new a(b)),Math.sqrt(Math.pow(this.x-b.x,2)+Math.pow(this.y-b.y,2))},angle:function(a,b){var c=Math.atan2(a.y-this.y,a.x-this.x);return b===!0&&(c*=180/Math.PI),c},deltaAngle:function(a,c,d){c=c===b?{x:0,y:0}:c;var e=this.angle(c)-a.angle(c);return e<0&&(e=2*Math.PI+e),d===!0&&(e*=180/Math.PI),e},transform:function(a){return a.transformPoint(this)},deltaTransform:function(a){return a.deltaTransformPoint(this)},rotate:function(a,b){var c=(new z).rotate(a,b);return this.transform(c)},getAsCss:function(){return{top:this.y,left:this.x}}},function(b,c){return new a(b,c)}}(),z=function(){function a(a,c,d,e,f,g){this.a=a!==b?a:1,this.b=c||0,this.c=d||0,this.d=e!==b?e:1,this.tx=f||0,this.ty=g||0}a.prototype={concat:function(b){return new a(this.a*b.a+this.c*b.b,this.b*b.a+this.d*b.b,this.a*b.c+this.c*b.d,this.b*b.c+this.d*b.d,this.a*b.tx+this.c*b.ty+this.tx,this.b*b.tx+this.d*b.ty+this.ty)},inverse:function(){var b=this.a*this.d-this.b*this.c;return new a(this.d/b,-this.b/b,-this.c/b,this.a/b,(this.c*this.ty-this.d*this.tx)/b,(this.b*this.tx-this.a*this.ty)/b)},rotate:function(b,c){var d=new a(Math.cos(b),Math.sin(b),-Math.sin(b),Math.cos(b));return c&&(d=this.translate(c.x,c.y).concat(d).translate(-c.x,-c.y)),this.concat(d)},scale:function(b,c,d){c=c||b;var e=new a(b,0,0,c);return d&&(e=e.translate(d.x,d.y).translate(-d.x,-d.y)),e},translate:function(b,c){var d=new a(1,0,0,1,b,c);return this.concat(d)},transformPoint:function(a){return new y(this.a*a.x+this.c*a.y+this.tx,this.b*a.x+this.d*a.y+this.ty)},deltaTransformPoint:function(a){return new y(this.a*a.x+this.c*a.y,this.b*a.x+this.d*a.y)},toStyle:function(){var a=o(this.a,3),b=o(this.b,3),c=o(this.c,3),d=o(this.d,3),e=o(this.tx,3),f=o(this.ty,3),g="matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")";return"matrix(1, 0, 0, 1, 0, 0)"===g?"none":g}};var c=function(b,c,d,e,f,g){return new a(b,c,d,e,f,g)};return c.IDENTITY=new a,c.HORIZONTAL_FLIP=new a(-1,0,0,1),c.VERTICAL_FLIP=new a(1,0,0,-1),c}(),A=function(){function a(a,b,c,d){this.tl=a,this.tr=b,this.bl=c,this.br=d}a.prototype={applyMatrix:function(c,d){var e,f,g,h,i=new z(1,0,0,1,d.x,d.y),j=new z(1,0,0,1,-d.x,-d.y);return d!==b?(e=this.tl.transform(j).transform(c).transform(i),f=this.tr.transform(j).transform(c).transform(i),g=this.bl.transform(j).transform(c).transform(i),h=this.br.transform(j).transform(c).transform(i)):(e=this.tl.transform(c),f=this.tr.transform(c),g=this.bl.transform(c),h=this.br.transform(c)),new a(e,f,g,h)},width:function(){var a=this.tl.x-this.tr.x,b=this.tl.y-this.tr.y;return Math.sqrt(a*a+b*b)},height:function(){var a=this.tl.x-this.bl.x,b=this.tl.y-this.bl.y;return Math.sqrt(a*a+b*b)},client:function(){var a=Math.min(this.tl.y,this.tr.y,this.bl.y,this.br.y),b=Math.min(this.tl.x,this.tr.x,this.bl.x,this.br.x),c=Math.max(this.tl.y,this.tr.y,this.bl.y,this.br.y)-a,d=Math.max(this.tl.x,this.tr.x,this.bl.x,this.br.x)-b;return{top:o(a,1),left:o(b,1),height:o(c,1),width:o(d,1),bottom:o(a+c,1),right:o(b+d,1)}},getAngle:function(a){var b=this.tl.y-this.tr.y,c=this.tl.x-this.tr.x;return 180*Math.tan(c/b)/Math.PI}};var c=function(b,c,d,e){var f=arguments;return"object"==typeof f[0]&&(c=f[0].top,b=f[0].left,d=f[0].width,e=f[0].height),new a(new y(b,c),new y(b+d,c),new y(b,c+e),new y(b+d,c+e))};return c.fromPoints=function(b,c,d,e){return new a(b,c,d,e)},c}();x(t.prototype,{dndDisableSelection:function(){this.on("dragstart selectstart",f).dndCss({"-moz-user-select":"none","-khtml-user-select":"none","-webkit-user-select":"none","-o-user-select":"none","-ms-user-select":"none","user-select":"none"})},dndEnableSelection:function(){this.off("dragstart selectstart",f).dndCss({"-moz-user-select":"auto","-khtml-user-select":"auto","-webkit-user-select":"auto","-o-user-select":"auto","-ms-user-select":"auto","user-select":"auto"})},dndClientRect:function(){if(this[0]){var a=this[0]===c?{top:0,bottom:0,left:0,right:0,width:0,height:0}:this[0].getBoundingClientRect();return{bottom:a.bottom,height:a.height,left:a.left,right:a.right,top:a.top,width:a.width}}},dndStyleRect:function(){var a=this.dndCss(["width","height","top","left"]),b=parseFloat(a.width),c=parseFloat(a.height),d="auto"===a.top?0:parseFloat(a.top),e="auto"===a.left?0:parseFloat(a.left);return{top:d,right:e+b,bottom:d+c,left:e,width:b,height:c}},dndGetParentScrollArea:function(){var a,b,e,f,g,h,i,j=[],k=this.dndClosest();d.documentElement;return w(k,function(c){i=t(c).dndCss(["padding-top","padding-right","padding-bottom","padding-left"]),a=c.scrollWidth,b=c.clientWidth,e=c.scrollHeight,f=c.clientHeight,h=parseFloat(i["padding-top"])+parseFloat(i["padding-bottom"]),g=parseFloat(i["padding-left"])+parseFloat(i["padding-right"]),a-g===b&&e-h===f||j.push(c)}),j.push(c),t(j)},dndGetFirstNotStaticParent:function(){var a,b,c=this.dndClosest(),e=this[0],f=c.index(e);f>=0&&(t(e).hasClass("angular-dnd-resizable-handle")&&f++,c.splice(0,f+1));var g=!1;return w(c,function(c){g||(b=t(c).dndCss("position"),"absolute"!==b&&"relative"!==b&&"fixed"!==b||(a=c,g=!0))}),a||(a=d.documentElement),t(a)},dndClosest:function(a){a=a||"*";for(var b=this[0],c=[];b;)b[r](a)&&c.push(b),b=b.parentElement;return t(c)},dndGetAngle:function(a){var b=this.dndCss(p);if("none"===b||""===b)return 0;var c=b.split("(")[1].split(")")[0].split(","),d=c[0],e=c[1],f=Math.atan2(e,d);return f=f<0?f+=2*Math.PI:f,a?Math.round(180*f/Math.PI):f},dndCloneByStyles:function(){for(var b=[],d=0,e=this.length;d-1&&this.get().splice(b,1)},has:function(a){return this.get().indexOf(a)>-1},add:function(a){if(!this.has(a)){this.get().push(a);var b=this;t(a).on("$destroy",function(){b.remove(a)})}}},a}(),i=function(){function a(a,b){this.el=a,this.$el=t(a),this.listeners={dragstart:[],drag:[],dragend:[],dragenter:[],dragover:[],dragleave:[],drop:[]},this.regions=new g(b),this.layer=function(){return b},this.setCurrentManipulator(null)}var b=["dragstart","drag","dragend","dragenter","dragover","dragleave","drop"],h=["dragstart","drag","dragend"],i=["dragenter","dragover","dragleave","drop"];h.has=i.has=function(a){return this.indexOf(a)>-1};var j;return j="ontouchstart"in d.documentElement?{start:"touchstart",move:"touchmove",end:"touchend",cancel:"touchcancel"}:"pointerEnabled"in c.navigator?{start:"pointerdown",move:"pointermove",end:"pointerup",cancel:"pointercancel"}:"msPointerEnabled"in c.navigator?{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp",cancel:"MSPointerCancel"}:{start:"touchstart",move:"touchmove",end:"touchend",cancel:"touchcancel"},a.prototype={_isEmptyListeners:function(a){if(a instanceof Array){for(var b=0;b0)return!1;return!0},addListener:function(a,d){return b.indexOf(a)===-1?(console.error("jquery.dnd: invalid event name - ",a),this):(this.listeners[a].push(d),i.has(a)?this.regions.add(this.el):!h.has(a)||this.mouse||this.touch||("onmousedown"in c&&(this.mouse=new e(this)),("ontouchstart"in c||"onmsgesturechange"in c)&&(this.touch=new f(this,j))),this)},removeListener:function(a,b){var c=arguments;if(0===c.length)for(var d in this.listeners)this.listeners[d].length=0;else if(1===c.length)this.listeners[a].length=0;else for(var e=this.listeners[a],f=0;f-1&&c.splice(a,1)},getTarget:function(){return c[0]},isTarget:function(){return this.getTarget()===this},start:function(){this.started=!0,this.targets=[],this.asPoint=!1,this.api=new j(this),this.$scrollareas=this.dnd.$el.dndGetParentScrollArea(),this.$reference=this.dnd.$el.dndGetFirstNotStaticParent(),this.$scrollareas.on("scroll",this.onscroll),this.dnd.trigger("dragstart",this.api)},onscroll:function(){this.clearCache(),this.dnd.trigger("drag",this.api)},getCache:function(a){return this.cache[a]},setCache:function(a,b){return this.cache[a]=b},clearCache:function(){this.cache={}},stop:function(){if(this.$scrollareas.off("scroll",this.onscroll),this.targets.length)for(var a=0,b=this.targets.length;ab.left&&a.xb.top&&a.y=b.left&&a.right<=b.right&&(b.top<=a.bottom&&a.bottom<=b.bottom||b.bottom>=a.top&&a.top>=b.top||a.top<=b.top&&a.bottom>=b.bottom)||a.top>=b.top&&a.bottom<=b.bottom&&(b.left<=a.right&&a.right<=b.right||b.right>=a.left&&a.left>=b.left||a.left<=b.left&&a.right>=b.right)||a.top>=b.top&&a.right<=b.right&&a.bottom<=b.bottom&&a.left>=b.left},progress:function(b){this.event=b,this.started||this.start();var c=this.getCache("regions");c||(c=this.setCache("regions",this.prepareRegions()),v.mode&&this.showRegioins()),this.dnd.trigger("drag",this.api);for(var d=this.asPoint?this._isTriggerByPoint.bind(this,this.getBorderedAxis()):this._isTriggerByRect.bind(this,a.element(this.dnd.el).dndClientRect()),e=[],f=[],g=[],h=0;h').dndCss({position:"absolute"});return b.prototype={init:function(a){return delete this.start,delete this.element,this.api=a,this.ready=!1,"clone"===this.templateUrl?this.createElementByClone():this.createElementByTemplate(),this.wrap().appendTo(t(d.body)),this.scope.$root&&this.scope.$root.$$phase||this.scope.$apply(),a.setReferenceElement(d.body),this.initBorderOffset(),this},createTemplateByUrl:function(b){return b=a.isFunction(b)?b():b,f.get(b,{cache:i}).then(function(a){this.template=a.data,this._offset=y(),this.ready=!0}.bind(this))},createElementByClone:function(){return this.element=this.mainElement.dndCloneByStyles().dndCss("position","static"),this._offset=y(this.mainElement.dndClientRect()).minus(this.api.getBorderedAxis()),this.ready=!0,this},createElementByTemplate:function(){return this.element=g(this.template)(this.scope),this},wrap:function(){return c.html(""),c.append(this.element),this},appendTo:function(a){return a.append(c),this},initBorderOffset:function(){var a=this.api.getBorderedAxis();if("clone"===this.templateUrl){var b=this.mainElement.dndClientRect();this.borderOffset={top:a.y-b.top,left:a.x-b.left,bottom:a.y-b.top-b.height,right:a.x-b.left-b.width}}else{var b=c.dndClientRect();this.borderOffset={top:0,left:0,bottom:-b.height,right:-b.width}}},updatePosition:function(){var a=this.api.getRelBorderedAxis(this.borderOffset).plus(this._offset);c.dndCss(a.getAsCss())},destroy:function(){this.element.remove()}},b}();return{require:["?dndRect","?dndModel","?dndContainment"],scope:!0,link:k}}]),B.directive("dndDroppable",["$parse","$timeout",function(a,c){return{require:"?dndModel",scope:!0,link:function(c,d,e,f){function g(a){var d=a.droplocal={};a.dropmodel=f?f.get():f,d.droppable=l(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),d.droppable=d.droppable===b||d.droppable,d.droppable&&(n(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),c.$root&&c.$root.$$phase||c.$apply())}function h(a){var b=a.droplocal;b.droppable&&(o(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),c.$root&&c.$root.$$phase||c.$apply())}function i(a){var d=a.droplocal;d.droppable&&(p(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a}),a.dropmodel=b,c.$root&&c.$root.$$phase||c.$apply())}function j(a){var b=a.droplocal;b.droppable&&q(c,{$dragmodel:a.dragmodel,$dropmodel:a.dropmodel,$api:a})}var k={layer:"common"},l=a(e.dndDroppable),m=x({},k,a(e.dndDroppableOpts)(c)||{}),n=a(e.dndOnDragenter),o=a(e.dndOnDragover),p=a(e.dndOnDragleave),q=a(e.dndOnDrop),r={};m.layer=m.layer||k.layer,r[m.layer+".dragenter"]=g,r[m.layer+".dragover"]=h,r[m.layer+".dragleave"]=i,r[m.layer+".drop"]=j,d.dndBind(r)}}}]),B.directive("dndRotatable",["$parse","$timeout",function(c,e){function f(f,g,h,k){function l(c){var e=c.local={};if(e.rotatable=r(f),e.rotatable=e.rotatable===b||e.rotatable,e.rotatable||c.unTarget(),c.isTarget()){e.started=!0,c.setBounderElement(p?p.get():a.element(d.body));var h=c.getRelBorderedAxis();e.srect=g.dndStyleRect(),e.currAngle=g.dndGetAngle(),e.startPoint=y(h),e.borders=c.getBorders(),e.center=y(e.srect).plus(y(e.srect.width/2,e.srect.height/2)),f.$rotated=!0,t(f),f.$root&&f.$root.$$phase||f.$apply()}}function m(a){var b=a.local;if(b.started){var c=a.getRelBorderedAxis(),d=y(c).deltaAngle(b.startPoint,b.center),e=j(b.currAngle+d);e=Math.round(e/s.step)*s.step;var h=i(e),k=z().rotate(h),l=A(b.center.x-b.srect.width/2,b.center.y-b.srect.height/2,b.srect.width,b.srect.height).applyMatrix(k,b.center).client(),m=a.getReferencePoint();b.borders&&(l.left+m.xb.borders.right+1||l.top+m.y+l.height>b.borders.bottom+1)||(o?o.update("transform",k.toStyle()):g.dndCss("transform",k.toStyle()),u(f),f.$root&&f.$root.$$phase||f.$apply())}}function n(a){var b=a.local;b.started&&(v(f),e(function(){f.$rotated=!1}))}var o=k[0],p=k[1],q={step:5},r=c(h.dndRotatable),s=x({},q,c(h.dndRotatableOpts)(f)||{}),t=c(h.dndOnRotatestart),u=c(h.dndOnRotate),v=c(h.dndOnRotateend),w=g.dndCss("position");"fixed"!=w&&"absolute"!=w&&"relative"!=w&&(w="relative",g.dndCss("position",w));var B=a.element('
');g.append(B),f.$rotated=!1;var C={"$$rotatable.dragstart":l,"$$rotatable.drag":m,"$$rotatable.dragend":n};B.dndBind(C)}return{require:["?dndRect","?dndContainment"],scope:!0,link:f}}]),B.directive("dndResizable",["$parse","$timeout",function(c,e){function f(b){return a.element("
").addClass("angular-dnd-resizable-handle angular-dnd-resizable-handle-"+b)}function g(a,b){return b="object"==typeof b?b:{x:1,y:1},new y(a.left+a.width*b.x/2,a.top+a.height*b.y/2)}function h(h,i,j,l){function m(c){function f(c){var e=c.local={};if(e.resizable=q(h),e.resizable=e.resizable===b||e.resizable,e.resizable||c.unTarget(),c.isTarget()){c.setBounderElement(o?o.get():a.element(d.body)),e.started=!0,e.$parent=i.parent(),e.rads=i.dndGetAngle(),e.rotateMatrix=z.IDENTITY.rotate(e.rads),e.inverseRotateMatrix=e.rotateMatrix.inverse(),e.parentRect=e.$parent.dndClientRect();var f=c.getRelBorderedAxis(),g=i.dndClientRect(),j=e.rect=i.dndStyleRect();e.borders=c.getBorders(),e.startAxis=f,e.minScaleX=r.minWidth/j.width,e.minScaleY=r.minHeight/j.height,e.maxScaleX=r.maxWidth/j.width,e.maxScaleY=r.maxHeight/j.height,e.deltaX=g.left-j.left+g.width/2-j.width/2,e.deltaY=g.top-j.top+g.height/2-j.height/2,h.$resized=!0,s(h),h.$root&&h.$root.$$phase||h.$apply()}}function j(a){var b=a.local;if(b.started){var d=a.getRelBorderedAxis(),e=y(d).minus(b.startAxis).transform(b.inverseRotateMatrix),f={x:1,y:1},j=b.rect.width,l=b.rect.height,m=b.rect.top,o=b.rect.left;switch(c){case"n":f.y=(l-e.y)/l;break;case"e":f.x=(j+e.x)/j;break;case"s":f.y=(l+e.y)/l;break;case"w":f.x=(j-e.x)/j;break;case"ne":f.x=(j+e.x)/j,f.y=(l-e.y)/l;break;case"se":f.x=(j+e.x)/j,f.y=(l+e.y)/l;break;case"sw":f.x=(j-e.x)/j,f.y=(l+e.y)/l;break;case"nw":f.x=(j-e.x)/j,f.y=(l-e.y)/l}f.x=k(b.minScaleX,f.x,b.maxScaleX),f.y=k(b.minScaleY,f.y,b.maxScaleY);var p,q=g(b.rect),r=g(b.rect,f);switch(c){case"n":p=y(o,m+l*f.y).rotate(b.rads,r).minus(y(o,m+l).rotate(b.rads,q));break;case"e":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"s":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"w":p=y(o+j*f.x,m).rotate(b.rads,r).minus(y(o+j,m).rotate(b.rads,q));break;case"ne":p=y(o,m+l*f.y).rotate(b.rads,r).minus(y(o,m+l).rotate(b.rads,q));break;case"se":p=y(o,m).rotate(b.rads,r).minus(y(o,m).rotate(b.rads,q));break;case"sw":p=y(o+j*f.x,m).rotate(b.rads,r).minus(y(o+j,m).rotate(b.rads,q));break;case"nw":p=y(o+j*f.x,m+l*f.y).rotate(b.rads,r).minus(y(o+j,m+l).rotate(b.rads,q))}var s={};s.width=j*f.x,s.height=l*f.y,s.left=o-p.x,s.top=m-p.y;var u=y(s.left+b.deltaX+s.width/2,s.top+b.deltaY+s.height/2),v=A(s.left+b.deltaX,s.top+b.deltaY,s.width,s.height).applyMatrix(b.rotateMatrix,u).client();b.borders&&(v.left+1b.borders.right||v.bottom-1>b.borders.bottom)||(n?n.update(s):i.dndCss(s),t(h),h.$root&&h.$root.$$phase||h.$apply())}}function l(a){var b=a.local;b.started&&(u(h),e(function(){h.$resized=!1}))}return{"$$resizable.dragstart":f,"$$resizable.drag":j,"$$resizable.dragend":l}}var n=l[0],o=l[1],p={handles:"ne, se, sw, nw, n, e, s, w",minWidth:20,minHeight:20,maxWidth:1e4,maxHeight:1e4},q=c(j.dndResizable),r=x({},p,c(j.dndResizableOpts)(h)||{}),s=c(j.dndOnResizestart),t=c(j.dndOnResize),u=c(j.dndOnResizeend),v=i.dndCss("position");"fixed"!==v&&"absolute"!==v&&"relative"!==v&&(v="relative",i.dndCss("position",v));for(var w=r.handles.replace(/\s/g,"").split(","),B=0;B0||(a.$sortable.model={list:i(c)},a.$sortable.insertBefore=!0,d.append(a.placeholder[0]))},d.dndBind(j)}function e(a,b,c){}return e.$inject=["$scope","$element","$attrs"],{scope:!0,link:d,controller:e}}]),B.directive("dndSortable",["$parse","$compile",function(b,c){function d(a,b,c){return Object.getOwnPropertyNames(a).map(function(c){return[c,a[c]].join(b)}).join(c)}function f(a){return"{"+d(a,":",",")+"}"}function g(a){return d(a,'="','" ')+'"'}function h(c,d){var e=c[0].nodeName.toLowerCase(),h=d.ngRepeat||"",i=h.match(j);if(!i)throw"dnd-sortable-item requires ng-repeat as dependence";var k=i[1],l=i[2];k=k.match(/^(?:(\s*[\$\w]+)|\(\s*([\$\w]+)\s*,\s*([\$\w]+)\s*\))$/);var m={item:"item: "+(k[3]||k[1])+", ",list:"list: "+l.replace(/\s\|(.)+$/g,"")+", ",index:"index: $index"},n=a.extend({layer:"'common'",handle:"''"},b(d.dndSortableOpts)()),o={"ng-transclude":"","dnd-draggable":"", +"dnd-draggable-opts":f({helper:"'clone'",useAsPoint:!0,layer:n.layer,handle:n.handle}),"dnd-droppable":"","dnd-droppable-opts":f({layer:n.layer}),"dnd-on-dragstart":"$$onDragStart($api, $dropmodel, $dragmodel)","dnd-on-dragend":"$$onDragEnd($api, $dropmodel, $dragmodel)","dnd-on-dragover":"$$onDragOver($api, $dropmodel, $dragmodel)","dnd-on-drag":"$$onDrag($api, $dropmodel, $dragmodel)","dnd-model":"{"+m.item+m.list+m.index+"}"};return"<"+e+" "+g(o)+">"}function i(c,d,f,g){function h(a,b,c){var e=d.dndClientRect();return(l?(b.x-e.left)/e.width:(b.y-e.top)/e.height)>.5}function i(a,b,c,d){d=d||b,d.splice(c,0,b.splice(a,1)[0])}var j=(g[0],d.dndCss(["float","display"])),k=d[0].parentNode,l=/left|right|inline/.test(j.float+j.display),m=b(f.dndModel)||e,n=b(f.dndOnSortstart),o=b(f.dndOnSort),p=b(f.dndOnSortchange),q=b(f.dndOnSortend);b(f.dndOnSortenter),b(f.dndOnSortleave);c.$$onDragStart=function(a){n(c),a.placeholder=d.clone(),d.addClass("ng-hide"),a.placeholder.addClass("angular-dnd-placeholder"),k.insertBefore(a.placeholder[0],d[0]),a.$sortable={},a.clearCache(),c.$root&&c.$root.$$phase||c.$apply()},c.$$onDragOver=function(b,e,f){var g=a.isDefined(b.$sortable);if(g){var i=h(b.getDragTarget(),b.getBorderedAxis());i?k.insertBefore(b.placeholder[0],d[0].nextSibling):k.insertBefore(b.placeholder[0],d[0]);var j=m(c);p===a.noop||b.$sortable.model&&b.$sortable.model.index===j.index||(p(c),c.$root&&c.$root.$$phase||c.$apply()),b.$sortable.model=j,b.$sortable.insertBefore=!i,b.clearCache()}},c.$$onDragEnd=function(a){if(d.removeClass("ng-hide"),a.placeholder.remove(),a.$sortable.model){var b=c.$index,e=a.$sortable.model.index,f=m(c).list,g=a.$sortable.model.list;g===f?e=c.left&&a.right<=c.right&&(c.top<=a.bottom&&a.bottom<=c.bottom||c.bottom>=a.top&&a.top>=c.top||a.top<=c.top&&a.bottom>=c.bottom)||a.top>=c.top&&a.bottom<=c.bottom&&(c.left<=a.right&&a.right<=c.right||c.right>=a.left&&a.left>=c.left||a.left<=c.left&&a.right>=c.right)||a.top>=c.top&&a.right<=c.right&&a.bottom<=c.bottom&&a.left>=c.left}}function d(a){this.$element=a}return c.$inject=["$scope","$attrs","$element"],d.prototype={getClient:function(){return this.$element.dndClientRect()}},{restrict:"A",require:["dndSelectable","^dndLassoArea","?dndRect"],controller:c,scope:!0,link:function(a,b,c,e){function f(){e[1].remove(e[0]),a.$root&&a.$root.$$phase||a.$apply()}a.$dndSelectable=e[0];var g=e[2];e[0].rectCtrl=g?g:new d(b),e[1].add(e[0]),b.on("$destroy",f)}}}]),B.directive("dndRect",["$parse",function(a){function c(c,g,h){function i(a){var c;a="object"==typeof a?a:{};for(var e=0;e-1},c.$inject=["$scope","$attrs","$element"],{restrict:"A",controller:c}}]),B.directive("dndModel",["$parse",function(a){function b(b,c){var d=a(c.dndModel),e=d.assign;this.set=function(a){e(b,a)},this.get=function(){return d(b)}}return b.$inject=["$scope","$attrs"],{restrict:"A",controller:b}}]),B.directive("dndLassoArea",["DndLasso","$parse","$timeout","dndKey",function(a,c,d,e){function f(){var a=[],c={};this.data=function(){return c},this.add=function(b){a.push(b)},this.remove=function(b){for(var c=0;c").dndCss({position:"absolute",left:-99999,top:-99999,opacity:0,"z-index":-9999});return t(d.body).append(h),{restrict:"A",link:function(a,d,e){function h(c){c=c===b?{}:c;var h=d.dndCss(["font-size","font-family","font-weight","text-transform","border-top","border-right","border-bottom","border-left","padding-top","padding-right","padding-bottom","padding-left"]),i=c.text==b?d.text()||d.val():c.text,j=[];c.width===b&&j.push("width"),c.height===b&&j.push("height"),j.length&&(j=d.dndCss(j));for(var l in j){var m=j[l];if("%"==m[m.length-1])return;c[l]=j[l]}var n=f(i,h),o=g(d,0,0);if(!n.width||!n.height)return void d.dndCss("font-size","");o.width=parseFloat(c.width),o.height=parseFloat(c.height);var p=o.height/n.height,q=o.width/n.width,r=a.$eval(e.dndFittextMax),s=a.$eval(e.dndFittextMin);s==b&&(s=0),r==b&&(r=Number.POSITIVE_INFINITY);var t=p.95&&t<=1||t>=1&&t<1.05)){var u=t*parseFloat(h["font-size"]);u=k(s,u,r),d.dndCss("font-size",u+"px")}}a.$watch(e.dndFittext,n(function(a){h(a)}),!0),t(c).on("resize",function(){h()})}}}]),B.directive("dndKeyModel",["$parse","dndKey",function(a,c){return{restrict:"A",link:function(d,e,f){var g=a(f.dndKeyModel),h=g.assign;d.$watch(function(){return c.get()},function(a,c){a!==b&&h(d,a)})}}}]),B.directive("dndContainment",["$parse",function(a){function b(b,c,d){var e=a(c.dndContainment);this.get=function(){var a=e(d);return a?b.dndClosest(a).eq(0):b.parent()}}return b.$inject=["$element","$attrs","$scope"],{restrict:"EAC",controller:b}}]),B.factory("dndKey",["$rootScope",function(a){function b(){}function c(b){var c=b.keyCode;f(b),e.indexOf(c)>-1||(e.push(c),a.$digest())}function d(b){var c=b.keyCode,d=e.indexOf(c);d!==-1&&(e.splice(d,1),a.$digest())}var e=[];b.prototype={get:function(){return e},isset:function(a){var b=e.indexOf(a);return b!==-1}};var f=m(d,1e3);return u.on("keydown",c),u.on("keyup",d),new b}]),B.factory("DndLasso",[function(){function a(a){this.getRect=function(){return this.isActive?a.rect:b},this.getClientRect=function(){return this.isActive?f.dndClientRect():b},this.isActive=function(){return a.active}}function c(b){var c=b.isTarget(),d=new a(this);this.isTarget=function(){return c},this.handler=function(){return d},this.getEvent=function(){return b.getEvent()}}function e(a){function b(b){var d=b.local=new c(b);return d.isTarget()?(d.active=!0,i.trigger("start",d.handler()),b.setReferenceElement(a.$el),b.setBounderElement(a.$el),d.startAxis=b.getRelBorderedAxis(),f.removeAttr("class style").removeClass("ng-hide").addClass(a.className),void a.$el.append(f)):void i.trigger("start",d.handler())}function e(b){var c=b.local;if(!c.active)return void i.trigger("drag",c.handler());var d=b.getRelBorderedAxis().minus(c.startAxis),e={top:c.startAxis.y,left:c.startAxis.x,width:d.x,height:d.y};e.width<0&&(e.width=-e.width,e.left=e.left-e.width),e.height<0&&(e.height=-e.height,e.top=e.top-e.height),c.rect=e,e.top+=a.offsetY,e.left+=a.offsetX,f.dndCss(e),i.trigger("drag",c.handler())}function h(a){var b=a.local;return b.active?(f.addClass("ng-hide"),t(d.body).append(f),void i.trigger("end",b.handler())):void i.trigger("end",b.handler())}var i=this;a=x({},g,a);var j={"$$lasso.dragstart":b,"$$lasso.drag":e,"$$lasso.dragend":h};a.$el.dndBind(j),this.destroy=function(){a.$el.dndUnbind()};var k={};this.on=function(a,b){k[a]=k[a]||[],k[a].push(b)},this.trigger=function(a,b){k[a]=k[a]||[],b=b||"string"==typeof b?[b]:[],k[a].forEach(function(a){a.apply(this,b)})}}var f=t("
").dndCss({position:"absolute"}),g={className:"angular-dnd-lasso",offsetX:0,offsetY:0};return e}]),B.factory("EventEmitter",[function(){function a(){var a={};this.on=function(b,c){a[b]=a[b]||[],a[b].push(c)},this.off=function(b,c){if(a[b])for(var d=0,e=a[b].length;d= 0) { + if ($(self).hasClass("angular-dnd-resizable-handle")) { + selfIndex++; + } + parents.splice(0, selfIndex + 1); + } + var parentExists = false; forEach(parents, function(element) { - if (!parentExists && element !== self) { + if (!parentExists) { position = $(element).dndCss('position'); if (position === 'absolute' || position === 'relative' || position === 'fixed') { diff --git a/src/directives/dndResizable.js b/src/directives/dndResizable.js old mode 100644 new mode 100755 index 7b6822e..805a43b --- a/src/directives/dndResizable.js +++ b/src/directives/dndResizable.js @@ -52,7 +52,7 @@ module.directive('dndResizable', ['$parse', '$timeout', function($parse, $timeou local.inverseRotateMatrix = local.rotateMatrix.inverse(); local.parentRect = local.$parent.dndClientRect(); - var axis = api.getBorderedAxis(), crect = $el.dndClientRect(), srect = local.rect = $el.dndStyleRect(); + var axis = api.getRelBorderedAxis(), crect = $el.dndClientRect(), srect = local.rect = $el.dndStyleRect(); local.borders = api.getBorders(); local.startAxis = axis; @@ -79,7 +79,7 @@ module.directive('dndResizable', ['$parse', '$timeout', function($parse, $timeou if (!local.started) return; - var axis = api.getBorderedAxis(); + var axis = api.getRelBorderedAxis(); var vector = Point(axis).minus(local.startAxis).transform(local.inverseRotateMatrix); var scale = {x:1,y:1};