mce按钮代码示例
(function() {
var each = tinymce.each;
tinymce.PluginManager.requireLangPack(\'grid\');
tinymce.create(\'tinymce.plugins.FoundationGridPlugin\', {
init : function(ed, url) {
var t = this; t.editor = ed;
imageUrl = url + \'/../images/grid.png\';
},
createControl : function(n, cm) {
var t = this, c, ed = t.editor;
if (n == \'grid\') {
c = cm.createButton(n, {
title : \'grid.title\',
scope : t,
image:imageUrl,
onclick : function() {
ed.execCommand("mceShowGridContainer", false, false);
}
});
return c;
}
},
execCommand: function(cmd, ui, type) {
var ed = tinyMCE.activeEditor;
var url = this.url;
switch (cmd) {
case "mceShowGridContainer":
jQuery.post(ajaxurl, {action:\'grid_action_ajax\'}, function(html){
// some code here
});
break;
}
},
getInfo : function() {
return {
longname : \'Foundation Grid Generator\',
author : \'Oleg Butuzov;\',
authorurl: \'http://made.com.ua\',
infourl : \'http://made.com.ua\',
version : \'2.0\'
};
}
});
tinymce.PluginManager.add(\'grid\', tinymce.plugins.FoundationGridPlugin);
})();
这是您实际需要的代码。。。
onclick : function() {
ed.execCommand("mceShowGridContainer", false, false);
}
其中运行
case "mceShowGridContainer":
jQuery.post(ajaxurl, {action:\'wpse73257_grid_action_ajax\'}, function(html){
// some code here
});
break;
现在,您只需添加将与脚本交互的ajax\\u操作
add_action(\'wp_ajax_wpse73257_grid_action_ajax\', \'wpse73257_grid_action_ajax\');
function wpse73257_grid_action_ajax(){
//do something and show something
exit;
}