Index: src/wp-includes/class-wp-editor.php =================================================================== --- src/wp-includes/class-wp-editor.php (revision 27644) +++ src/wp-includes/class-wp-editor.php (working copy) @@ -243,6 +243,7 @@ 'wplink', 'wpdialogs', 'wpview', + 'wpcode', ) ) ); if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) { @@ -397,7 +398,7 @@ $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id ); $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array(); } else { - $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id); + $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'wpcode', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id); $mce_buttons_2 = apply_filters('mce_buttons_2', array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id); $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id); $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id); Index: src/wp-includes/js/tinymce/plugins/wpcode/plugin.js =================================================================== --- src/wp-includes/js/tinymce/plugins/wpcode/plugin.js (revision 0) +++ src/wp-includes/js/tinymce/plugins/wpcode/plugin.js (working copy) @@ -0,0 +1,126 @@ +/*global tinymce:true */ + +tinymce.PluginManager.add('wpcode', function(editor) { + function showDialog() { + if (editor.selection.isCollapsed()) { + editor.windowManager.open({ + title: "Source code", + body: { + type: 'textbox', + name: 'wpcode', + multiline: true, + minWidth: editor.getParam("code_dialog_width", 600), + minHeight: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)), + value: "", + spellcheck: false, + style: 'direction: ltr; text-align: left' + }, + onSubmit: function(e) { + // We get a lovely "Wrong document" error in IE 11 if we + // don't move the focus to the editor before creating an undo + // transation since it tries to make a bookmark for the current selection + editor.focus(); + + editor.undoManager.transact(function() { + editor.insertContent('
' + escapeHtml(e.data.wpcode) + ''); + }); + + editor.selection.setCursorLocation(); + editor.nodeChanged(); + } + }); + } else { + editor.undoManager.transact(function() { + tinymce.activeEditor.selection.setNode(tinymce.activeEditor.dom.create( + 'code', + {}, + editor.selection.getContent() + )); + }); + } + } + + function escapeHtml(str) { + var div = document.createElement('div'); + div.appendChild(document.createTextNode(str)); + return div.innerHTML; + }; + + editor.addCommand("mceCodeEditor", showDialog); + + editor.addButton('wpcode', { + icon: 'code', + tooltip: 'Source code', + onclick: showDialog + }); + + editor.addMenuItem('wpcode', { + icon: 'code', + text: 'Source code', + context: 'tools', + onclick: showDialog + }); +}); +/*global tinymce:true */ + +tinymce.PluginManager.add('wpcode', function(editor) { + function showDialog() { + if (editor.selection.isCollapsed()) { + editor.windowManager.open({ + title: "Source code", + body: { + type: 'textbox', + name: 'wpcode', + multiline: true, + minWidth: editor.getParam("code_dialog_width", 600), + minHeight: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)), + value: "", + spellcheck: false, + style: 'direction: ltr; text-align: left' + }, + onSubmit: function(e) { + // We get a lovely "Wrong document" error in IE 11 if we + // don't move the focus to the editor before creating an undo + // transation since it tries to make a bookmark for the current selection + editor.focus(); + + editor.undoManager.transact(function() { + editor.insertContent('
' + escapeHtml(e.data.wpcode) + ''); + }); + + editor.selection.setCursorLocation(); + editor.nodeChanged(); + } + }); + } else { + editor.undoManager.transact(function() { + tinymce.activeEditor.selection.setNode(tinymce.activeEditor.dom.create( + 'code', + {}, + editor.selection.getContent() + )); + }); + } + } + + function escapeHtml(str) { + var div = document.createElement('div'); + div.appendChild(document.createTextNode(str)); + return div.innerHTML; + }; + + editor.addCommand("mceCodeEditor", showDialog); + + editor.addButton('wpcode', { + icon: 'code', + tooltip: 'Source code', + onclick: showDialog + }); + + editor.addMenuItem('wpcode', { + icon: 'code', + text: 'Source code', + context: 'tools', + onclick: showDialog + }); +}); Property changes on: src/wp-includes/js/tinymce/plugins/wpcode/plugin.js ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property