这个简单的例子将添加一个Quicktag按钮,当它被点击时调用Javascript函数。。。
<?PHP
function _add_my_quicktags(){ ?>
<script type="text/javascript">
QTags.addButton( \'alert\', \'Alert Button\', simple_alert );
function simple_alert() {
alert(\'hello, example callback function\');
}
</script>
<?php
}
add_action(\'admin_print_footer_scripts\', \'_add_my_quicktags\');
?>
更新。。。。正在添加使用传入变量的回调函数。。。
// Add a button called \'abbr\' with a callback function
QTags.addButton( \'abbr\', \'Abbr\', abbr_prompt );
// and this is the callback function
function abbr_prompt(e, c, ed) {
var prmt, t = this;
if ( ed.canvas.selectionStart !== ed.canvas.selectionEnd ) {
// if we have a selection in the editor define out tagStart and tagEnd to wrap around the text
// prompt the user for the abbreviation and return gracefully on a null input
prmt = prompt(\'Enter Abbreviation\');
if ( prmt === null ) return;
t.tagStart = \'<abbr title="\' + prmt + \'">\';
t.tagEnd = \'</abbr>\';
} else if ( ed.openTags ) {
// if we have an open tag, see if it\'s ours
var ret = false, i = 0, t = this;
while ( i < ed.openTags.length ) {
ret = ed.openTags[i] == t.id ? i : false;
i ++;
}
if ( ret === false ) {
// if the open tags don\'t include \'abbr\' prompt for input
prmt = prompt(\'Enter Abbreviation\');
if ( prmt === null ) return;
t.tagStart = \'<abbr title="\' + prmt + \'">\';
t.tagEnd = false;
if ( ! ed.openTags ) {
ed.openTags = [];
}
ed.openTags.push(t.id);
e.value = \'/\' + e.value;
} else {
// otherwise close the \'abbr\' tag
ed.openTags.splice(ret, 1);
t.tagStart = \'</abbr>\';
e.value = t.display;
}
} else {
// last resort, no selection and no open tags
// so prompt for input and just open the tag
prmt = prompt(\'Enter Abbreviation\');
if ( prmt === null ) return;
t.tagStart = \'<abbr title="\' + prmt + \'">\';
t.tagEnd = false;
if ( ! ed.openTags ) {
ed.openTags = [];
}
ed.openTags.push(t.id);
e.value = \'/\' + e.value;
}
// now we\'ve defined all the tagStart, tagEnd and openTags we process it all to the active window
QTags.TagButton.prototype.callback.call(t, e, c, ed);
};