%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/templates/p4_new/js/ |
Current File : /home/bitrix/www/bitrix/templates/p4_new/js/jquery.cropit.min.js |
/* * cropit - v0.1.7 * Customizable crop and zoom. * https://github.com/scottcheng/cropit * * Made by Scott Cheng * Based on https://github.com/yufeiliu/simple_image_uploader * Under MIT License */ !function(a){var b;b=function(){function a(){}return a.prototype.setup=function(a,b,c,d){var e,f;return null==c&&(c=1),f=b.w/a.w,e=b.h/a.h,this.minZoom=(null!=d?d.fitWidth:void 0)&&!(null!=d?d.fitHeight:void 0)?f:(null!=d?d.fitHeight:void 0)&&!(null!=d?d.fitWidth:void 0)?e:(null!=d?d.fitWidth:void 0)&&(null!=d?d.fitHeight:void 0)?e>f?f:e:e>f?e:f,this.maxZoom=this.minZoom<1/c?1/c:this.minZoom},a.prototype.getZoom=function(a){return this.minZoom&&this.maxZoom?a*(this.maxZoom-this.minZoom)+this.minZoom:null},a.prototype.getSliderPos=function(a){return this.minZoom&&this.maxZoom?this.minZoom===this.maxZoom?0:(a-this.minZoom)/(this.maxZoom-this.minZoom):null},a.prototype.isZoomable=function(){return this.minZoom&&this.maxZoom?this.minZoom!==this.maxZoom:null},a.prototype.fixZoom=function(a){return a<this.minZoom?this.minZoom:a>this.maxZoom?this.maxZoom:a},a}();var c,d;d={exportZoom:1,imageBackground:!1,imageBackgroundBorderWidth:0,imageState:null},c=function(){function c(b,c){var e;this.element=b,this.$el=a(this.element),e={$fileInput:this.$("input.cropit-image-input"),$preview:this.$(".cropit-image-preview"),$imageZoomInput:this.$("input.cropit-image-zoom-input"),$previewContainer:this.$(".cropit-image-preview-container")},this.options=a.extend({},d,e,c),this._defaults=d,this.init()}return c.prototype.init=function(){var c,d,e,f,g;return this.image=new Image,this.options.allowCrossOrigin&&(this.image.crossOrigin="Anonymous"),this.$fileInput=this.options.$fileInput.attr({accept:"image/*"}),this.$preview=this.options.$preview.css({backgroundRepeat:"no-repeat"}),this.$imageZoomInput=this.options.$imageZoomInput.attr({min:0,max:1,step:.01}),this.previewSize={w:this.options.width||this.$preview.width(),h:this.options.height||this.$preview.height()},this.options.width&&this.$preview.width(this.previewSize.w),this.options.height&&this.$preview.height(this.previewSize.h),this.options.imageBackground&&(d=this.options.imageBackgroundBorderWidth,c=this.options.$previewContainer,this.$imageBg=a("<img />").addClass("cropit-image-background").attr("alt","").css("position","absolute"),this.$imageBgContainer=a("<div />").addClass("cropit-image-background-container").css({position:"absolute",zIndex:0,left:-d+window.parseInt(this.$preview.css("border-left-width")),top:-d+window.parseInt(this.$preview.css("border-top-width")),width:this.previewSize.w+2*d,height:this.previewSize.h+2*d}).append(this.$imageBg),d>0&&this.$imageBgContainer.css({overflow:"hidden"}),c.css("position","relative").prepend(this.$imageBgContainer),this.$preview.css("position","relative"),this.$preview.hover(function(a){return function(){return a.$imageBg.addClass("cropit-preview-hovered")}}(this),function(a){return function(){return a.$imageBg.removeClass("cropit-preview-hovered")}}(this))),this.initialOffset={x:0,y:0},this.initialZoom=0,this.initialSliderPos=0,this.imageLoaded=!1,this.moveContinue=!1,this.zoomer=new b,this.$preview.on("mousedown mouseup mouseleave",this.onPreviewMouseEvent.bind(this)),this.$fileInput.on("change",this.onFileChange.bind(this)),this.$imageZoomInput.on("mousedown mouseup mousemove",this.onSliderChange.bind(this)),this.$imageZoomInput.val(this.initialSliderPos),this.setOffset((null!=(e=this.options.imageState)?e.offset:void 0)||this.initialOffset),this.zoom=(null!=(f=this.options.imageState)?f.zoom:void 0)||this.initialZoom,this.loadImage((null!=(g=this.options.imageState)?g.src:void 0)||null)},c.prototype.reset=function(){return this.zoom=this.initialZoom,this.offset=this.initialOffset},c.prototype.onFileChange=function(){var a,b,c;return"function"==typeof(c=this.options).onFileChange&&c.onFileChange(),b=new FileReader,a=this.$fileInput.get(0).files[0],(null!=a?a.type.match("image"):void 0)?(this.setImageLoadingClass(),b.readAsDataURL(a),b.onload=this.onFileReaderLoaded.bind(this),b.onerror=this.onFileReaderError.bind(this)):void 0},c.prototype.onFileReaderLoaded=function(a){return this.reset(),this.loadImage(a.target.result)},c.prototype.onFileReaderError=function(){var a;return"function"==typeof(a=this.options).onFileReaderError?a.onFileReaderError():void 0},c.prototype.loadImage=function(a){var b;return this.imageSrc=a,this.imageSrc?("function"==typeof(b=this.options).onImageLoading&&b.onImageLoading(),this.setImageLoadingClass(),this.image.onload=this.onImageLoaded.bind(this),this.image.onerror=this.onImageError.bind(this),this.image.src=this.imageSrc):void 0},c.prototype.onImageLoaded=function(){var a;return this.setImageLoadedClass(),this.setOffset(this.offset),this.$preview.css("background-image","url("+this.imageSrc+")"),this.options.imageBackground&&this.$imageBg.attr("src",this.imageSrc),this.imageSize={w:this.image.width,h:this.image.height},this.setupZoomer(),this.imageLoaded=!0,"function"==typeof(a=this.options).onImageLoaded?a.onImageLoaded():void 0},c.prototype.onImageError=function(){var a;return"function"==typeof(a=this.options).onImageError?a.onImageError():void 0},c.prototype.setImageLoadingClass=function(){return this.$preview.removeClass("cropit-image-loaded").addClass("cropit-image-loading")},c.prototype.setImageLoadedClass=function(){return this.$preview.removeClass("cropit-image-loading").addClass("cropit-image-loaded")},c.prototype.onPreviewMouseEvent=function(b){return this.imageLoaded?(this.moveContinue=!1,this.$preview.off("mousemove"),"mousedown"===b.type?(this.origin={x:b.clientX,y:b.clientY},this.moveContinue=!0,this.$preview.on("mousemove",this.onMove.bind(this))):a(document.body).focus(),b.stopPropagation(),!1):void 0},c.prototype.onMove=function(a){return this.moveContinue&&this.setOffset({x:this.offset.x+a.clientX-this.origin.x,y:this.offset.y+a.clientY-this.origin.y}),this.origin={x:a.clientX,y:a.clientY},a.stopPropagation(),!1},c.prototype.setOffset=function(a){return this.offset=this.fixOffset(a),this.$preview.css("background-position",""+this.offset.x+"px "+this.offset.y+"px"),this.options.imageBackground?this.$imageBg.css({left:this.offset.x+this.options.imageBackgroundBorderWidth,top:this.offset.y+this.options.imageBackgroundBorderWidth}):void 0},c.prototype.fixOffset=function(a){var b;return this.imageLoaded?(b={x:a.x,y:a.y},this.imageSize.w*this.zoom<=this.previewSize.w?b.x=0:b.x>0?b.x=0:b.x+this.imageSize.w*this.zoom<this.previewSize.w&&(b.x=this.previewSize.w-this.imageSize.w*this.zoom),this.imageSize.h*this.zoom<=this.previewSize.h?b.y=0:b.y>0?b.y=0:b.y+this.imageSize.h*this.zoom<this.previewSize.h&&(b.y=this.previewSize.h-this.imageSize.h*this.zoom),b.x=this.round(b.x),b.y=this.round(b.y),b):a},c.prototype.onSliderChange=function(){var a;if(this.imageLoaded)return this.sliderPos=Number(this.$imageZoomInput.val()),a=this.zoomer.getZoom(this.sliderPos),this.setZoom(a)},c.prototype.setupZoomer=function(){var a,b;return this.zoomer.setup(this.imageSize,this.previewSize,this.options.exportZoom,this.options),this.zoom=this.fixZoom(this.zoom),this.setZoom(this.zoom),this.isZoomable()?(this.$imageZoomInput.removeAttr("disabled"),"function"==typeof(a=this.options).onZoomEnabled?a.onZoomEnabled():void 0):(this.$imageZoomInput.attr("disabled",!0),"function"==typeof(b=this.options).onZoomDisabled?b.onZoomDisabled():void 0)},c.prototype.setZoom=function(a){var b,c,d,e,f;return a=this.fixZoom(a),f=this.round(this.imageSize.w*a),e=this.round(this.imageSize.h*a),d=this.zoom,b=this.previewSize.w/2-(this.previewSize.w/2-this.offset.x)*a/d,c=this.previewSize.h/2-(this.previewSize.h/2-this.offset.y)*a/d,this.zoom=a,this.setOffset({x:b,y:c}),this.sliderPos=this.zoomer.getSliderPos(this.zoom),this.$imageZoomInput.val(this.sliderPos),this.$preview.css("background-size",""+f+"px "+e+"px"),this.options.imageBackground?this.$imageBg.css({width:f,height:e}):void 0},c.prototype.fixZoom=function(a){return this.zoomer.fixZoom(a)},c.prototype.isZoomable=function(){return this.zoomer.isZoomable()},c.prototype.getCroppedImageData=function(b){var c,d,e,f,g;return this.imageSrc?(f={type:"image/png",quality:.75,originalSize:!1},b=a.extend({},f,b),e={w:this.previewSize.w,h:this.previewSize.h},this.options.fitHeight&&!this.options.fitWidth&&this.imageSize.w*this.zoom<this.previewSize.w?e.w=this.imageSize.w*this.zoom:this.options.fitWidth&&!this.options.fitHeight&&this.imageSize.h*this.zoom<this.previewSize.h&&(e.h=this.imageSize.h*this.zoom),g=b.originalSize?1/this.zoom:this.options.exportZoom,c=a("<canvas />").attr({width:e.w*g,height:e.h*g}).get(0),d=c.getContext("2d"),d.drawImage(this.image,this.offset.x*g,this.offset.y*g,this.zoom*g*this.imageSize.w,this.zoom*g*this.imageSize.h),c.toDataURL(b.type,b.quality)):null},c.prototype.getImageState=function(){return{src:this.imageSrc,offset:this.offset,zoom:this.zoom}},c.prototype.getImageSrc=function(){return this.imageSrc},c.prototype.getOffset=function(){return this.offset},c.prototype.getZoom=function(){return this.zoom},c.prototype.getImageSize=function(){return this.imageSize?{width:this.imageSize.w,height:this.imageSize.h}:null},c.prototype.getPreviewSize=function(){return{width:this.previewSize.w,height:this.previewSize.h}},c.prototype.setPreviewSize=function(a){return(null!=a?a.width:void 0)>0&&(null!=a?a.height:void 0)>0?(this.previewSize={w:a.width,h:a.height},this.$preview.css({width:this.previewSize.w,height:this.previewSize.h}),this.options.imageBackground&&this.$imageBgContainer.css({width:this.previewSize.w+2*this.options.imageBackgroundBorderWidth,height:this.previewSize.h+2*this.options.imageBackgroundBorderWidth}),this.imageLoaded?this.setupZoomer():void 0):void 0},c.prototype.round=function(a){return Math.round(1e5*a)/1e5},c.prototype.$=function(a){return this.$el?this.$el.find(a):null},c}();var e,f;e="cropit",f={init:function(b){return this.each(function(){var d;return a.data(this,e)?void 0:(d=new c(this,b),a.data(this,e,d))})},destroy:function(){return this.each(function(){return a.removeData(this,e)})},isZoomable:function(){var a;return a=this.first().data(e),null!=a?a.isZoomable():void 0},"export":function(a){var b;return b=this.first().data(e),null!=b?b.getCroppedImageData(a):void 0},imageState:function(){var a;return a=this.first().data(e),null!=a?a.getImageState():void 0},imageSrc:function(b){var c;return null!=b?this.each(function(){var c;return c=a.data(this,e),null!=c&&c.reset(),null!=c?c.loadImage(b):void 0}):(c=this.first().data(e),null!=c?c.getImageSrc():void 0)},offset:function(b){var c;return null!=b&&null!=b.x&&null!=b.y?this.each(function(){var c;return c=a.data(this,e),null!=c?c.setOffset(b):void 0}):(c=this.first().data(e),null!=c?c.getOffset():void 0)},zoom:function(b){var c;return null!=b?this.each(function(){var c;return c=a.data(this,e),null!=c?c.setZoom(b):void 0}):(c=this.first().data(e),null!=c?c.getZoom():void 0)},imageSize:function(){var a;return a=this.first().data(e),null!=a?a.getImageSize():void 0},previewSize:function(b){var c;return null!=b?this.each(function(){var c;return c=a.data(this,e),null!=c?c.setPreviewSize(b):void 0}):(c=this.first().data(e),null!=c?c.getPreviewSize():void 0)}},a.fn.cropit=function(a){return f[a]?f[a].apply(this,[].slice.call(arguments,1)):f.init.apply(this,arguments)}}(window.jQuery);