UNPKG

admiraljs

Version:
105 lines (88 loc) 3.45 kB
/** * * @author WSL.RU * @copyright Copyright (c) 2006-2009. All rights reserved. * */ (function(tinymce) { /** * Add a new command to tiny MCE */ function addCommand(ed, url, headingNumber) { var headingTag = 'h' + headingNumber; // tinyMCE.PluginManager.add('stylebuttons', function(editor, url) { // ['pre', 'p', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach(function(name){ ed.addButton(headingTag, { tooltip: "Toggle " + headingTag, text: headingTag.toUpperCase(), onClick: function() { ed.execCommand('mceToggleFormat', false, headingTag); }, onPostRender: function() { var self = this, setup = function() { ed.formatter.formatChanged(headingTag, function(state) { self.active(state); }); }; ed.formatter ? setup() : ed.on('init', setup); } }) // }); // }); // ed.addButton(headingTag, { // title : ed.getLang('advanced.' + headingTag, headingTag) + ' (Ctrl+' + headingNumber + ')', // text:headingTag, // icon:false, // cmd: 'mceHeading' + headingNumber // }); // node = ed.selection.getNode(); // // with(document.getElementById(iframe_id).contentWindow){ // var newElement = document.createTextNode(node.innerHTML); // } // // node.parentNode.replaceChild(newElement, node); // ed.addCommand('mceHeading' + headingNumber, function() { // var ct = ed.getParam("heading_clear_tag", false) ? ed.getParam("heading_clear_tag", "") : ""; // // if (ed.selection.getNode().nodeName.toLowerCase() != headingTag) { // ct = headingTag; // } // ed.execCommand('FormatBlock', false, headingTag); // // var nodeContent=ed.selection.getContent(); // // var newElement = document.createElement(headingTag); // // newElement.innerHTML = node.innerHTML; // // ed.selection.setContent("<"+headingTag+">"+nodeContent+"</"+headingTag+">"); // //node.parentNode.replaceChild(newElement, node); // // ed.execCommand('heading', false, ct) // }); // ed.onNodeChange.add( function(ed, cm, n) { // cm.setActive(headingTag, n.nodeName.toLowerCase() == headingTag); // }); // ed.addButton(headingTag, { // text: 'My button', // stateSelector: headingTag // }); } tinymce.create('tinymce.plugins.heading', { /** * Initialize the plugin */ init : function(ed, url) { for (var headingNumber = 1; headingNumber <= 6; headingNumber++) { addCommand(ed, url, headingNumber); } }, /** * Plugin information */ getInfo : function() { return { longname : 'Heading plugin', author : 'WSL.RU / Andrey G, ggoodd, Merten van Gerven', authorurl : 'http://wsl.ru', infourl : 'mailto:merten.vg@gmail.com', version : '1.4' }; } }); tinymce.PluginManager.add('heading', tinymce.plugins.heading); })(tinymce);