1
|
|
|
jQuery(function(){"use strict";var e=jQuery("#image"),r=jQuery("#x"),o=jQuery("#y"),t=jQuery("#height"),a=jQuery("#width"),i={viewMode:1,dragMode:"move",autoCropArea:1,restore:!1,highlight:!1,cropBoxMovable:!1,cropBoxResizable:!1,aspectRatio:1,preview:".img-preview",crop:function(e){r.val(Math.round(e.x)),o.val(Math.round(e.y)),t.val(Math.round(e.height)),a.val(Math.round(e.width)),jQuery("#inputImage").val()||(jQuery(".btn-group button").attr("disabled",!0),jQuery(".cropper-view-box").hide(),jQuery(".cropper-wrap-box").hide())}};e.cropper(i),jQuery(".docs-buttons").on("click","[data-method]",function(){var r,o,t=jQuery(this),a=t.data();if(!t.prop("disabled")&&!t.hasClass("disabled")){if(e.data("cropper")&&a.method){if(void 0!==(a=jQuery.extend({},a)).target&&(r=jQuery(a.target),void 0===a.option))try{a.option=JSON.parse(r.val())}catch(e){console.log(e.message)}if(o=e.cropper(a.method,a.option,a.secondOption),$.isPlainObject(o)&&r)try{r.val(JSON.stringify(o))}catch(e){console.log(e.message)}}return!1}}),jQuery(document.body).on("keydown",function(r){if(e.data("cropper")&&!(this.scrollTop>300))switch(r.which){case 37:r.preventDefault(),e.cropper("move",-1,0);break;case 38:r.preventDefault(),e.cropper("move",0,-1);break;case 39:r.preventDefault(),e.cropper("move",1,0);break;case 40:r.preventDefault(),e.cropper("move",0,1)}});var p,c=jQuery("#inputImage"),n=window.URL||window.webkitURL;n?c.change(function(){var r,o=this.files;e.data("cropper")&&(o&&o.length&&(r=o[0],/^image\/\w+$/.test(r.type)?(p=n.createObjectURL(r),e.one("built.cropper",function(){n.revokeObjectURL(p)}).cropper("reset").cropper("replace",p)):window.alert("Please choose an image file.")),jQuery(".btn-group button").removeAttr("disabled"))}):c.prop("disabled",!0).parent().addClass("disabled")}); |