-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathangular-resizable.min.js
More file actions
1 lines (1 loc) · 2.9 KB
/
angular-resizable.min.js
File metadata and controls
1 lines (1 loc) · 2.9 KB
1
!function(){"use strict";function e(){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:"=",rMinWidth:"=",rMinHeight:"=",rMaxWidth:"=",rMaxHeight:"="},link:function(t,r,n){var i="flexBasis"in document.documentElement.style?"flexBasis":"webkitFlexBasis"in document.documentElement.style?"webkitFlexBasis":"msFlexPreferredSize"in document.documentElement.style?"msFlexPreferredSize":"flexBasis";t.$watch("rWidth",function(e){r[0].style[t.rFlex?i:"width"]=t.rWidth+"px"}),t.$watch("rHeight",function(e){r[0].style[t.rFlex?i:"height"]=t.rHeight+"px"}),r.addClass("resizable");var a,o,s,d,u,l=window.getComputedStyle(r[0],null),c=t.rDirections||["right"],h=t.rCenteredX?2:1,m=t.rCenteredY?2:1,g=t.rGrabber?t.rGrabber:"<span></span>",x={},v=function(e){x.width=!1,x.height=!1,"x"===u?x.width=parseInt(r[0].style[t.rFlex?i:"width"]):x.height=parseInt(r[0].style[t.rFlex?i:"height"]),x.id=r[0].id,x.evt=e},p=function(e){return e.touches?e.touches[0].clientX:e.clientX},f=function(e){return e.touches?e.touches[0].clientY:e.clientY},b=function(n){function l(){t.$emit("angular-resizable.resizing",x)}var c,g,b,y="x"===u?s-p(n):s-f(n);switch(d){case"top":g=o+y*m,c=t.rFlex?i:"height",r[0].style[c]=t.rMaxHeight&&t.rMaxHeight<g?t.rMaxHeight:g+"px";break;case"bottom":g=o-y*m,c=t.rFlex?i:"height",r[0].style[c]=t.rMinHeight&&t.rMinHeight>g?t.rMinHeight:g+"px";break;case"right":b=a-y*h,c=t.rFlex?i:"width",r[0].style[c]=t.rMaxWidth&&t.rMaxWidth<g?t.rMaxWidth:b+"px";break;case"left":b=a+y*h,c=t.rFlex?i:"width",r[0].style[c]=t.rMinWidth&&t.rMinWidth>g?t.rMinWidth:b+"px"}v(n),t.rNoThrottle?l():e(l)},y=function(e){v(),t.$emit("angular-resizable.resizeEnd",x),t.$apply(),document.removeEventListener("mouseup",y,!1),document.removeEventListener("mousemove",b,!1),document.removeEventListener("touchend",y,!1),document.removeEventListener("touchmove",b,!1),r.removeClass("no-transition")},E=function(e,n){d=n,u="left"===d||"right"===d?"x":"y",s="x"===u?p(e):f(e),a=parseInt(l.getPropertyValue("width")),o=parseInt(l.getPropertyValue("height")),r.addClass("no-transition"),document.addEventListener("mouseup",y,!1),document.addEventListener("mousemove",b,!1),document.addEventListener("touchend",y,!1),document.addEventListener("touchmove",b,!1),e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.cancelBubble=!0,e.returnValue=!1,v(e),t.$emit("angular-resizable.resizeStart",x),t.$apply()};c.forEach(function(e){var n=document.createElement("div");n.setAttribute("class","rg-"+e),n.innerHTML=g,r[0].appendChild(n),n.ondragstart=function(){return!1};var i=function(r){var n="true"===t.rDisabled;n||1!==r.which&&!r.touches||E(r,e)};n.addEventListener("mousedown",i,!1),n.addEventListener("touchstart",i,!1)})}}}angular.module("angularResizable",[]).directive("resizable",e)}();