打开主菜单
首页
随机
最近更改
特殊页面
沙盒
互助客栈
方针与指引
帮助
页面信息
链入页面
相关更改
设置
关于LLWiki
免责声明
LLWiki
搜索
用户菜单
3.133.159.58
讨论
监视列表
贡献
登录
LLWiki正在建设中,欢迎
加入我们
!
查看“MediaWiki:Gadget-SettingsDialog.js”的源代码
←
MediaWiki:Gadget-SettingsDialog.js
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
该页提供此wiki软件的界面文字,它已被保护以防止恶意修改。您可以点击右侧按钮在讨论页提出编辑请求,让管理人员代为编辑:
提出编辑请求
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /** * @Function: 定义小工具设置对话框 * @Methods: constructor,构建mw.SettingsDialog对象 initialize,打开窗口时初始化html getActionProcess,点击按钮时执行动作 saveOptions,将设置保存到localStorage * @Author: [[User:Bhsd]] */ "use strict"; /* global OO, wgULS */ const formalize = function(ele) { return {data: ele.data || ele[0], label: ele.label || ele[1]}; }; mw.SettingsDialog = function(config) { config.classes = (config.classes || []).concat( 'settingsDialog' ); mw.SettingsDialog.super.call(this, config); this.name = config.name; mw.gadgets = mw.gadgets || {}; const settings = mw.gadgets[ this.name ] || {}; // 这里不更新mw.gadgets[ this.name ],因为原则上小工具执行时已经更新过了 // checkbox输入:[data, label, default],输出:{data, label, widget} this.checkboxes = (config.checkboxes || []).map(function(ele) { const option = formalize(ele); return $.extend(option, {widget: new OO.ui.CheckboxInputWidget( {selected: settings[ option.data ] || ele.default || ele[2]} ) }); }); // radio输入:{0: data, 1: label, 2: default, options},输出:{data, label, widget} this.radios = (config.radios || []).map(function(ele) { const option = formalize(ele); return $.extend(option, {widget: new OO.ui.RadioSelectInputWidget({options: ele.options.map(formalize), value: settings[ option.data ] || ele.default || ele[2]}) // 初始值不正确时会自动选取第一个选项 }); }); }; OO.inheritClass(mw.SettingsDialog, OO.ui.ProcessDialog); mw.SettingsDialog.prototype.initialize = function() { mw.SettingsDialog.super.prototype.initialize.apply(this, arguments); this.$body.append( this.checkboxes.map(function(ele) { return new OO.ui.FieldLayout(ele.widget, {label: ele.label, align: 'inline'}).$element; }).concat( '<hr>' ).concat( this.radios.map(function(ele) { return $('<div>', {class: 'multioptions-wrap', html: [$('<b>', {text: ele.label}), ele.widget.$element]}); }) ) ); }; mw.SettingsDialog.prototype.getActionProcess = function(action) { if (action == 'save') { mw.notify(wgULS('您的设置已保存!', '您的設置已保存!'), {type: 'success'}); this.saveOptions(); } this.close(); return new OO.ui.Process(); }; mw.SettingsDialog.prototype.saveOptions = function() { const settings = Object.fromEntries( this.checkboxes.map(function(ele) { return [ele.data, ele.widget.isSelected()]; }).conat( this.radios.map(function(ele) { return [ele.data, ele.widget.getValue()]; }) ) ); mw.gadgets[ this.name ] = settings; mw.storage.setObject('gadget-' + this.name, settings); mw.hook( 'settings.update' ).fire( this.name ); // 视情况根据新设置更新小工具,有些设置可能需要刷新页面才会生效 }; mw.SettingsDialog.static = {name: 'settingsDialog', tagName: 'div', title: wgULS('小工具设置', '小工具設置'), actions: [{action: 'save', label: '保存', flags: ['primary', 'progressive']}, {action: 'cancel', label: '取消', flags: 'safe'}] }; //</nowiki> // [[category:作为模块的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:系统工具]] // {{DEFAULTSORT:SettingsDialog.js}}
返回
MediaWiki:Gadget-SettingsDialog.js
。