(function() { var activate, open_image_editing_dialog, open_image_editing_dialog_options, save_edited_image, setup_edit_btn, setup_image_kit, setup_image_kit_container; activate = function(element) { return setup_edit_btn($(element)); }; setup_edit_btn = function(element) { scrivito.editors._setupButtonContainer(element); if (element.scrivito('content')) { return $(" ").insertBefore(element).click(function(event) { event.preventDefault(); return open_image_editing_dialog(element); }); } }; open_image_editing_dialog = function(element) { var content, dialog; content = $("
"); dialog = scrivito.dialog(content, open_image_editing_dialog_options()); return setup_image_kit_container(element, dialog); }; open_image_editing_dialog_options = function() { var dialog_options; return dialog_options = { color: "dark", confirm: { title: "Confirm", color: "green" }, cancel: { title: "Cancel", color: "lightgrey" } }; }; setup_image_kit = function(image, container) { return new ImglyKit({ renderer: "canvas", assetsUrl: "imgly_sdk", image: image, versionCheck: false, container: container[0], ui: { enabled: true, assetPathResolver: scrivito.editors._imgly_asset_path_resolver } }); }; setup_image_kit_container = function(element, dialog) { return element.scrivito('content').noCacheUrl().then(function(no_cache_url) { var container, image; container = $(".image_kit_start"); image = new Image(); image.crossOrigin = "Anonymous"; image.src = no_cache_url; image.onerror = function() { return $("
\n

We're sorry,

\n

Scrivito can't edit this image in your browser. What now?

\n \n
").appendTo(container); }; return image.onload = function() { var kit; kit = setup_image_kit(image, container); kit.ui.selectOperations({ except: "stickers" }); kit.run(); return dialog.when_closed.then((function(_this) { return function() { return save_edited_image(element, kit); }; })(this)); }; }); }; save_edited_image = function(element, kit) { return kit.render("blob", "image/jpeg").then(function(blob) { scrivito.editors._showButtonContainerProgress(element); return element.scrivito("save", scrivito.upload_binary({ blob: blob, filename: element.scrivito("content").filename })).then(function() { return element.scrivito("reload"); }); }); }; scrivito.editors.image_editor = { can_edit: function(element) { return $(element).is('img[data-scrivito-field-type=binary]'); }, activate: function(element) { return activate(element); } }; scrivito.on('load', function() { return scrivito.define_editor('image', scrivito.editors.image_editor); }); }).call(this);