我正在使用 tinymce 按钮来插入短代码。它基于一个短代码列表,每个都打开一个带有该短代码选项的弹出窗口,来自 js 结构。
在一个非常简化的版本中,代码是:
(function() {
tinymce.create('tinymce.plugins.sympleShortcodeMce', {
init : function(ed, url){
//do nothing
},
createControl : function(btn, e) {
if ( btn == "symple_shortcodes_button" ) {
var a = this;
var btn = e.createSplitButton('symple_button', {
title: "Insert Shortcodes",
image: "shortcode-button.png",
icons: false,
});
btn.onRenderMenu.add(function (c, b) {
a.render( b, "Caixa", "caixa" );
});
return btn;
}
return null;
},
render : function(ed, title, id) {
ed.add({
title: title,
onclick: function () {
// Box
if(id == "caixa") {
H = jQuery(window).height()* 0.9,
W = ( 720 < width ) ? 720 : width;
W = W - 120;
H = H - 84;
tb_show( 'Insert Box - Shortcode', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=mycaixa-form' );
}
return false;
}
})
}
});
tinymce.PluginManager.add("symple_shortcodes", tinymce.plugins.sympleShortcodeMce);
// BOXES
jQuery(function(){
var formcaixa = jQuery('<div id="mycaixa-form"><table id="mycaixa-table" class="form-table">\
<tr>\
<th><label for="mycaixa-icone">Ícone</label></th>\
<td>\
<div class="nochecked"><input type="radio" name="icone" value="meh"><i class="icon-meh"></i></div>\
<div class="nochecked"><input type="radio" name="icone" value="smile"><i class="icon-smile"></i></div>\
<br />\
<small>Box icon</small></td>\
</tr><br />\
</table>\
<p class="submit">\
<input type="button" id="mycaixa-submit" class="button-primary" value="Create Box" name="submit" />\
</p>\
</div>');
var tablecaixa = formcaixa.find('table');
formcaixa.appendTo('body').hide();
jQuery('input[type="radio"]').on('change', function() {
vals = jQuery('input[type="radio"]:checked').map(function() {
return this.value;
}).get();
console.log(vals);
jQuery('#mycaixa-icone').val(vals);
}).change();
// handles the click event of the submit button
formcaixa.find('#mycaixa-submit').click(function(){
// defines the options and their default values
var options = {
'icone' : ''
};
if (tinyMCE.activeEditor.selection.getContent() == "") {
contentcaixa = "INSIRA CONTEÚDO"; }
else {contentcaixa = tinyMCE.activeEditor.selection.getContent();}
var shortcodecaixa = '[caixa';
for(var index in options) {
var value = tablecaixa.find('#mycaixa-' + index).val();
// attaches the attribute to the shortcode only if it's different from the default value
if ( value !== options[index] ) {
shortcodecaixa += ' ' + index + '="' + value + '"';
} }
shortcodecaixa += ']'+contentcaixa+'[/caixa]';
// inserts the shortcode into the active editor
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcodecaixa);
// closes Thickbox
tb_remove(); }) })
/* END FORMS */
})();
所以,我想做的是使用复选框中的值来设置输入文本的值。该值被接收var value = tablecaixa.find('#mycaixa-' + index).val();
并用于创建简码。
但是当我更改复选框时,输入文本的值会发生变化,但是会随着值一起插入“2,public”。因此,我得到的不是“微笑”或“meh”值,而是“2,public,smile”或“2,public,meh”。
知道这是什么吗?