4 * Some code is based on the Heading plugin by Andrey G and ggoodd.
5 * Base code stolen from Bit Santos blockquote plugin.
7 * @author Blake Watters
8 * @copyright Copyright © 2006, Blake Watters, All rights reserved.
11 tinyMCE.importPluginLanguagePack('codeblock', 'en');
12 var TinyMCE_CodeblockPlugin = {
14 getInfo : function() {
16 longname : 'Codeblock plugin',
17 author : 'Blake Watters',
18 authorurl : 'http://thatswhatimtalkingabout.org/',
19 infourl : 'mailto:blake@near-time.com',
24 initInstance : function(inst) {
25 inst.addShortcut('alt', '|', 'lang_codeblock_desc', 'mceCodeblock', false, 1);
28 getControlHTML : function(cn) {
30 case "codeblock": return tinyMCE.getButtonHTML(cn, 'lang_codeblock_desc', '{$pluginurl}/images/code.gif', 'mceCodeblock', false, 1);
37 execCommand : function(editor_id, element, command, user_interface, value) {
39 case "mceCodeblock": {
41 var currentNode = tinyMCE.selectedElement;
43 // alert("Selected node: " + currentNode.nodeName.toLowerCase());
46 while(n.nodeName.toLowerCase() != 'body') {
47 if(n.nodeName.toLowerCase() == 'pre') {
53 if(n.nodeName.toLowerCase() != 'body') {
54 if(currentNode == n) {
55 //alert("I am a codeblock.");
56 onlyChild = (currentNode.childNodes.length == 1);
58 tinyMCE.execInstanceCommand(editor_id, 'mceRemoveNode', false);
61 tinyMCE.execInstanceCommand(editor_id, 'FormatBlock', false, "<pre>");
62 tinyMCE.execInstanceCommand(editor_id, 'FormatBlock', false, "<code>");
65 //alert("My parent is a codeblock.");
68 var parent = codeblock.parentNode;
70 for(var i = 0; i < codeblock.childNodes.length; i++) {
71 // alert("Child #" + i + ": " + codeblock.childNodes[i].nodeName);
72 parent.insertBefore(codeblock.childNodes[i].cloneNode(true), codeblock);
74 parent.removeChild(codeblock);
77 tinyMCE.execInstanceCommand(editor_id, 'FormatBlock', false, "<code>");
78 tinyMCE.execInstanceCommand(editor_id, 'FormatBlock', false, "<pre>");
88 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
92 tinyMCE.switchClass(editor_id + '_codeblock', tinyMCE.getParentElement(node, "pre") ? 'mceButtonSelected' : 'mceButtonNormal');
98 tinyMCE.addPlugin("codeblock", TinyMCE_CodeblockPlugin);