(function() { var activate, closeEditor, defaultOptions, getCurrentContent, getOptions, saveContents, showDeprecationWarningOnce; this.RedactorPlugins || (this.RedactorPlugins = {}); RedactorPlugins.scrivito_editors_close = function() { return { init: function() { var button; button = this.button.addFirst('close', 'Close'); return this.button.addCallback(button, function() { return closeEditor(this); }); } }; }; defaultOptions = { buttons: ['formatting', 'bold', 'italic', 'deleted', 'underline', 'unorderedlist', 'orderedlist', 'table', 'image', 'link', 'html'], buttonSource: true, cleanSpaces: false, cleanOnPaste: false, convertLinks: false, imageUpload: true, linkTooltip: false, paragraphize: false, placeholder: false, plugins: ['scrivito_editors_close', 'scrivito_editors_image_manager', 'scrivito_editors_link_manager', 'table'], replaceDivs: false, tabifier: false, blurCallback: function() { if (this._everHadFocus) { return closeEditor(this); } }, changeCallback: function() { return saveContents(this); }, destroyCallback: function() { return saveContents(this); }, dropdownShowCallback: function() { return saveContents(this); }, focusCallback: function() { if (this._isInitialized) { return this._everHadFocus = true; } }, modalOpenedCallback: function() { return saveContents(this); }, keyupCallback: function(event) { var key; key = event.keyCode || event.which; if (key === 27) { event.stopPropagation(); return closeEditor(this); } else { return saveContents(this); } }, initCallback: function() { var cmsField, content, html, htmlWithSelection; cmsField = $(this.$element); content = cmsField.scrivito('content'); this._initialScrivitoContent = content; this.selection.selectAll(); htmlWithSelection = this.selection.getHtml(); this.selection.removeMarkers(); html = this.selection.getHtml(); if (html !== content) { this.code.set(content); this.selection.selectAll(); html = this.selection.getHtml(); this.focus.setEnd(); } else { this.code.set(htmlWithSelection); this.selection.restore(); } this._initialRedactorContent = html; return this._isInitialized = true; }, startCallback: function() { this._everHadFocus = void 0; this._initialRedactorContent = void 0; this._initialScrivitoContent = void 0; this._isInitialized = void 0; if (document.getSelection().anchorNode) { return this.insert.node(this.selection.getMarker(), false); } } }; closeEditor = function(editor) { var cmsField; cmsField = $(editor.$element); editor.core.destroy(); cmsField.removeClass('scrivito_editors_redactor'); return cmsField.trigger('scrivito_editors:blur'); }; saveContents = function(editor) { var cmsField, content; cmsField = editor.$element; content = getCurrentContent(editor); if (content !== cmsField.scrivito('content')) { return cmsField.scrivito('save', content).done(function() { return cmsField.trigger('scrivito_editors:save'); }); } else { return $.Deferred().resolve(); } }; getCurrentContent = function(editor) { var content; content = editor.code.get(); if (content === editor._initialRedactorContent) { content = editor._initialScrivitoContent; } return content; }; getOptions = function() { return $.extend({}, scrivito.editors.redactor_editor.default_options, scrivito.editors.redactor_editor.options); }; activate = function(element) { var cmsField; cmsField = $(element); cmsField.on('click', function(event) { event.preventDefault(); if (!cmsField.hasClass('scrivito_editors_redactor')) { return cmsField.redactor(getOptions()).addClass('scrivito_editors_redactor'); } }); return showDeprecationWarningOnce(); }; showDeprecationWarningOnce = function() { if (scrivito.editors.redactor_editor.deprecation_warning) { console.warn(scrivito.editors.redactor_editor.deprecation_warning); return delete scrivito.editors.redactor_editor.deprecation_warning; } }; scrivito.editors.redactor_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=html]'); }, activate: function(element) { return activate(element); }, default_options: defaultOptions, deprecation_warning: "The Scrivito Redactor editor is deprecated. See https://scrivito.com/editors for details.\nYou can continue to use Redactor, but there will be no updates in future Scrivito versions.\nScrivito recommends MediumEditor for smooth on-page editing, CodeMirror for HTML source editing.", options: {} }; scrivito.on('load', function() { return scrivito.define_editor('redactor', scrivito.editors.redactor_editor); }); }).call(this);