3.12. 2 editor.js のカスタマイズ

 wp-admin/js/editor.js をコピーして別名で保存してから改造します。改造する場所をコードに示します。このコードは、WordPress バージョン 4.3.1 を元にしています。

コード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function SwitchEditors() {
    ----- (途中省略) -----
    function switchEditor( id, mode ) {
        ----- (途中省略) -----
        if ( 'tmce' === mode || 'tinymce' === mode ) {
            if ( editor && ! editor.isHidden() ) {
// HK EDITOR CUSTOMIZE
                hk_editor_tmce2tmce( editor );
                return false;
            }
            if ( typeof( window.QTags ) !== 'undefined' ) {
                window.QTags.closeAllTags( id );
            }
            editorHeight = parseInt( textarea.style.height, 10 ) || 0;
// HK EDITOR CUSTOMIZE
            textarea.value = hk_editor_html2tmce( textarea.value );
            if ( editor ) {
                editor.show();
                ----- (途中省略) -----
            } else {
                tinymce.init( window.tinyMCEPreInit.mceInit[id] );
            }
            ----- (途中省略) -----
        } else if ( 'html' === mode ) {
            ----- (途中省略) -----
            if ( editor ) {
                ----- (途中省略) -----
                editor.hide();
// HK EDITOR CUSTOMIZE
                textarea.value = hk_editor_tmce2html( textarea.value );
            } else {
                ----- (途中省略) -----
            }
            ----- (途中省略) -----
        }
    }

// HK EDITOR CUSTOMIZE - BEGIN -
    function hk_editor_tmce2tmce( editor ) {
        ----- (別途説明) -----
    }
    function hk_editor_html2tmce( content ) {
        ----- (別途説明) -----
    }
    function hk_editor_tmce2html( content ) {
        ----- (別途説明) -----
    }
// HK EDITOR CUSTOMIZE - END -

        // Replace paragraphs with double line breaks
        function removep( html ) {
    ----- (以下省略) -----

説明

 7~8行目:ビジュアルモードでビジュアルがクリックされた時の処理
 15~16行目:テキスト→ビジュアル 切り替え時の処理
 29~30行目:ビジュアル→テキスト 切り替え時の処理
 38~48行目:各処理関数

 このプログラムをお使いになる場合は、お使いになる方の自己責任でお願いします。

更新日:2015/11/21
掲載日:2015/11/21