Last active
September 16, 2015 13:34
-
-
Save kurozumi/30dc47403137364563c4 to your computer and use it in GitHub Desktop.
【ワードプレス】テーマフォルダのパスを取得するショートコード作成とビジュアルリッチエディタでショートコードを展開するプラグイン(外部エディタープラグイン)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
tinymce.create('tinymce.plugins.tpl_url_conv', { | |
getInfo: function () { | |
return { | |
longname: 'Template Directory ShortCode Convert', | |
version: "1.0" | |
}; | |
}, | |
init: function (ed, url) { | |
var t = this; | |
// ビジュアルリッチエディタのときテーマディレクトリのパスに展開 | |
ed.onBeforeSetContent.add(function (ed, o) { | |
o.content = t._to_tpl_url(o.content); | |
}); | |
// コードエディタのときショートコードに戻す | |
ed.onGetContent.add(function (ed, o) { | |
if(o.content) | |
o.content = t._to_shortcode(o.content); | |
}); | |
}, | |
_to_tpl_url: function (co) { | |
return co.replace(/\[template_url\]/g, tpl_url); | |
}, | |
_to_shortcode: function (co) { | |
reg = new RegExp(tpl_url, 'g'); | |
return co.replace(reg, '[template_url]'); | |
} | |
}); | |
tinymce.PluginManager.add('tpl_url_conv', tinymce.plugins.tpl_url_conv); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment