(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._setup_binary_button_container(element, 'scrivito-editor-image-button-container'); 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) { var container, fallbackUrl, image, url; container = $(".image_kit_start"); image = new Image(); url = element.scrivito("content").url; image.crossOrigin = "Anonymous"; image.src = url; fallbackUrl = url; if (url.indexOf("?") < 0) { fallbackUrl = url + "?=" + new Date().getTime(); } else { fallbackUrl = url + "&=" + new Date().getTime(); } image.onerror = function() { if (image.src === fallbackUrl) { return $("
\n

We're sorry,

\n

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

\n \n
").appendTo(container); } else { console.info("Scrivito detected a probable CORS browser cache mismatch, trying uncached load"); return image.src = fallbackUrl; } }; 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) { 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);