forked from Reklino/angular-resizable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-resizable.min.js
More file actions
1 lines (1 loc) · 3.05 KB
/
angular-resizable.min.js
File metadata and controls
1 lines (1 loc) · 3.05 KB
1
angular.module("angularResizable",[]).directive("resizable",function(){function e(e){void 0===t?(t=e,setTimeout(function(){t(),t=void 0},100)):t=e}var t;return{restrict:"AE",scope:{rDirections:"=",rCenteredX:"=",rCenteredY:"=",rWidth:"=",rHeight:"=",rFlex:"=",rGrabber:"@",rDisabled:"=",rNoThrottle:"=",rParent:"=",rGrid:"=",rLimitResizeTo:"=?"},link:function(t,r,n){var i=r;t.rParent&&(i=r.parent());var a="flexBasis"in document.documentElement.style?"flexBasis":"webkitFlexBasis"in document.documentElement.style?"webkitFlexBasis":"msFlexPreferredSize"in document.documentElement.style?"msFlexPreferredSize":"flexBasis";t.$watch("rWidth",function(e){i[0].style[t.rFlex?a:"width"]=t.rWidth+"px"}),t.$watch("rHeight",function(e){i[0].style[t.rFlex?a:"height"]=t.rHeight+"px"}),i.addClass("resizable");var o,s,u,d,l,c,h,m=(window.getComputedStyle(i[0],null),t.rDirections||["right"]),f=t.rCenteredX?2:1,v=t.rCenteredY?2:1,g=t.rGrabber?t.rGrabber:"<span></span>",p={},x=function(e){p.width=!1,p.height=!1,"x"===h?p.width=parseInt(i[0].style[t.rFlex?a:"width"]):p.height=parseInt(i[0].style[t.rFlex?a:"height"]),p.id=i[0].id,p.evt=e,p.originalWidth=o,p.originalHeight=s},b=function(e){return e.touches?e.touches[0].clientX:e.clientX},w=function(e){return e.touches?e.touches[0].clientY:e.clientY},E=function(r){function n(){t.$emit("angular-resizable.resizing",p)}var m,g,E="x"===h?l-b(r):l-w(r),y=t.rGrid?t.rGrid[0]:1,z=t.rGrid?t.rGrid[1]:1,F=t.rLimitResizeTo;switch(E="x"==h?Math.round(E/y)*y:Math.round(E/z)*z,c){case"top":if(g=d+E*v,angular.isDefined(F)&&g>s+z*F)return;m=t.rFlex?a:"height",i[0].style[m]=d+E*v+"px";break;case"bottom":if(g=d-E*v,angular.isDefined(F)&&g<s-z*F)return;m=t.rFlex?a:"height",i[0].style[m]=d-E*v+"px";break;case"right":if(g=u-E*f,angular.isDefined(F)&&g>o+y*F)return;m=t.rFlex?a:"width",i[0].style[m]=g+"px";break;case"left":if(g=u+E*f,angular.isDefined(F)&&g<o-y*F)return;m=t.rFlex?a:"width",i[0].style[m]=u+E*f+"px"}x(r),t.rNoThrottle?n():e(n)},y=function(e){x(),t.$emit("angular-resizable.resizeEnd",p),t.$apply(),document.removeEventListener("mouseup",y,!1),document.removeEventListener("mousemove",E,!1),document.removeEventListener("touchend",y,!1),document.removeEventListener("touchmove",E,!1),i.removeClass("no-transition")},z=function(e,r){c=r,h="left"===c||"right"===c?"x":"y",l="x"===h?b(e):w(e);var n=i[0].getBoundingClientRect();u=parseInt(n.width),d=parseInt(n.height),o=u,s=d,i.addClass("no-transition"),document.addEventListener("mouseup",y,!1),document.addEventListener("mousemove",E,!1),document.addEventListener("touchend",y,!1),document.addEventListener("touchmove",E,!1),e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.cancelBubble=!0,e.returnValue=!1,x(e),t.$emit("angular-resizable.resizeStart",p),t.$apply()};t.$watch("rDisabled",function(e){m.forEach(function(t){if(!e){var r=document.createElement("div");r.setAttribute("class","rg-"+t),r.innerHTML=g,i[0].appendChild(r),r.ondragstart=function(){return!1};var n=function(e){(1===e.which||e.touches)&&z(e,t)};r.addEventListener("mousedown",n,!1),r.addEventListener("touchstart",n,!1)}})})}}});