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

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

跳转到导航 跳转到搜索
添加1,037字节 、​ 2021年2月20日 (六) 06:54
无编辑摘要
* @Dependencies: ext.gadget.site-styles
* @Param {Object[]} options, 形如{text, msg, icon, href, target, click}的菜单项
* @Param {ObjectString} attrtext, 菜单外层容器属性文本
* @Param {String} msg, mw.messages的键值
* @Return {jQuery} 菜单外层容器
* @Param {String} icon, FontAwesome的图标名称(仅限fas类,可选)
* @Param {String} href, 链接(可选)
* @Param {String} target(可选)
* @Param {Function} click, 单击事件(可选)
* @Param {Object} attr, 菜单外层容器属性(可选)
* @Param {Number} multiSelect, 允许的选择数(可选)
* @Return {jQuery} 菜单外层容器,注意初始化时不可连锁
*/
mw.menu = function(options, attr, multiSelect) {
const hasIcon = options.some(function(ele) { return ele.icon; });,
return $menu = $('<div>', $.extend({html: options.map(function(ele) {
return $('<a>', {href: ele.href, target: ele.target, class: ele.selected ? 'site-menu-selected' : '', html: [
hasIcon ? $('<i>', {class: 'fa' + (ele.icon ? 'fa-' + ele.icon : '')}) : null,
ele.msg ? mw.msg( ele.msg ) : ele.text
]}).click( ele.click );
}), class: 'site-menu', tabindex: -1}, attr)).extend({open: function() { this.slideDown( 'fast' ).focus(); }})
.blurextend(multiSelect && { getSelected: function() { $(return this).slideUpchildren( 'fast.site-menu-selected' ); }),
.on('click', 'a',clearSelected: function(e) { $this.getSelected(e.delegateTarget).slideUpremoveClass( 'fastsite-menu-selected' ); });,
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' );
}
}).blur(function() { $(this).slideUp( 'fast' ); }).on('click', 'a', function() {
$menu.slideUp( 'fast' );
if (multiSelect) { $menu.setSelected( this ); }
});
return $menu;
};
 
16,874

个编辑

导航菜单