0

我在 Wordpress 3.8 中使用了列表框 UI 元素,但它在较新的版本 (3.9) 中不起作用。我写了这段 JS 代码来测试它:

(function() {
var ICONS;
var icon = function(id) {
    return '<i class="fa fa-' + id + '"></i>';
}

ICONS = ["rub", "ruble", "rouble", "pagelines", "stack-exchange", "arrow-circle-o-right", "arrow-circle-o-left", "caret-square-o-left", "toggle-left", "dot-circle-o", "wheelchair", "vimeo-square", "try", "adjust", "anchor", "archive", "arrows", "arrows-h", "arrows-v", "asterisk", "ban", "bar-chart-o", "barcode", "bars", "beer", "bell", "bell-o", "bolt", "book", "bookmark", "bookmark-o", "briefcase", "bug"]

var menuval=[];
for (var i = 0; i < ICONS.length; i++) {
    var _id = ICONS[i];
    menuval.push({text: icon( _id )+' '+_id, onclick: function(){setcontentfun(_id)} 
 });
}

tinymce.PluginManager.add("font_awesome_glyphs", function(editor, url) {
    var menucreate=editor.addButton('fontAwesomeGlyphSelect', {
       type: 'listbox',
       text: 'Icons',
       icon: false,
       values: menuval
 });
});

function setcontentfun(id) {
    alert(id);
    return false;
} 
})();

这创建了一个列表框,但是当我单击菜单项而不是提醒“ICON”数组的最后一个元素时,它会显示列表框中的所有元素。如何提醒我单击的列表项?

4

1 回答 1

1

刚刚在您的代码中做了一些更新:

var menuval=[];
var insertVar = function (val) {
    return function () { 
        editor.insertContent(val);
    }
};
for (var i = 0; i < SHORTCODES.length; i++) {
    var _id = SHORTCODES[i];
    var _code = SHORTCODE_EXE[i];
    var variable = insertVar(_code);
    //alert(_id+' '+ SHORTCODES[i]+' '+SHORTCODE_EXE[i]);
    menuval.push({text: _id, onclick: variable }); 
}
于 2014-05-02T17:43:47.813 回答