-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathimage-editor.js
More file actions
1 lines (1 loc) · 4.44 KB
/
image-editor.js
File metadata and controls
1 lines (1 loc) · 4.44 KB
1
!function(t){var e={};function i(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=t,i.c=e,i.d=function(t,e,o){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(o,n,function(e){return t[e]}.bind(null,n));return o},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=2)}([function(t,e){t.exports=window.wp.apiFetch},,function(t,e,i){"use strict";i.r(e);var o=i(0),n=i.n(o),r={container:document.getElementById("cloudinary-editor"),mediaPreview:document.getElementById("cloudinary-media-preview"),startControls:document.getElementById("edit-start-wrap"),editStart:document.getElementById("edit-start"),editClose:document.getElementById("edit-close"),editControls:document.getElementById("edit-controls-wrap"),saveButton:document.getElementById("edit-save"),restoreButton:document.getElementById("edit-restore"),config:cldData.editor?cldData.editor:{},editor:null,init:function(){var t=this;this.config.publicId&&(this.show(this.editStart),this.container.style.transition="opacity 0.5s",n.a.use(n.a.createNonceMiddleware(this.config.nonce)),this.editStart.addEventListener("click",(function(){t.open()})),this.editClose.addEventListener("click",(function(){t.close()})),this.saveButton.addEventListener("click",(function(){t.editor.triggerExport()})),this.restoreButton.addEventListener("click",(function(){t.restoreButton.disabled=!0;var e={ID:t.config.assetID};t.restore(e)})),this.restoreMaybe(),this.editor=cloudinary.mediaEditor({appendTo:this.container}),["interactivecropresize","interactivecropmove","flipvertically","fliphorizontally","rotateclockwise","rotatecounterclockwise","aspectratioclick","cropclick"].forEach((function(e){t.editor.on(e,(function(e){t.enableSave()}))})))},disableSave:function(){"image"===this.config.resourceType&&(this.saveButton.disabled=!0)},enableSave:function(){"image"===this.config.resourceType&&(this.saveButton.disabled=!1)},restoreMaybe:function(){this.config.original?this.hide(this.restoreButton):(this.restoreButton.disabled=!1,this.show(this.restoreButton))},openEditor:function(){var t=this;this.mediaPreview.addEventListener("load",(function(){t.mediaPreview.style.opacity=1})),this.updateEditor(),this.editor.on("export",(function(e){var i={ID:t.config.assetID,transformations:e.transformation,imageUrl:e.assets[0].secureUrl};t.saveButton.disabled=!0,t.save(i)})),this.editor.show()},updateEditor:function(){this.editor.update({cloudName:this.config.cloudName,publicIds:[{publicId:this.config.publicId,resourceType:this.config.resourceType}],mode:"inline",image:{transformation:this.config.transformation,steps:["resizeAndCrop"],resizeAndCrop:{toggleAspectRatio:!0},export:{download:!1,quality:["best"],share:!1}}}),this.disableSave()},hide:function(t){t.style.display="none"},show:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"block";t.style.display=e},open:function(){this.hide(this.startControls),this.show(this.editControls,"flex"),this.hide(this.mediaPreview);var t=document.body.offsetHeight-this.container.offsetTop-200;this.show(this.container),this.container.style.height=t+"px",this.openEditor()},close:function(){this.show(this.startControls),this.hide(this.editControls),this.show(this.mediaPreview),this.hide(this.container),this.editor.hide()},save:function(t){var e=this;this.disableSave(),this.container.style.opacity=.5,n()({url:this.config.saveUrl,data:t,method:"POST"}).then((function(t){e.config.publicId=t.publicId,e.config.original=t.original,e.updateEditor(),e.mediaPreview.src=t.previewUrl,e.container.style.opacity=1,e.restoreMaybe()}))},restore:function(t){var e=this;this.container.style.opacity=.5,n()({url:this.config.restoreUrl,data:t,method:"POST"}).then((function(t){e.config.publicId=t.publicId,e.config.original=t.original,e.updateEditor(),e.mediaPreview.src=t.previewUrl,e.container.style.opacity=1,e.restoreMaybe()}))}};window.addEventListener("load",(function(){return r.init()})),e.default=r}]);