LLWiki正在建设中,欢迎加入我们

“MediaWiki:Gadget-site-lib.js”的版本间差异

跳转到导航 跳转到搜索
 
/**
* @Function: 生成一个仿OOUI样式标准化的下拉菜单
* @Dependencies: oojs-ui-core, ext.gadget.site-styles
* @Param {Object[]} options, 形如{text, msgicon, icondata, href, target, click, data}的菜单项
* @Param {String} text, 文本,必须独一无二
* @Param {String} msg, mw.messages的键值
* @Param {String} icon, FontAwesome的图标名称(仅限fas类,可选)
* @Param {Object} data, 数据(可选,默认为text)
* @Param {String} href, 链接(可选)
* @Param {String} target(可选)
* @Param {Function} click, 单击事件(可选)
* @Param {Object} dataconfig, 数据菜单设置(可选)
* @Return {OO.ui.MenuSelectWidget}
* @Param {Object} attr, 菜单外层容器属性(可选)
* @Param {Number} multiSelect, 允许的选择数(可选)
* @Return {jQuery} 菜单外层容器,注意初始化时不可连锁
*/
mw.menu = function(options, attr, multiSelectconfig) {
const hasIcon = options.some(function(elee) { return elee.icon; }),
$menuhasClick = $('<div>', $.extend({html: options.mapsome(function(elee) { return e.href || e.click; }),
menu = new OO.ui.MenuSelectWidget( $.extend({ classes: ['site-menu'], hideWhenOutOfView: false,
const $child = $('<a>', {html: [
setSelecteditems: options.map(function(childe) {
hasIcon ? $('<i>', {class: 'fa' + (ele.icon ? 'fa-' + ele.icon : '')}) : null,
ele.msgconst ?widget mw= new OO.msgui.MenuOptionWidget({label: elee.msg )text, data: elee.data || e.text});
// 不使用OO.ui.HtmlSnippet,防止污染label属性
], href: ele.href, target: ele.target, class: ele.selected ? 'site-menu-selected' : ''}).click( ele.click );
if (hasIcon) { widget.$label.isPlainObjectprepend( ele.data ))$('<i>', {class: 'fa' + $child.data(e.icon ele? ' fa-' + e.dataicon : '')}) ); }
return thiswidget;
else { $child.data('data', ele.data); }
return $child;})
}, config) );
}), class: 'site-menu', tabindex: -1}, attr)).extend({ open: function() {
options.filter(function(e) { return e.selected; }).forEach(function(e) { menu.selectItemByLabel( e.text ); });
this.slideDown( 'fast' ).focus();
if (!hasClick) { return thismenu; }
} })menu.extendon(multiSelect && { getSelected:'choose', function()item, { return this.children( '.site-menu-selected' ); },{
clearSelected:if function(!selected) { return; }
const option = options.find(function(e) { e.text == item.getLabel(); });
this.getSelected().removeClass( 'site-menu-selected' );
returnif this(option.click) { option.click(); }
if (option.href) { location.href = option.href; }
},
setSelected: function(child) {
const $child = $(child); // child已经是jQuery了也没关系
if (this[0] != $child.parent()[0]) { return; }
if (multiSelect == 1) { this.clearSelected(); } // 单选
$child.addClass( 'site-menu-selected' );
return this;
},
getData: function() { return this.getSelected().map(function() { return $(this).data( 'data' ); }).toArray(); }
}).blur(function() { $(this).slideUp( 'fast' ); }).on('click', 'a', function() {
$menu.slideUp( 'fast' );
if (multiSelect) { $menu.setSelected( this ); }
});
return $menu;
};