WordPress TinyMCE Template でテンプレート挿入時の並び順が作成順(id順)で使いづらかったのでタイトル順になるように改造してみた。
- tinymce-templates/js/tinymce-templates.js を開き、get_template_list()を探す。
- tinymceTemplates.set_content(); の前に以下のソートを追加
$( "#tinymce-templates-list" ).html( $( "#tinymce-templates-list option" ) .sort(function( a, b ) { return ( a.text == b.text ? 0 : ( a.text < b.text ? -1 : 1 ) ) }));- このソートでは初期選択アイテムが最後尾となるため、気になるなるのであれば以下のコードで先頭を選択状態にする
$( "#tinymce-templates-list option:first" ).prop( 'selected', true );
変更後の関数はこんな感じ。get_template_list: function() { var args = $.extend({}, tinymce_templates_list_args); $.ajax({ url: tinymce_templates_list_uri, async: true, type: 'GET', dataType: 'json', data: args }).done(function(data){ $.each(data, function(key, tpl){ var option = $(''); $(option).attr('value', key); $(option).text(tpl.title); $('#tinymce-templates-list').append(option); }); $( "#tinymce-templates-list" ).html( $( "#tinymce-templates-list option" ). sort(function( a, b ) { return ( a.text == b.text ? 0 : ( a.text < b.text ? -1 : 1 ) ) })); $( "#tinymce-templates-list option:first" ).prop( 'selected', true ); tinymceTemplates.set_content(); }); },
投稿者 NMVL : 2017年4月 9日 02:15