Make WordPress Core

Ticket #6331: 6331.diff

File 6331.diff, 4.0 KB (added by miyauchi, 11 years ago)
  • src/wp-includes/class-wp-editor.php

     
    243243                                                'wplink',
    244244                                                'wpdialogs',
    245245                                                'wpview',
     246                        'code',
    246247                                        ) ) );
    247248
    248249                                        if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
     
    397398                                $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 );
    398399                                $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
    399400                        } else {
    400                                 $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);
     401                                $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'code', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
    401402                                $mce_buttons_2 = apply_filters('mce_buttons_2', array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id);
    402403                                $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
    403404                                $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
  • src/wp-includes/js/tinymce/plugins/code/plugin.js

     
     1/*global tinymce:true */
     2
     3tinymce.PluginManager.add('code', function(editor) {
     4        function showDialog() {
     5                if (editor.selection.isCollapsed()) {
     6                        editor.windowManager.open({
     7                                title: "Source code",
     8                                body: {
     9                                        type: 'textbox',
     10                                        name: 'code',
     11                                        multiline: true,
     12                                        minWidth: editor.getParam("code_dialog_width", 600),
     13                                        minHeight: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)),
     14                                        value: "",
     15                                        spellcheck: false,
     16                                        style: 'direction: ltr; text-align: left'
     17                                },
     18                                onSubmit: function(e) {
     19                                        // We get a lovely "Wrong document" error in IE 11 if we
     20                                        // don't move the focus to the editor before creating an undo
     21                                        // transation since it tries to make a bookmark for the current selection
     22                                        editor.focus();
     23
     24                                        editor.undoManager.transact(function() {
     25                                                var obj = document.createElement('pre');
     26                                                if (typeof obj.textContent != 'undefined') {
     27                                                        obj.textContent = e.data.code;
     28                                                } else {
     29                                                        obj.innerText = e.data.code;
     30                                                }
     31                                                editor.insertContent('<pre>' + escapeHtml(e.data.code) + '</pre>');
     32                                        });
     33
     34                                        editor.selection.setCursorLocation();
     35                                        editor.nodeChanged();
     36                                }
     37                        });
     38                } else {
     39                        editor.undoManager.transact(function() {
     40                                tinymce.activeEditor.selection.setNode(tinymce.activeEditor.dom.create(
     41                                        'code',
     42                                        {},
     43                                        editor.selection.getContent()
     44                                ));
     45                        });
     46                }
     47        }
     48
     49        function escapeHtml(str) {
     50                var div = document.createElement('div');
     51                div.appendChild(document.createTextNode(str));
     52                return div.innerHTML;
     53        };
     54
     55        editor.addCommand("mceCodeEditor", showDialog);
     56
     57        editor.addButton('code', {
     58                icon: 'code',
     59                tooltip: 'Source code',
     60                onclick: showDialog
     61        });
     62
     63        editor.addMenuItem('code', {
     64                icon: 'code',
     65                text: 'Source code',
     66                context: 'tools',
     67                onclick: showDialog
     68        });
     69});