medium-editor-multi-placeholders-plugin
Version:
A plugin for adding multiple placeholders in MediumEditor
1 lines • 1.24 kB
JavaScript
var MediumEditorMultiPlaceholders=MediumEditor.Extension.extend({name:"multi_placeholder",init:function(){this.placeholderElements=[],this.initPlaceholders(this.placeholders,this.placeholderElements),this.watchChanges()},initPlaceholders:function(a,b){this.getEditorElements().forEach(function(a){this.placeholders.map(function(c){var d=document.createElement(c.tag);d.appendChild(document.createElement("br")),d.setAttribute("data-placeholder",c.text),b.push(d),a.appendChild(d),this.updatePlaceholder(d)},this)},this)},destroy:function(){this.getEditorElements().forEach(function(a){a.querySelectorAll("[data-placeholder]").map(function(a){a.removeAttribute("data-placeholder")},this)},this)},showPlaceholder:function(a){a&&a.classList.add("medium-editor-placeholder")},hidePlaceholder:function(a){a&&a.classList.remove("medium-editor-placeholder")},updatePlaceholder:function(a){return""===a.textContent?this.showPlaceholder(a):void this.hidePlaceholder(a)},updateAllPlaceholders:function(){this.placeholderElements.map(function(a){this.updatePlaceholder(a)},this)},watchChanges:function(){this.subscribe("editableInput",this.updateAllPlaceholders.bind(this)),this.subscribe("externalInteraction",this.updateAllPlaceholders.bind(this))}});