PTMagic/Monitor/wwwroot/assets/plugins/cropper/cropper.min.js

9 lines
15 KiB
JavaScript
Raw Normal View History

2018-05-22 10:11:50 +02:00
/*!
* Cropper v0.7.0
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
* Released under the MIT license
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";var b=a(window),c=a(document),d=!0,e=!1,f=null,g=0/0,h=1/0,i="undefined",j="directive",k=".cropper",l=/^(e|n|w|s|ne|nw|sw|se|all|crop|move|zoom)$/i,m=/^(x|y|width|height|rotate)$/i,n=/^(naturalWidth|naturalHeight|width|height|aspectRatio|ratio|rotate)$/i,o="cropper-modal",p="cropper-hidden",q="cropper-invisible",r="cropper-move",s="cropper-crop",t="cropper-disabled",u="mousedown touchstart",v="mousemove touchmove",w="mouseup mouseleave touchend touchleave touchcancel",x="wheel mousewheel DOMMouseScroll",y="resize"+k,z="dblclick",A="build"+k,B="built"+k,C="dragstart"+k,D="dragmove"+k,E="dragend"+k,F=function(a){return"number"==typeof a},G=function(a){return'<img src="'+a+'">'},H=function(a){return"rotate("+a+"deg)"},I=function(b,c){this.$element=a(b),this.defaults=a.extend({},I.DEFAULTS,a.isPlainObject(c)?c:{}),this.ready=e,this.built=e,this.cropped=e,this.disabled=e,this.init()},J=Math.round,K=Math.sqrt,L=Math.min,M=Math.max,N=Math.abs,O=parseFloat;I.prototype={constructor:I,init:function(){var b=this.defaults;a.each(b,function(a,c){switch(a){case"aspectRatio":b[a]=N(O(c))||g;break;case"minWidth":case"minHeight":b[a]=N(O(c))||0;break;case"maxWidth":case"maxHeight":b[a]=N(O(c))||h}}),this.load()},load:function(){var b,c,e=this,f=this.$element,g=f[0],h={};f.is("img")?c=f.attr("src"):f.is("canvas")&&g.getContext&&(c=g.toDataURL()),c&&(this.$clone&&this.$clone.remove(),this.$clone=b=a(G(c)),b.one("load",function(){h.naturalWidth=this.naturalWidth||b.width(),h.naturalHeight=this.naturalHeight||b.height(),h.aspectRatio=h.naturalWidth/h.naturalHeight,e.url=c,e.image=h,e.ready=d,e.build()}),b.addClass(q).prependTo("body"))},build:function(){var b,e,f=this.$element,g=this.defaults;this.ready&&(this.built&&this.unbuild(),f.one(A,g.build),b=a.Event(A),f.trigger(b),b.isDefaultPrevented()||(this.$cropper=e=a(I.TEMPLATE),f.addClass(p),this.$clone.removeClass(q).prependTo(e),this.$container=f.parent(),this.$container.append(e),this.$canvas=e.find(".cropper-canvas"),this.$dragger=e.find(".cropper-dragger"),this.$viewer=e.find(".cropper-viewer"),g.autoCrop?this.cropped=d:this.$dragger.addClass(p),g.dragCrop&&this.setDragMode("crop"),g.modal&&this.$canvas.addClass(o),!g.dashed&&this.$dragger.find(".cropper-dashed").addClass(p),!g.movable&&this.$dragger.find(".cropper-face").addClass(p),!g.resizable&&this.$dragger.find(".cropper-line, .cropper-point").addClass(p),this.$dragScope=g.multiple?this.$cropper:c,this.addListeners(),this.initPreview(),this.built=d,this.update(),f.one(B,g.built),f.trigger(B)))},unbuild:function(){this.built&&(this.built=e,this.removeListeners(),this.$preview.empty(),this.$preview=f,this.$dragger=f,this.$canvas=f,this.$container=f,this.$cropper.remove(),this.$cropper=f)},update:function(a){this.initContainer(),this.initCropper(),this.initImage(),this.initDragger(),a?(this.setData(a,d),this.setDragMode("crop")):this.setData(this.defaults.data)},resize:function(){clearTimeout(this.resizing),this.resizing=setTimeout(a.proxy(this.update,this,this.getData()),200)},preview:function(){var b=this.image,c=this.dragger,d=b.width,e=b.height,f=c.left-b.left,g=c.top-b.top,h=b.rotate;this.$viewer.find("img").css({width:J(d),height:J(e),marginLeft:-J(f),marginTop:-J(g),transform:H(h)}),this.$preview.each(function(){var b=a(this),i=b.width()/c.width;b.find("img").css({width:J(d*i),height:J(e*i),marginLeft:-J(f*i),marginTop:-J(g*i),transform:H(h)})})},addListeners:function(){var c=this.$element,d=this.defaults;c.on(C,d.dragstart).on(D,d.dragmove).on(E,d.dragend),this.$cropper.on(u,a.proxy(this.dragstart,this)).on(z,a.proxy(this.dblclick,this)),d.zoomable&&this.$cropper.on(x,a.proxy(this.wheel,this)),this.$dragScope.on(v,a.proxy(this.dragmove,this)).on(w,a.proxy(this.dragend,this)),b.on(y,a.proxy(this.resize,this))},removeListeners:function(){var a=this.$element,c=this.defaults;a.off(C,c.dragstart).off(D,c.dragmove).off(E,c.dragend),this.$cropper.off(u,this.dragstart).off(z,this.dblclick),c.zoomable&&this.$cropper.off(x,this.w