(function(){ if (typeof window.customToolbarElements === 'undefined') { window.customToolbarElements = []; } window.customToolbarElements.push({ identifier: 'content-headings', button: { title : 'Headings', label : '', class : 'heading-icon', }, processAction: function(editor) { if ($('#heading-dropdown').is(':visible')) { $('#heading-dropdown').remove(); return; } var dropdown = '
'; var $headingDropdown = $('.heading-icon'); var $dropdown = $(dropdown) .insertAfter($headingDropdown); $dropdown.on('click', 'a', function () { $('#heading-dropdown').remove(); var text = $(this).data('heading'); //Add text to the editor var cm = editor.editor, pos = cm.getDoc().getCursor(true), posend = cm.getDoc().getCursor(false); for (var i=pos.line; i<(posend.line+1);i++) { cm.replaceRange(text+cm.getLine(i), { line: i, ch: 0 }, { line: i, ch: cm.getLine(i).length }); } cm.setCursor({ line: posend.line, ch: cm.getLine(posend.line).length }); cm.focus(); }); } }); })();