From 84c5d417226599ed34dc8b2941efd1998e49f92f Mon Sep 17 00:00:00 2001 From: Elizabeth Young Date: Fri, 27 Mar 2015 08:29:11 +0000 Subject: [PATCH] Added header object to options Added a header object to options. --- croppic.js | 9 ++++++--- croppic.min.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/croppic.js b/croppic.js index a9edeca..321bb11 100644 --- a/croppic.js +++ b/croppic.js @@ -34,7 +34,8 @@ processInline: false, loadPicture:'', onReset: null, - enableMousescroll: false, + enableMousescroll: false, + headers: {}, //callbacks onBeforeImgUpload: null, @@ -221,7 +222,8 @@ cache: false, contentType: false, processData: false, - type: 'POST' + type: 'POST', + headers: that.options.headers }).always(function(data){ response = typeof data =='object' ? data : jQuery.parseJSON(data); if(response.status=='success'){ @@ -612,7 +614,8 @@ cache: false, contentType: false, processData: false, - type: 'POST' + type: 'POST', + headers: that.options.headers }).always(function(data){ response = typeof data =='object' ? data : jQuery.parseJSON(data); diff --git a/croppic.min.js b/croppic.min.js index 569346b..85de359 100644 --- a/croppic.min.js +++ b/croppic.min.js @@ -3,4 +3,4 @@ * dependancy: jQuery * author: Ognjen "Zmaj Džedaj" Božičković and Mat Steinlin */ - !function(o,t){Croppic=function(o,t){var n=this;n.id=o,n.obj=$("#"+o),n.outputDiv=n.obj,n.options={uploadUrl:"",uploadData:{},cropUrl:"",cropData:{},outputUrlId:"",imgEyecandy:!0,imgEyecandyOpacity:.2,zoomFactor:10,rotateFactor:5,doubleZoomControls:!0,rotateControls:!0,modal:!1,customUploadButtonId:"",loaderHtml:"",scaleToFill:!0,processInline:!1,loadPicture:"",onReset:null,enableMousescroll:!1,onBeforeImgUpload:null,onAfterImgUpload:null,onImgDrag:null,onImgZoom:null,onImgRotate:null,onBeforeImgCrop:null,onAfterImgCrop:null,onError:null};for(i in t)n.options[i]=t[i];n.init()},Croppic.prototype={id:"",imgInitW:0,imgInitH:0,imgW:0,imgH:0,objW:0,objH:0,actualRotation:0,windowW:0,windowH:$(o).height(),obj:{},outputDiv:{},outputUrlObj:{},img:{},defaultImg:{},croppedImg:{},imgEyecandy:{},form:{},cropControlsUpload:{},cropControlsCrop:{},cropControlZoomMuchIn:{},cropControlZoomMuchOut:{},cropControlZoomIn:{},cropControlZoomOut:{},cropControlCrop:{},cropControlReset:{},cropControlRemoveCroppedImage:{},modal:{},loader:{},init:function(){var o=this;o.objW=o.obj.width(),o.objH=o.obj.height(),o.actualRotation=0,$.isEmptyObject(o.defaultImg)&&(o.defaultImg=o.obj.find("img")),o.createImgUploadControls(),$.isEmptyObject(o.options.loadPicture)?o.bindImgUploadControl():o.loadExistingImage()},createImgUploadControls:function(){var o=this,t="";""===o.options.customUploadButtonId&&(t='');var i='';$.isEmptyObject(o.croppedImg)&&(i=""),$.isEmptyObject(o.options.loadPicture)||(t="");var n='
'+t+i+"
";o.outputDiv.append(n),o.cropControlsUpload=o.outputDiv.find(".cropControlsUpload"),""===o.options.customUploadButtonId?o.imgUploadControl=o.outputDiv.find(".cropControlUpload"):(o.imgUploadControl=$("#"+o.options.customUploadButtonId),o.imgUploadControl.show()),$.isEmptyObject(o.croppedImg)||(o.cropControlRemoveCroppedImage=o.outputDiv.find(".cropControlRemoveCroppedImage"))},bindImgUploadControl:function(){var o=this,i='';o.outputDiv.append(i),o.form=o.outputDiv.find("."+o.id+"_imgUploadForm"),o.imgUploadControl.off("click"),o.imgUploadControl.on("click",function(){o.form.find('input[type="file"]').trigger("click")}),$.isEmptyObject(o.croppedImg)||o.cropControlRemoveCroppedImage.on("click",function(){o.croppedImg.remove(),$(this).hide(),$.isEmptyObject(o.defaultImg)||o.obj.append(o.defaultImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val("")}),o.form.find('input[type="file"]').change(function(){if(o.options.onBeforeImgUpload&&o.options.onBeforeImgUpload.call(o),o.showLoader(),o.imgUploadControl.hide(),o.options.processInline){var i=new FileReader;i.onload=function(t){var i=new Image;i.src=t.target.result,i.onload=function(){o.imgInitW=o.imgW=i.width,o.imgInitH=o.imgH=i.height,o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=i.src,o.obj.append(''),o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)}},i.readAsDataURL(o.form.find('input[type="file"]')[0].files[0])}else{var n=new FormData(o.form[0]);for(var r in o.options.uploadData)o.options.uploadData.hasOwnProperty(r)&&n.append(r,o.options.uploadData[r]);$.ajax({url:o.options.uploadUrl,data:n,context:t.body,cache:!1,contentType:!1,processData:!1,type:"POST"}).always(function(t){if(response="object"==typeof t?t:jQuery.parseJSON(t),"success"==response.status){o.imgInitW=o.imgW=response.width,o.imgInitH=o.imgH=response.height,o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=response.url;var i=$('');o.obj.append(i),i.load(function(){o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)})}"error"==response.status&&(o.options.onError&&o.options.onError.call(o,response.message),o.hideLoader(),setTimeout(function(){o.reset()},2e3))})}})},loadExistingImage:function(){var o=this;if($.isEmptyObject(o.croppedImg)){o.options.onBeforeImgUpload&&o.options.onBeforeImgUpload.call(o),o.showLoader(),o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=o.options.loadPicture;var t=$('');o.obj.append(t),t.load(function(){o.imgInitW=o.imgW=this.width,o.imgInitH=o.imgH=this.height,o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)})}else o.cropControlRemoveCroppedImage.on("click",function(){o.croppedImg.remove(),$(this).hide(),$.isEmptyObject(o.defaultImg)||o.obj.append(o.defaultImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(""),o.croppedImg="",o.reset()})},createModal:function(){var o=this,t=o.windowH/2-o.objH/2,i='
';$("body").append(i),o.modal=$("#croppicModal"),o.obj=$("#croppicModalObj")},destroyModal:function(){var o=this;o.obj=o.outputDiv,o.modal.remove()},initCropper:function(){var o=this;o.img=o.obj.find("img"),o.img.wrap('
'),o.createCropControls(),o.options.imgEyecandy&&o.createEyecandy(),o.initDrag(),o.initialScaleImg()},createEyecandy:function(){var o=this;o.imgEyecandy=o.img.clone(),o.imgEyecandy.css({"z-index":"0",opacity:o.options.imgEyecandyOpacity}).appendTo(o.obj)},destroyEyecandy:function(){var o=this;o.imgEyecandy.remove()},initialScaleImg:function(){var o=this;o.zoom(-o.imgInitW),o.zoom(40),o.options.enableMousescroll&&o.img.on("mousewheel",function(t){t.preventDefault(),o.zoom(o.options.zoomFactor*t.deltaY)}),o.img.css({left:-(o.imgW-o.objW)/2,top:-(o.imgH-o.objH)/2,position:"relative"}),o.options.imgEyecandy&&o.imgEyecandy.css({left:-(o.imgW-o.objW)/2,top:-(o.imgH-o.objH)/2,position:"relative"})},createCropControls:function(){var o,t=this,i="",n='',r='',e="",p="",a="",s='',c='';t.options.doubleZoomControls&&(i='',e=''),t.options.rotateControls&&(p='',a=''),o='
'+i+n+r+e+p+a+s+c+"
",t.obj.append(o),t.cropControlsCrop=t.obj.find(".cropControlsCrop"),t.options.doubleZoomControls&&(t.cropControlZoomMuchIn=t.cropControlsCrop.find(".cropControlZoomMuchIn"),t.cropControlZoomMuchIn.on("click",function(){t.zoom(10*t.options.zoomFactor)}),t.cropControlZoomMuchOut=t.cropControlsCrop.find(".cropControlZoomMuchOut"),t.cropControlZoomMuchOut.on("click",function(){t.zoom(10*-t.options.zoomFactor)})),t.cropControlZoomIn=t.cropControlsCrop.find(".cropControlZoomIn"),t.cropControlZoomIn.on("click",function(){t.zoom(t.options.zoomFactor)}),t.cropControlZoomOut=t.cropControlsCrop.find(".cropControlZoomOut"),t.cropControlZoomOut.on("click",function(){t.zoom(-t.options.zoomFactor)}),t.cropControlZoomIn=t.cropControlsCrop.find(".cropControlRotateLeft"),t.cropControlZoomIn.on("click",function(){t.rotate(-t.options.rotateFactor)}),t.cropControlZoomOut=t.cropControlsCrop.find(".cropControlRotateRight"),t.cropControlZoomOut.on("click",function(){t.rotate(t.options.rotateFactor)}),t.cropControlCrop=t.cropControlsCrop.find(".cropControlCrop"),t.cropControlCrop.on("click",function(){t.crop()}),t.cropControlReset=t.cropControlsCrop.find(".cropControlReset"),t.cropControlReset.on("click",function(){t.reset()})},initDrag:function(){var t=this;t.img.on("mousedown touchstart",function(i){i.preventDefault();var n,r,e=o.navigator.userAgent;e.match(/iPad/i)||e.match(/iPhone/i)||e.match(/android/i)?(n=i.originalEvent.touches[0].pageX,r=i.originalEvent.touches[0].pageY):(n=i.pageX,r=i.pageY);var p=t.img.css("z-index"),a=t.img.outerHeight(),s=t.img.outerWidth(),c=t.img.offset().top+a-r,l=t.img.offset().left+s-n;t.img.css("z-index",1e3).on("mousemove touchmove",function(o){var i,n;if(e.match(/iPad/i)||e.match(/iPhone/i)||e.match(/android/i)?(i=o.originalEvent.touches[0].pageY+c-a,n=o.originalEvent.touches[0].pageX+l-s):(i=o.pageY+c-a,n=o.pageX+l-s),t.img.offset({top:i,left:n}).on("mouseup",function(){$(this).removeClass("draggable").css("z-index",p)}),t.options.imgEyecandy&&t.imgEyecandy.offset({top:i,left:n}),t.objH0&&(t.img.css("top",0),t.options.imgEyecandy&&t.imgEyecandy.css("top",0));var r=-(t.imgH-t.objH);parseInt(t.img.css("top"))r&&(t.img.css("top",r),t.options.imgEyecandy&&t.imgEyecandy.css("top",r))}if(t.objW0&&(t.img.css("left",0),t.options.imgEyecandy&&t.imgEyecandy.css("left",0));var m=-(t.imgW-t.objW);parseInt(t.img.css("left"))m&&(t.img.css("left",m),t.options.imgEyecandy&&t.imgEyecandy.css("left",m))}t.options.onImgDrag&&t.options.onImgDrag.call(t)})}).on("mouseup",function(){t.img.off("mousemove")}).on("mouseout",function(){t.img.off("mousemove")})},rotate:function(o){var t=this;t.actualRotation+=o,t.img.css({"-webkit-transform":"rotate("+t.actualRotation+"deg)","-moz-transform":"rotate("+t.actualRotation+"deg)",transform:"rotate("+t.actualRotation+"deg)"}),t.options.imgEyecandy&&t.imgEyecandy.css({"-webkit-transform":"rotate("+t.actualRotation+"deg)","-moz-transform":"rotate("+t.actualRotation+"deg)",transform:"rotate("+t.actualRotation+"deg)"}),"function"==typeof t.options.onImgRotate&&t.options.onImgRotate.call(t)},zoom:function(o){var t=this,i=t.imgW/t.imgH,n=t.imgW+o,r=n/i,e=!0;(nt.imgInitW||r>t.imgInitH)&&(n-t.imgInitW0&&(p=0),a>0&&(a=0);var s=-(r-t.objH);s>p&&(p=s);var c=-(n-t.objW);c>a&&(a=c),e&&t.img.css({top:p,left:a}),t.options.imgEyecandy&&(t.imgEyecandy.width(n),t.imgEyecandy.height(r),e&&t.imgEyecandy.css({top:p,left:a})),t.options.onImgZoom&&t.options.onImgZoom.call(t)},crop:function(){var o=this;o.options.onBeforeImgCrop&&o.options.onBeforeImgCrop.call(o),o.cropControlsCrop.hide(),o.showLoader();var i={imgUrl:o.imgUrl,imgInitW:o.imgInitW,imgInitH:o.imgInitH,imgW:o.imgW,imgH:o.imgH,imgY1:Math.abs(parseInt(o.img.css("top"))),imgX1:Math.abs(parseInt(o.img.css("left"))),cropH:o.objH,cropW:o.objW,rotation:o.actualRotation},n=new FormData;for(var r in i)i.hasOwnProperty(r)&&n.append(r,i[r]);for(var r in o.options.cropData)o.options.cropData.hasOwnProperty(r)&&n.append(r,o.options.cropData[r]);$.ajax({url:o.options.cropUrl,data:n,context:t.body,cache:!1,contentType:!1,processData:!1,type:"POST"}).always(function(t){response="object"==typeof t?t:jQuery.parseJSON(t),"success"==response.status&&(o.options.imgEyecandy&&o.imgEyecandy.hide(),o.destroy(),o.obj.append(''),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(response.url),o.croppedImg=o.obj.find(".croppedImg"),o.init(),o.hideLoader()),"error"==response.status&&(o.options.onError&&o.options.onError.call(o,response.message),o.hideLoader(),setTimeout(function(){o.reset()},2e3)),o.options.onAfterImgCrop&&o.options.onAfterImgCrop.call(o)})},showLoader:function(){var o=this;o.obj.append(o.options.loaderHtml),o.loader=o.obj.find(".loader")},hideLoader:function(){var o=this;o.loader.remove()},reset:function(){var o=this;o.destroy(),o.init(),$.isEmptyObject(o.croppedImg)||(o.obj.append(o.croppedImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(o.croppedImg.attr("url"))),"function"==typeof o.options.onReset&&o.options.onReset.call(o)},destroy:function(){var o=this;o.options.modal&&!$.isEmptyObject(o.modal)&&o.destroyModal(),o.options.imgEyecandy&&!$.isEmptyObject(o.imgEyecandy)&&o.destroyEyecandy(),$.isEmptyObject(o.cropControlsUpload)||o.cropControlsUpload.remove(),$.isEmptyObject(o.cropControlsCrop)||o.cropControlsCrop.remove(),$.isEmptyObject(o.loader)||o.loader.remove(),$.isEmptyObject(o.form)||o.form.remove(),o.obj.html("")}}}(window,document); \ No newline at end of file + !function(o,t){Croppic=function(o,t){var n=this;n.id=o,n.obj=$("#"+o),n.outputDiv=n.obj,n.options={uploadUrl:"",uploadData:{},cropUrl:"",cropData:{},outputUrlId:"",imgEyecandy:!0,imgEyecandyOpacity:.2,zoomFactor:10,rotateFactor:5,doubleZoomControls:!0,rotateControls:!0,modal:!1,customUploadButtonId:"",loaderHtml:"",scaleToFill:!0,processInline:!1,loadPicture:"",onReset:null,enableMousescroll:!1,headers:{},onBeforeImgUpload:null,onAfterImgUpload:null,onImgDrag:null,onImgZoom:null,onImgRotate:null,onBeforeImgCrop:null,onAfterImgCrop:null,onBeforeRemoveCroppedImg:null,onAfterRemoveCroppedImg:null,onError:null};for(i in t)n.options[i]=t[i];n.init()},Croppic.prototype={id:"",imgInitW:0,imgInitH:0,imgW:0,imgH:0,objW:0,objH:0,actualRotation:0,windowW:0,windowH:$(o).height(),obj:{},outputDiv:{},outputUrlObj:{},img:{},defaultImg:{},croppedImg:{},imgEyecandy:{},form:{},cropControlsUpload:{},cropControlsCrop:{},cropControlZoomMuchIn:{},cropControlZoomMuchOut:{},cropControlZoomIn:{},cropControlZoomOut:{},cropControlCrop:{},cropControlReset:{},cropControlRemoveCroppedImage:{},modal:{},loader:{},init:function(){var o=this;o.objW=o.obj.width(),o.objH=o.obj.height(),o.actualRotation=0,$.isEmptyObject(o.defaultImg)&&(o.defaultImg=o.obj.find("img")),o.createImgUploadControls(),$.isEmptyObject(o.options.loadPicture)?o.bindImgUploadControl():o.loadExistingImage()},createImgUploadControls:function(){var o=this,t="";""===o.options.customUploadButtonId&&(t='');var i='';$.isEmptyObject(o.croppedImg)&&(i=""),$.isEmptyObject(o.options.loadPicture)||(t="");var n='
'+t+i+"
";o.outputDiv.append(n),o.cropControlsUpload=o.outputDiv.find(".cropControlsUpload"),""===o.options.customUploadButtonId?o.imgUploadControl=o.outputDiv.find(".cropControlUpload"):(o.imgUploadControl=$("#"+o.options.customUploadButtonId),o.imgUploadControl.show()),$.isEmptyObject(o.croppedImg)||(o.cropControlRemoveCroppedImage=o.outputDiv.find(".cropControlRemoveCroppedImage"))},bindImgUploadControl:function(){var o=this,i='';o.outputDiv.append(i),o.form=o.outputDiv.find("."+o.id+"_imgUploadForm"),o.imgUploadControl.off("click"),o.imgUploadControl.on("click",function(){o.form.find('input[type="file"]').trigger("click")}),$.isEmptyObject(o.croppedImg)||o.cropControlRemoveCroppedImage.on("click",function(){typeof o.options.onBeforeRemoveCroppedImg==typeof Function&&o.options.onBeforeRemoveCroppedImg.call(o),o.croppedImg.remove(),$(this).hide(),typeof o.options.onAfterRemoveCroppedImg==typeof Function&&o.options.onAfterRemoveCroppedImg.call(o),$.isEmptyObject(o.defaultImg)||o.obj.append(o.defaultImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val("")}),o.form.find('input[type="file"]').change(function(){if(o.options.onBeforeImgUpload&&o.options.onBeforeImgUpload.call(o),o.showLoader(),o.imgUploadControl.hide(),o.options.processInline){var i=new FileReader;i.onload=function(t){var i=new Image;i.src=t.target.result,i.onload=function(){o.imgInitW=o.imgW=i.width,o.imgInitH=o.imgH=i.height,o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=i.src,o.obj.append(''),o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)}},i.readAsDataURL(o.form.find('input[type="file"]')[0].files[0])}else{var n=new FormData(o.form[0]);for(var e in o.options.uploadData)o.options.uploadData.hasOwnProperty(e)&&n.append(e,o.options.uploadData[e]);$.ajax({url:o.options.uploadUrl,data:n,context:t.body,cache:!1,contentType:!1,processData:!1,type:"POST",headers:o.options.headers}).always(function(t){if(response="object"==typeof t?t:jQuery.parseJSON(t),"success"==response.status){o.imgInitW=o.imgW=response.width,o.imgInitH=o.imgH=response.height,o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=response.url;var i=$('');o.obj.append(i),i.load(function(){o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)})}"error"==response.status&&(o.options.onError&&o.options.onError.call(o,response.message),o.hideLoader(),setTimeout(function(){o.reset()},2e3))})}})},loadExistingImage:function(){var o=this;if($.isEmptyObject(o.croppedImg)){o.options.onBeforeImgUpload&&o.options.onBeforeImgUpload.call(o),o.showLoader(),o.options.modal&&o.createModal(),$.isEmptyObject(o.croppedImg)||o.croppedImg.remove(),o.imgUrl=o.options.loadPicture;var t=$('');o.obj.append(t),t.load(function(){o.imgInitW=o.imgW=this.width,o.imgInitH=o.imgH=this.height,o.initCropper(),o.hideLoader(),o.options.onAfterImgUpload&&o.options.onAfterImgUpload.call(o)})}else o.cropControlRemoveCroppedImage.on("click",function(){o.croppedImg.remove(),$(this).hide(),$.isEmptyObject(o.defaultImg)||o.obj.append(o.defaultImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(""),o.croppedImg="",o.reset()})},createModal:function(){var o=this,t=o.windowH/2-o.objH/2,i='
';$("body").append(i),o.modal=$("#croppicModal"),o.obj=$("#croppicModalObj")},destroyModal:function(){var o=this;o.obj=o.outputDiv,o.modal.remove()},initCropper:function(){var o=this;o.img=o.obj.find("img"),o.img.wrap('
'),o.createCropControls(),o.options.imgEyecandy&&o.createEyecandy(),o.initDrag(),o.initialScaleImg()},createEyecandy:function(){var o=this;o.imgEyecandy=o.img.clone(),o.imgEyecandy.css({"z-index":"0",opacity:o.options.imgEyecandyOpacity}).appendTo(o.obj)},destroyEyecandy:function(){var o=this;o.imgEyecandy.remove()},initialScaleImg:function(){var o=this;o.zoom(-o.imgInitW),o.zoom(40),o.options.enableMousescroll&&o.img.on("mousewheel",function(t){t.preventDefault(),o.zoom(o.options.zoomFactor*t.deltaY)}),o.img.css({left:-(o.imgW-o.objW)/2,top:-(o.imgH-o.objH)/2,position:"relative"}),o.options.imgEyecandy&&o.imgEyecandy.css({left:-(o.imgW-o.objW)/2,top:-(o.imgH-o.objH)/2,position:"relative"})},createCropControls:function(){var o,t=this,i="",n='',e='',r="",p="",a="",s='',c='';t.options.doubleZoomControls&&(i='',r=''),t.options.rotateControls&&(p='',a=''),o='
'+i+n+e+r+p+a+s+c+"
",t.obj.append(o),t.cropControlsCrop=t.obj.find(".cropControlsCrop"),t.options.doubleZoomControls&&(t.cropControlZoomMuchIn=t.cropControlsCrop.find(".cropControlZoomMuchIn"),t.cropControlZoomMuchIn.on("click",function(){t.zoom(10*t.options.zoomFactor)}),t.cropControlZoomMuchOut=t.cropControlsCrop.find(".cropControlZoomMuchOut"),t.cropControlZoomMuchOut.on("click",function(){t.zoom(10*-t.options.zoomFactor)})),t.cropControlZoomIn=t.cropControlsCrop.find(".cropControlZoomIn"),t.cropControlZoomIn.on("click",function(){t.zoom(t.options.zoomFactor)}),t.cropControlZoomOut=t.cropControlsCrop.find(".cropControlZoomOut"),t.cropControlZoomOut.on("click",function(){t.zoom(-t.options.zoomFactor)}),t.cropControlZoomIn=t.cropControlsCrop.find(".cropControlRotateLeft"),t.cropControlZoomIn.on("click",function(){t.rotate(-t.options.rotateFactor)}),t.cropControlZoomOut=t.cropControlsCrop.find(".cropControlRotateRight"),t.cropControlZoomOut.on("click",function(){t.rotate(t.options.rotateFactor)}),t.cropControlCrop=t.cropControlsCrop.find(".cropControlCrop"),t.cropControlCrop.on("click",function(){t.crop()}),t.cropControlReset=t.cropControlsCrop.find(".cropControlReset"),t.cropControlReset.on("click",function(){t.reset()})},initDrag:function(){var t=this;t.img.on("mousedown touchstart",function(i){i.preventDefault();var n,e,r=o.navigator.userAgent;r.match(/iPad/i)||r.match(/iPhone/i)||r.match(/android/i)?(n=i.originalEvent.touches[0].pageX,e=i.originalEvent.touches[0].pageY):(n=i.pageX,e=i.pageY);var p=t.img.css("z-index"),a=t.img.outerHeight(),s=t.img.outerWidth(),c=t.img.offset().top+a-e,m=t.img.offset().left+s-n;t.img.css("z-index",1e3).on("mousemove touchmove",function(o){var i,n;if(r.match(/iPad/i)||r.match(/iPhone/i)||r.match(/android/i)?(i=o.originalEvent.touches[0].pageY+c-a,n=o.originalEvent.touches[0].pageX+m-s):(i=o.pageY+c-a,n=o.pageX+m-s),t.img.offset({top:i,left:n}).on("mouseup",function(){$(this).removeClass("draggable").css("z-index",p)}),t.options.imgEyecandy&&t.imgEyecandy.offset({top:i,left:n}),t.objH0&&(t.img.css("top",0),t.options.imgEyecandy&&t.imgEyecandy.css("top",0));var e=-(t.imgH-t.objH);parseInt(t.img.css("top"))e&&(t.img.css("top",e),t.options.imgEyecandy&&t.imgEyecandy.css("top",e))}if(t.objW0&&(t.img.css("left",0),t.options.imgEyecandy&&t.imgEyecandy.css("left",0));var l=-(t.imgW-t.objW);parseInt(t.img.css("left"))l&&(t.img.css("left",l),t.options.imgEyecandy&&t.imgEyecandy.css("left",l))}t.options.onImgDrag&&t.options.onImgDrag.call(t)})}).on("mouseup",function(){t.img.off("mousemove")}).on("mouseout",function(){t.img.off("mousemove")})},rotate:function(o){var t=this;t.actualRotation+=o,t.img.css({"-webkit-transform":"rotate("+t.actualRotation+"deg)","-moz-transform":"rotate("+t.actualRotation+"deg)",transform:"rotate("+t.actualRotation+"deg)"}),t.options.imgEyecandy&&t.imgEyecandy.css({"-webkit-transform":"rotate("+t.actualRotation+"deg)","-moz-transform":"rotate("+t.actualRotation+"deg)",transform:"rotate("+t.actualRotation+"deg)"}),"function"==typeof t.options.onImgRotate&&t.options.onImgRotate.call(t)},zoom:function(o){var t=this,i=t.imgW/t.imgH,n=t.imgW+o,e=n/i,r=!0;(nt.imgInitW||e>t.imgInitH)&&(n-t.imgInitW0&&(p=0),a>0&&(a=0);var s=-(e-t.objH);s>p&&(p=s);var c=-(n-t.objW);c>a&&(a=c),r&&t.img.css({top:p,left:a}),t.options.imgEyecandy&&(t.imgEyecandy.width(n),t.imgEyecandy.height(e),r&&t.imgEyecandy.css({top:p,left:a})),t.options.onImgZoom&&t.options.onImgZoom.call(t)},crop:function(){var o=this;o.options.onBeforeImgCrop&&o.options.onBeforeImgCrop.call(o),o.cropControlsCrop.hide(),o.showLoader();var i={imgUrl:o.imgUrl,imgInitW:o.imgInitW,imgInitH:o.imgInitH,imgW:o.imgW,imgH:o.imgH,imgY1:Math.abs(parseInt(o.img.css("top"))),imgX1:Math.abs(parseInt(o.img.css("left"))),cropH:o.objH,cropW:o.objW,rotation:o.actualRotation},n=new FormData;for(var e in i)i.hasOwnProperty(e)&&n.append(e,i[e]);for(var e in o.options.cropData)o.options.cropData.hasOwnProperty(e)&&n.append(e,o.options.cropData[e]);$.ajax({url:o.options.cropUrl,data:n,context:t.body,cache:!1,contentType:!1,processData:!1,type:"POST",headers:o.options.headers}).always(function(t){response="object"==typeof t?t:jQuery.parseJSON(t),"success"==response.status&&(o.options.imgEyecandy&&o.imgEyecandy.hide(),o.destroy(),o.obj.append(''),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(response.url),o.croppedImg=o.obj.find(".croppedImg"),o.init(),o.hideLoader()),"error"==response.status&&(o.options.onError&&o.options.onError.call(o,response.message),o.hideLoader(),setTimeout(function(){o.reset()},2e3)),o.options.onAfterImgCrop&&o.options.onAfterImgCrop.call(o)})},showLoader:function(){var o=this;o.obj.append(o.options.loaderHtml),o.loader=o.obj.find(".loader")},hideLoader:function(){var o=this;o.loader.remove()},reset:function(){var o=this;o.destroy(),o.init(),$.isEmptyObject(o.croppedImg)||(o.obj.append(o.croppedImg),""!==o.options.outputUrlId&&$("#"+o.options.outputUrlId).val(o.croppedImg.attr("url"))),"function"==typeof o.options.onReset&&o.options.onReset.call(o)},destroy:function(){var o=this;o.options.modal&&!$.isEmptyObject(o.modal)&&o.destroyModal(),o.options.imgEyecandy&&!$.isEmptyObject(o.imgEyecandy)&&o.destroyEyecandy(),$.isEmptyObject(o.cropControlsUpload)||o.cropControlsUpload.remove(),$.isEmptyObject(o.cropControlsCrop)||o.cropControlsCrop.remove(),$.isEmptyObject(o.loader)||o.loader.remove(),$.isEmptyObject(o.form)||o.form.remove(),o.obj.html("")}}}(window,document); \ No newline at end of file