gentelella/production/js/cropping/cropper.min.js

10 lines
17 KiB
JavaScript
Raw Normal View History

2015-05-19 08:25:00 +02:00
/*!
* Cropper v0.8.0
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014-2015 Fengyuan Chen
* Released under the MIT license
*
* Date: 2015-02-19T06:49:29.144Z
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){"use strict";function b(a){return"number"==typeof a}function c(a){return"string"==typeof a}function d(a){return"undefined"==typeof a}function e(a,c){var d=[];return b(c)&&d.push(c),d.slice.apply(a,d)}function f(a,b){var c=e(arguments,2);return function(){return a.apply(b,c.concat(e(arguments)))}}function g(a){var b=a.match(/^(https?:)\/\/([^\:\/\?#]+):?(\d*)/i);return!b||b[1]===o.protocol&&b[2]===o.hostname&&b[3]===o.port?!1:!0}function h(a){var b="timestamp="+(new Date).getTime();return a+(-1===a.indexOf("?")?"?":"&")+b}function i(a){return a?"rotate("+a+"deg)":"none"}function j(a){var b=Q(a.degree)%180,c=(b>90?180-b:b)*Math.PI/180;return{width:a.width*S(c)+a.height*R(c),height:a.width*R(c)+a.height*S(c)}}function k(b,c){var d=a("<canvas>")[0],e=d.getContext("2d"),f=c.naturalWidth,g=c.naturalHeight,h=c.rotate,i=j({width:f,height:g,degree:h});return h?(d.width=i.width,d.height=i.height,e.save(),e.translate(i.width/2,i.height/2),e.rotate(h*Math.PI/180),e.drawImage(b,-f/2,-g/2,f,g),e.restore()):(d.width=f,d.height=g,e.drawImage(b,0,0,f,g)),d}function l(b,c){this.$element=a(b),this.options=a.extend({},l.DEFAULTS,a.isPlainObject(c)&&c),this.ready=!1,this.built=!1,this.cropped=!1,this.disabled=!1,this.load()}var m=a(window),n=a(document),o=window.location,p="directive",q=".cropper",r=/^(e|n|w|s|ne|nw|sw|se|all|crop|move|zoom)$/,s="cropper-modal",t="cropper-hide",u="cropper-hidden",v="cropper-invisible",w="cropper-move",x="cropper-crop",y="cropper-disabled",z="cropper-bg",A="mousedown touchstart",B="mousemove touchmove",C="mouseup mouseleave touchend touchleave touchcancel",D="wheel mousewheel DOMMouseScroll",E="dblclick",F="resize"+q,G="build"+q,H="built"+q,I="dragstart"+q,J="dragmove"+q,K="dragend"+q,L={canvas:a.isFunction(a("<canvas>")[0].getContext)},M=Math.round,N=Math.sqrt,O=Math.min,P=Math.max,Q=Math.abs,R=Math.sin,S=Math.cos,T=parseFloat,U={};U.load=function(){var b,c,d,e=this,f=this.options,i=this.$element,j="";i.is("img")?d=i.prop("src"):i.is("canvas")&&L.canvas&&(d=i[0].toDataURL()),d&&(b=a.Event(G),i.one(G,f.build).trigger(b),b.isDefaultPrevented()||(f.checkImageOrigin&&g(d)&&(j=" crossOrigin",d=h(d)),this.$clone=c=a("<img"+j+' src="'+d+'">'),c.one("load",function(){var a=this.naturalWidth||c.width(),b=this.naturalHeight||c.height();e.image={naturalWidth:a,naturalHeight:b,aspectRatio:a/b,rotate:0},e.url=d,e.ready=!0,e.build()}),c.addClass(t).prependTo("body")))},U.build=function(){var b,c,d=this.$element,e=this.options;this.ready&&(this.built&&this.unbuild(),this.$cropper=b=a(l.TEMPLATE),d.addClass(u),this.$clone.removeClass(t).prependTo(b),this.$container=d.parent(),this.$container.append(b),this.$canvas=b.find(".cropper-canvas"),this.$cropBox=c=b.find(".cropper-cropbox"),this.$viewer=b.find(".cropper-viewer"),this.addListeners(),this.initPreview(),e.aspectRatio=Q(T(e.aspectRatio))||0/0,e.autoCrop?(this.cropped=!0,e.modal&&this.$canvas.addClass(s)):c.addClass(u),e.background&&b.addClass(z),!e.highlight&&c.find(".cropper-face").addClass(v),!e.guides&&c.find(".cropper-dashed").addClass(u),!e.movable&&c.find(".cropper-face").data(p,"move"),!e.resizable&&c.find(".cropper-line, .cropper-point").addClass(u),this.setDragMode(e.dragCrop?"crop":"move"),this.built=!0,this.render(),d.one(H,e.built).trigger(H))},U.unbuild=function(){this.built&&(this.built=!1,this.removeListeners(),this.$preview.empty(),this.$preview=null,this.$cropBox=null,this.$canvas=null,this.$container=null,this.$cropper.remove(),this.$cropper=null)},a.extend(U,{render:function(){this.initContainer(),this.initImage(),this.initCropBox()},initContainer:function(){var a=this.$element,b=this.$container,c=this.$cropper,d=this.options;c.addClass(u),a.removeClass(u),c.css(this.container={width:P(b.width(),T(d.minContainerWidth)||350),height:P(b.height(),T(d.minContainerHeight)||150)}),a.addClass(u),c.removeClass(u)},initImage:function(){var b=this.container,c=this.image,d=c.aspectRatio,e=b.width,f=b.height,g=c.naturalWidth,h