(function() { var ScrivitoAnchor, activate, customOptions, defaultOptions, editorOptions; ScrivitoAnchor = MediumEditor.extensions.anchor.extend({ name: 'scrivito_anchor', proxy: null, contentDefault: '', init: function() { var ref; MediumEditor.extensions.anchor.prototype.init.apply(this, arguments); return this.targetCheckbox = (ref = this.getEditorOption('anchor')) != null ? ref.targetCheckbox : void 0; }, handleClick: function(event) { var linkElement, selectedParent, selectionRange; event.preventDefault(); event.stopPropagation(); if (!this.isDisplayed()) { selectionRange = MediumEditor.selection.getSelectionRange(this.document); selectedParent = MediumEditor.selection.getSelectedParentElement(selectionRange); linkElement = MediumEditor.util.getClosestTag(selectedParent, 'a'); this.showForm({ value: $(linkElement).attr('href') || null, target: $(linkElement).attr('target') || null }); } return false; }, getTemplate: function() { var targetCheckboxTemplate; targetCheckboxTemplate = ""; if (this.targetCheckbox) { targetCheckboxTemplate = "
\n \n
"; } return ("\n\n\n\n" + targetCheckboxTemplate).replace(/\n\s*/g, ""); }, attachFormEvents: function(form) { var input; MediumEditor.extensions.anchor.prototype.attachFormEvents.call(this, form); form = $(form); input = form.find('.medium-editor-toolbar-input'); return form.find('.medium-editor-toolbar-browse').on('click', (function(_this) { return function() { var cmsField, id, selection; selection = (id = _this.proxy.idFromPath(input.val())) ? [id] : []; cmsField = $(_this.base.origElements); scrivito.content_browser.open({ filter: cmsField.data('scrivitoEditorsFilter'), filter_context: cmsField.data('scrivitoEditorsFilterContext'), selection: selection, selection_mode: 'single' }).always(function() { return input.focus(); }).done(function(selection) { if (selection.length) { return input.val(_this.proxy.pathForId(selection[0])); } else { return input.val(''); } }); return false; }; })(this)); }, completeFormSave: function(opts) { this.base.restoreSelection(); if (opts.value) { this.execAction(this.action, opts); } else { this.execAction('unlink'); } return this.base.checkSelection(); } }); editorOptions = function() { return $.extend({}, defaultOptions(), customOptions()); }; defaultOptions = function() { return { anchorPreview: false, extensions: { scrivito_anchor: new ScrivitoAnchor, imageDragging: {} }, placeholder: false, toolbar: { buttons: ['bold', 'italic', 'scrivito_anchor', 'h2', 'h3', 'unorderedlist', 'orderedlist'], standardizeSelectionStart: true } }; }; customOptions = function() { var ref, ref1, ref2, ref3; if (typeof (typeof scrivito !== "undefined" && scrivito !== null ? (ref = scrivito.editors) != null ? (ref1 = ref.medium_editor) != null ? ref1.options : void 0 : void 0 : void 0) === 'function') { return scrivito.editors.medium_editor.options(); } else { return (typeof scrivito !== "undefined" && scrivito !== null ? (ref2 = scrivito.editors) != null ? (ref3 = ref2.medium_editor) != null ? ref3.options : void 0 : void 0 : void 0) || {}; } }; activate = function(proxy) { var cmsField, mediumEditor, scrivitoAnchorExtension; cmsField = proxy.jQueryElement(); scrivito.editors.applyPlaceholder(cmsField); mediumEditor = new MediumEditor(cmsField, editorOptions()).subscribe('editableInput', function() { return proxy.save(cmsField.html()); }); scrivitoAnchorExtension = mediumEditor.getExtensionByName('scrivito_anchor'); return scrivitoAnchorExtension != null ? scrivitoAnchorExtension.proxy = proxy : void 0; }; scrivito.editors.medium_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=html]'); }, activate: function(element) { return activate(new scrivito.editors.DomContentProxy(element)); }, default_options: defaultOptions, options: function() { return {}; }, _activateWithProxy: function(proxy) { return activate(proxy); } }; scrivito.on('load', function() { return scrivito.define_editor('medium', scrivito.editors.medium_editor); }); }).call(this);