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) · 2.73 KB
/
angular-resizable.min.js
File metadata and controls
1 lines (1 loc) · 2.73 KB
1
angular.module("angularResizable",[]).directive("resizable",["$compile","$rootScope",function(e,t){function r(e){void 0===n?(n=e,setTimeout(function(){n(),n=void 0},100)):n=e}var n;return{restrict:"AE",scope:{rDirections:"=",rCenteredX:"=",rCenteredY:"=",rWidth:"=",rHeight:"=",rFlex:"=",rGrabber:"@",rDisabled:"@",rNoThrottle:"="},link:function(t,n,i){var o="flexBasis"in document.documentElement.style?"flexBasis":"webkitFlexBasis"in document.documentElement.style?"webkitFlexBasis":"msFlexPreferredSize"in document.documentElement.style?"msFlexPreferredSize":"flexBasis";t.$watch("rWidth",function(e){n[0].style[t.rFlex?o:"width"]=t.rWidth+"px"}),t.$watch("rHeight",function(e){n[0].style[t.rFlex?o:"height"]=t.rHeight+"px"}),n.addClass("resizable");var a,s,l,u,d,c=function(r){var n=e(angular.element(r));return n(t.$parent)[0]},h=window.getComputedStyle(n[0],null),m=t.rDirections||["right"],p=t.rCenteredX?2:1,v=t.rCenteredY?2:1,f=c(t.rGrabber?t.rGrabber:"<span></span>"),g={},x=function(e){g.width=!1,g.height=!1,"x"===d?g.width=parseInt(n[0].style[t.rFlex?o:"width"]):g.height=parseInt(n[0].style[t.rFlex?o:"height"]),g.id=n[0].id,g.evt=e},b=function(e){return e.touches?e.touches[0].clientX:e.clientX},y=function(e){return e.touches?e.touches[0].clientY:e.clientY},E=function(e){function i(){t.$emit("angular-resizable.resizing",g)}var c,h="x"===d?l-b(e):l-y(e);switch(u){case"top":c=t.rFlex?o:"height",n[0].style[c]=s+h*v+"px";break;case"bottom":c=t.rFlex?o:"height",n[0].style[c]=s-h*v+"px";break;case"right":c=t.rFlex?o:"width",n[0].style[c]=a-h*p+"px";break;case"left":c=t.rFlex?o:"width",n[0].style[c]=a+h*p+"px"}x(e),t.rNoThrottle?i():r(i)},w=function(e){x(),t.$emit("angular-resizable.resizeEnd",g),t.$apply(),document.removeEventListener("mouseup",w,!1),document.removeEventListener("mousemove",E,!1),document.removeEventListener("touchend",w,!1),document.removeEventListener("touchmove",E,!1),n.removeClass("no-transition")},F=function(e,r){u=r,d="left"===u||"right"===u?"x":"y",l="x"===d?b(e):y(e),a=parseInt(h.getPropertyValue("width")),s=parseInt(h.getPropertyValue("height")),n.addClass("no-transition"),document.addEventListener("mouseup",w,!1),document.addEventListener("mousemove",E,!1),document.addEventListener("touchend",w,!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",g),t.$apply()};m.forEach(function(e){var r=document.createElement("div");r.setAttribute("class","rg-"+e),r.appendChild(f),n[0].appendChild(r),r.ondragstart=function(){return!1};var i=function(r){var n="true"===t.rDisabled;n||1!==r.which&&!r.touches||F(r,e)};r.addEventListener("mousedown",i,!1),r.addEventListener("touchstart",i,!1)})}}}]);