forked from allenJynRoyston/ngCroppie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-croppie.min.js
1 lines (1 loc) · 2.3 KB
/
ng-croppie.min.js
1
!function(){"use strict";angular.module("ngCroppie",[]).directive("ngCroppie",["$timeout",function(o){return{restrict:"AE",scope:{src:"=",rotation:"=",viewport:"=",boundry:"=",type:"@",zoom:"@",mousezoom:"@",zoomslider:"@",exif:"@",orientation:"@",update:"=",ngModel:"=",mobile:"@"},link:function(e,n,t){void 0==e.viewport&&(e.viewport={w:null,h:null}),void 0==e.boundry&&(e.boundry={w:null,h:null}),"true"===e.mobile?(e.viewport.w=250,e.viewport.h=250,e.boundry.w=300,e.boundry.h=300):(e.viewport.w=void 0!=e.viewport.w?e.viewport.w:300,e.viewport.h=void 0!=e.viewport.h?e.viewport.h:300,e.boundry.w=void 0!=e.boundry.w?e.boundry.w:400,e.boundry.h=void 0!=e.boundry.h?e.boundry.h:400),e.viewport.w>e.boundry.w&&(e.viewport.w=e.boundry.w),e.viewport.h>e.boundry.h&&(e.viewport.h=e.boundry.h);var i="true"===e.zoom||void 0===e.zoom,r="true"===e.mousezoom||void 0===e.mousezoom,u="true"===e.zoomslider||void 0===e.zoomslider,a={viewport:{width:e.viewport.w,height:e.viewport.h,type:e.type||"square"},boundary:{width:e.boundry.w,height:e.boundry.h},enableZoom:i,mouseWheelZoom:r,showZoomer:u,enableExif:e.exif,enableOrientation:e.orientation};void 0!=e.update&&(a.update=e.update);var d,l=new Croppie(n[0],a),v=angular.element(n[0])[0],c=angular.element(n[0].getElementsByClassName("cr-boundary"))[0].getBoundingClientRect();v.addEventListener("mousedown",function(){d=window.setInterval(function(){l.result("canvas").then(function(o){e.$apply(function(){e.ngModel=o})})},250)},!1),r&&v.addEventListener("wheel",function(o){console.log("Wheel event called"),o.preventDefault(),o.clientX>c.left&&o.clientX<c.right&&o.clientY<c.bottom&&o.clientY>c.top&&l.result("canvas").then(function(o){e.$apply(function(){e.ngModel=o})})},!1),v.addEventListener("mouseup",function(){clearInterval(d)},!1),v.addEventListener("mouseleave",function(){clearInterval(d)},!1),v.addEventListener("mouseout",function(){clearInterval(d)},!1),e.$on("$destroy",function(o){clearInterval(d)}),e.$watch("rotation",function(o,n){if("false"===e.orientation||void 0==e.orientation)throw"ngCroppie: Cannot rotate without 'orientation' option";l.rotate(o-n),l.result("canvas").then(function(o){e.$apply(function(){e.ngModel=o})})}),e.$watch("src",function(n,t){void 0!=e.src&&(l.bind(e.src),o(function(){l.result("canvas").then(function(o){e.$apply(function(){e.ngModel=o})})},250))})}}}])}();