diff --git a/.gitignore b/.gitignore index 8cec646..776a80a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ ehthumbs.db Thumbs.db -node_modules \ No newline at end of file +node_modules +.idea \ No newline at end of file diff --git a/angular-resizable.min.js b/angular-resizable.min.js index eb0f450..03649dc 100644 --- a/angular-resizable.min.js +++ b/angular-resizable.min.js @@ -1 +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:"@"},link:function(t,n,r){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){n[0].style[t.rFlex?i:"width"]=t.rWidth+"px"}),t.$watch("rHeight",function(e){n[0].style[t.rFlex?i:"height"]=t.rHeight+"px"}),n.addClass("resizable");var s,o,a,u,l,d=window.getComputedStyle(n[0],null),c=t.rDirections,h=t.rCenteredX?2:1,m=t.rCenteredY?2:1,v=t.rGrabber?t.rGrabber:"",p={},f=function(e){p.width=!1,p.height=!1,"x"===l?p.width=parseInt(n[0].style[t.rFlex?i:"width"]):p.height=parseInt(n[0].style[t.rFlex?i:"height"]),p.id=n[0].id,p.evt=e},x=function(e){return e.touches?e.touches[0].clientX:e.clientX},g=function(e){return e.touches?e.touches[0].clientY:e.clientY},b=function(r){var d,c="x"===l?a-x(r):a-g(r);switch(u){case"top":d=t.rFlex?i:"height",n[0].style[d]=o+c*m+"px";break;case"bottom":d=t.rFlex?i:"height",n[0].style[d]=o-c*m+"px";break;case"right":d=t.rFlex?i:"width",n[0].style[d]=s-c*h+"px";break;case"left":d=t.rFlex?i:"width",n[0].style[d]=s+c*h+"px"}f(r),e(function(){t.$emit("angular-resizable.resizing",p)})},y=function(e){f(),t.$emit("angular-resizable.resizeEnd",p),t.$apply(),document.removeEventListener("mouseup",y,!1),document.removeEventListener("mousemove",b,!1),document.removeEventListener("touchend",y,!1),document.removeEventListener("touchmove",b,!1),n.removeClass("no-transition")},E=function(e,r){u=r,l="left"===u||"right"===u?"x":"y",a="x"===l?x(e):g(e),s=parseInt(d.getPropertyValue("width")),o=parseInt(d.getPropertyValue("height")),n.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,f(e),t.$emit("angular-resizable.resizeStart",p),t.$apply()};c.forEach(function(e){var r=document.createElement("div");r.setAttribute("class","rg-"+e),r.innerHTML=v,n[0].appendChild(r),r.ondragstart=function(){return!1};var i=function(n){var r="true"===t.rDisabled;r||1!==n.which&&!n.touches||E(n,e)};r.addEventListener("mousedown",i,!1),r.addEventListener("touchstart",i,!1)})}}}); \ No newline at end of file +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:"=",resizable:"@",rOnResizeStart:"&",rOnResizing:"&",rOnResizeEnd:"&"},link:function(t,r,n){if("false"!==t.resizable){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 s,o,a,l,u,d=window.getComputedStyle(r[0],null),c=t.rDirections||["right"],h=t.rCenteredX?2:1,m=t.rCenteredY?2:1,f=t.rGrabber?t.rGrabber:"",v={},p=function(e){v.width=!1,v.height=!1,"x"===u?(v.width=t.rFlex?parseInt(r[0].style[i],10):r[0].offsetWidth,t.rWidth=v.width):(v.height=t.rFlex?parseInt(r[0].style[t.rFlex],10):r[0].offsetHeight,t.rHeight=v.height),v.id=r[0].id,v.evt=e},g=function(e){return e.touches?e.touches[0].clientX:e.clientX},x=function(e){return e.touches?e.touches[0].clientY:e.clientY},b=function(n){function d(){t.rOnResizing({info:v}),t.$emit("angular-resizable.resizing",v)}var c,f="x"===u?a-g(n):a-x(n);switch(l){case"top":c=t.rFlex?i:"height",r[0].style[c]=o+f*m+"px";break;case"bottom":c=t.rFlex?i:"height",r[0].style[c]=o-f*m+"px";break;case"right":c=t.rFlex?i:"width",r[0].style[c]=s-f*h+"px";break;case"left":c=t.rFlex?i:"width",r[0].style[c]=s+f*h+"px"}p(n),t.rNoThrottle?d():e(d)},z=function(e){p(),t.$apply(),t.$emit("angular-resizable.resizeEnd",v),t.rOnResizeEnd({event:e,info:v}),document.removeEventListener("mouseup",z,!1),document.removeEventListener("mousemove",b,!1),document.removeEventListener("touchend",z,!1),document.removeEventListener("touchmove",b,!1),r.removeClass("no-transition")},E=function(e,n){l=n,u="left"===l||"right"===l?"x":"y",a="x"===u?g(e):x(e),s=parseInt(d.getPropertyValue("width")),o=parseInt(d.getPropertyValue("height")),r.addClass("no-transition"),document.addEventListener("mouseup",z,!1),document.addEventListener("mousemove",b,!1),document.addEventListener("touchend",z,!1),document.addEventListener("touchmove",b,!1),e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.cancelBubble=!0,e.returnValue=!1,p(e),t.$apply(),t.$emit("angular-resizable.resizeStart",v),t.rOnResizeStart({event:e,info:v})};c.forEach(function(e){var n=document.createElement("div");n.setAttribute("class","rg-"+e),n.innerHTML=f,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)})}}}}); \ No newline at end of file diff --git a/src/angular-resizable.js b/src/angular-resizable.js index 4a6e24a..b51a75f 100644 --- a/src/angular-resizable.js +++ b/src/angular-resizable.js @@ -25,13 +25,16 @@ angular.module('angularResizable', []) rDisabled: '@', rNoThrottle: '=', resizable: '@', + rOnResizeStart: '&', + rOnResizing: '&', + rOnResizeEnd: '&' }, link: function(scope, element, attr) { if (scope.resizable === 'false') return; var flexBasis = 'flexBasis' in document.documentElement.style ? 'flexBasis' : 'webkitFlexBasis' in document.documentElement.style ? 'webkitFlexBasis' : - 'msFlexPreferredSize' in document.documentElement.style ? 'msFlexPreferredSize' : 'flexBasis'; + 'msFlexPreferredSize' in document.documentElement.style ? 'msFlexPreferredSize' : 'flexBasis'; // register watchers on width and height attributes if they are set scope.$watch('rWidth', function(value){ @@ -57,10 +60,13 @@ angular.module('angularResizable', []) var updateInfo = function(e) { info.width = false; info.height = false; - if(axis === 'x') - info.width = parseInt(element[0].style[scope.rFlex ? flexBasis : 'width']); - else - info.height = parseInt(element[0].style[scope.rFlex ? flexBasis : 'height']); + if (axis === 'x') { + info.width = scope.rFlex ? parseInt(element[0].style[flexBasis], 10) : element[0].offsetWidth; + scope.rWidth = info.width; + } else { + info.height = scope.rFlex ? parseInt(element[0].style[scope.rFlex], 10) : element[0].offsetHeight; + scope.rHeight = info.height; + } info.id = element[0].id; info.evt = e; }; @@ -95,6 +101,7 @@ angular.module('angularResizable', []) } updateInfo(e); function resizingEmit(){ + scope.rOnResizing({info: info}); scope.$emit('angular-resizable.resizing', info); } if (scope.rNoThrottle) { @@ -105,8 +112,9 @@ angular.module('angularResizable', []) }; var dragEnd = function(e) { updateInfo(); - scope.$emit('angular-resizable.resizeEnd', info); scope.$apply(); + scope.$emit('angular-resizable.resizeEnd', info); + scope.rOnResizeEnd({event: e, info: info}); document.removeEventListener('mouseup', dragEnd, false); document.removeEventListener('mousemove', dragging, false); document.removeEventListener('touchend', dragEnd, false); @@ -135,8 +143,9 @@ angular.module('angularResizable', []) e.returnValue = false; updateInfo(e); - scope.$emit('angular-resizable.resizeStart', info); scope.$apply(); + scope.$emit('angular-resizable.resizeStart', info); + scope.rOnResizeStart({event: e, info: info}); }; dir.forEach(function (direction) {