(function() { var ScrivitoAnchor, activate, editorOptions; ScrivitoAnchor = MediumEditor.extensions.anchor.extend({ name: 'scrivito_anchor', contentDefault: '', handleClick: function(event) { var firstTextElement, linkElement, linkValue, selectedParent, selectionRange; if (!this.isDisplayed()) { selectionRange = MediumEditor.selection.getSelectionRange(this.document); selectedParent = MediumEditor.selection.getSelectedParentElement(selectionRange); firstTextElement = MediumEditor.util.getFirstTextNode(selectedParent); linkElement = MediumEditor.util.getClosestTag(firstTextElement, 'a'); linkValue = $(linkElement).attr('href'); this.showForm(linkValue); } return false; }, getTemplate: function() { return "" + ("") + "" + ""; }, 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, matches, selection; matches = input.val().match(/\b([a-f0-9]{16})\b/); selection = matches != null ? [matches[1]] : []; 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) { return input.val(selection); }); return false; }; })(this)); }, completeFormSave: function(opts) { this.base.restoreSelection(); if (opts.url) { this.execAction(this.action, opts); } else { this.execAction('unlink'); } return this.base.checkSelection(); } }); editorOptions = function(toolbarOptions) { var options; options = { anchorPreview: false, extensions: { scrivito_anchor: new ScrivitoAnchor }, toolbar: { buttons: ['h1', 'h2', 'h3', 'bold', 'italic', 'scrivito_anchor', 'underline', 'orderedlist', 'unorderedlist', 'indent', 'outdent', 'justifyLeft', 'justifyCenter', 'justifyFull'] } }; if (toolbarOptions) { options.toolbar = toolbarOptions; } options.toolbar.standardizeSelectionStart = true; return options; }; activate = function(element) { var cmsField; cmsField = $(element); return new MediumEditor(cmsField, editorOptions(cmsField.data('medium-editor-toolbar'))).subscribe('editableInput', function() { return cmsField.scrivito('save', cmsField.html()); }); }; scrivito.editors.medium_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=html]'); }, activate: function(element) { return activate(element); } }; scrivito.on('load', function() { return scrivito.define_editor('medium', scrivito.editors.medium_editor); }); }).call(this);