Make WordPress Core

Ticket #6331: 6331.3.diff

File 6331.3.diff, 3.6 KB (added by miyauchi, 11 years ago)

delete duplicated lines ...

  • src/wp-includes/class-wp-editor.php

     
    243243                                                'wplink',
    244244                                                'wpdialogs',
    245245                                                'wpview',
     246                                                'wpcode',
    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', 'wpcode', '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/wpcode/plugin.js

     
     1/*global tinymce:true */
     2
     3tinymce.PluginManager.add('wpcode', 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: 'wpcode',
     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                                                editor.insertContent('<pre>' + escapeHtml(e.data.wpcode) + '</pre>');
     26                                        });
     27
     28                                        editor.selection.setCursorLocation();
     29                                        editor.nodeChanged();
     30                                }
     31                        });
     32                } else {
     33                        editor.undoManager.transact(function() {
     34                                tinymce.activeEditor.selection.setNode(tinymce.activeEditor.dom.create(
     35                                        'code',
     36                                        {},
     37                                        editor.selection.getContent()
     38                                ));
     39                        });
     40                }
     41        }
     42
     43        function escapeHtml(str) {
     44                var div = document.createElement('div');
     45                div.appendChild(document.createTextNode(str));
     46                return div.innerHTML;
     47        };
     48
     49        editor.addCommand("mceCodeEditor", showDialog);
     50
     51        editor.addButton('wpcode', {
     52                icon: 'code',
     53                tooltip: 'Source code',
     54                onclick: showDialog
     55        });
     56
     57        editor.addMenuItem('wpcode', {
     58                icon: 'code',
     59                text: 'Source code',
     60                context: 'tools',
     61                onclick: showDialog
     62        });
     63});
     64