(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;
},
showForm: function(opts) {
MediumEditor.extensions.anchor.prototype.showForm.call(this, opts);
return this.updateRelUi(opts);
},
handleClick: function(event) {
var href, linkElement, rel, selectedParent, selectionRange, target;
event.preventDefault();
event.stopPropagation();
$('.scrivito_medium_link_collapse').removeClass('show');
if (!this.isDisplayed()) {
selectionRange = MediumEditor.selection.getSelectionRange(this.document);
selectedParent = MediumEditor.selection.getSelectedParentElement(selectionRange);
linkElement = MediumEditor.util.getClosestTag(selectedParent, 'a');
href = target = rel = null;
if (linkElement) {
linkElement = $(linkElement);
href = linkElement.attr('href') || null;
target = linkElement.attr('target') || null;
rel = linkElement.attr('rel') || null;
}
this.showForm({
value: href,
target: target,
rel: rel
});
}
return false;
},
getTemplate: function() {
var classTargetCheckboxNA, targetCheckboxTemplate;
targetCheckboxTemplate = "";
classTargetCheckboxNA = "scrivito_target_checkbox_not_available";
if (this.targetCheckbox) {
targetCheckboxTemplate = "
\n \n
";
classTargetCheckboxNA = "";
}
return ("\n\n\n " + targetCheckboxTemplate + "\n \n Save\n \n
\n\n
\n
Rel attribute value
\n
\n Search engines use a link's rel attribute to determine how to handle the linked document or resource.\n
\n
\n - noindex
\n - nofollow
\n - noarchive
\n - nosnippet
\n - noopener
\n - noreferrer
\n - notranslate
\n
\n
\n
").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');
form.find('[data-scrivito-rel]').on('click', (function(_this) {
return function(event) {
return _this.onRelSelectionButtonClick(event);
};
})(this));
form.find('.scrivito_icon_gear').on('click', (function(_this) {
return function() {
return _this.onToggleRelPanelButtonClick(form);
};
})(this));
return form.find('.medium-editor-toolbar-browse').on('click', (function(_this) {
return function() {
return _this.onContentBrowserButtonClick(input);
};
})(this));
},
completeFormSave: function(opts) {
this.base.restoreSelection();
if (opts.value) {
this.execAction(this.action, opts);
this.updateRelAttribute(opts);
} else {
this.execAction('unlink');
}
return this.base.checkSelection();
},
getFormOpts: function() {
var opts;
opts = MediumEditor.extensions.anchor.prototype.getFormOpts.call(this);
opts.rel = this.selectedRelValues();
return opts;
},
relButtons: function() {
return $(this.getForm()).find('.scrivito_enum_attribute.scrivito_multi [data-scrivito-rel]');
},
selectedRelValues: function() {
return this.relButtons().filter('.scrivito_enum_attribute_active').toArray().map(function(button) {
return button.attributes['data-scrivito-rel'].value;
}).join(' ');
},
updateRelIndicator: function() {
var selectedClass, toggleRelPanelButton;
toggleRelPanelButton = $(this.getForm().querySelector('.scrivito_icon_gear'));
selectedClass = 'scrivito_active_rel_selected';
if (this.relButtons().hasClass('scrivito_enum_attribute_active')) {
return toggleRelPanelButton.addClass(selectedClass);
} else {
return toggleRelPanelButton.removeClass(selectedClass);
}
},
updateRelAttribute: function(opts) {
var elem, linkElement, selectedParent, selectionRange;
selectionRange = MediumEditor.selection.getSelectionRange(this.document);
selectedParent = MediumEditor.selection.getSelectedParentElement(selectionRange);
linkElement = $(MediumEditor.util.getClosestTag(selectedParent, 'a'));
if (opts.rel) {
linkElement.attr('rel', opts.rel);
} else {
linkElement.removeAttr('rel');
}
elem = this.getEditorElements()[0];
return this.base.trigger('editableInput', {}, elem);
},
updateRelUi: function(opts) {
var ref, rel;
rel = (ref = opts.rel) != null ? ref.split(/\s+/) : void 0;
this.relButtons().each(function(_, button) {
if (rel && rel.indexOf(button.getAttribute('data-scrivito-rel')) !== -1) {
return button.className = 'scrivito_enum_attribute_active';
} else {
return button.className = '';
}
});
return this.updateRelIndicator();
},
onToggleRelPanelButtonClick: function(form) {
return $(form.find('.scrivito_medium_link_collapse')).toggleClass('show');
},
onRelSelectionButtonClick: function(event) {
var relButton;
relButton = $(event.target);
relButton.toggleClass('scrivito_enum_attribute_active');
return this.updateRelIndicator();
},
onContentBrowserButtonClick: function(input) {
var cmsField, id, selection;
selection = (id = this.proxy.idFromPath(input.val())) ? [id] : [];
cmsField = $(this.base.origElements);
scrivito.content_browser.open({
filters: cmsField.data('scrivitoEditorsFilter'),
filter_context: cmsField.data('scrivitoEditorsFilterContext'),
selection: selection,
selection_mode: 'single'
}).always((function(_this) {
return function() {
return input.focus();
};
})(this)).done((function(_this) {
return function(selection) {
if (selection.length) {
return input.val(_this.proxy.pathForId(selection[0]));
} else {
return input.val('');
}
};
})(this));
return false;
}
});
editorOptions = function() {
return $.extend({}, defaultOptions(), customOptions());
};
defaultOptions = function() {
return {
anchor: {
targetCheckbox: true
},
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);