打开主菜单
首页
随机
最近更改
特殊页面
沙盒
互助客栈
方针与指引
帮助
页面信息
链入页面
相关更改
设置
关于LLWiki
免责声明
LLWiki
搜索
用户菜单
3.139.67.40
讨论
监视列表
贡献
登录
LLWiki正在建设中,欢迎
加入我们
!
查看“MediaWiki:Gadget-SettingsDialog.js”的源代码
←
MediaWiki:Gadget-SettingsDialog.js
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
该页提供此wiki软件的界面文字,它已被保护以防止恶意修改。您可以点击右侧按钮在讨论页提出编辑请求,让管理人员代为编辑:
提出编辑请求
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /** * @Function: 定义小工具设置对话框 * @Methods: constructor:构建mw.SettingsDialog对象 * initialize:打开窗口时初始化html * getActionProcess:点击按钮时执行动作 * addTab:添加小工具 * removeTab:移除小工具 * saveOptions:将设置保存到localStorage * clearOptions:还原设置 * @Author: [[User:Bhsd]] */ "use strict"; /* global OO, wgULS */ mw.messages.set( wgULS({'gadget-sd-title': '小工具设置', 'gadget-sd-notify': '您的设置已保存!', 'gadget-sd-save': '保存', 'gadget-sd-cancel': '取消'}, {'gadget-sd-title': '小工具偏好設定', 'gadget-sd-notify': '您的偏好設定已儲存!', 'gadget-sd-save': '儲存', 'gadget-sd-cancel': '取消'}) ); // constructor只添加一个CSS类,剩下的交给addTab方法逐一添加小工具 function SettingsDialog(config) { config.classes = (config.classes || []).concat( 'settingsDialog' ); SettingsDialog.super.call(this, config); this.gadgets = []; } OO.inheritClass(SettingsDialog, OO.ui.ProcessDialog); // initialize只创建一个OO.ui.IndexLayout对象,剩下的交给addTab方法填入内容 SettingsDialog.prototype.initialize = function() { SettingsDialog.super.prototype.initialize.apply(this, arguments); this.content = new OO.ui.IndexLayout(); this.$body.append( this.content.$element ); }; SettingsDialog.prototype.getActionProcess = function(action) { if (action == 'save') { mw.notify(mw.msg( 'gadget-sd-notify' ), {type: 'success'}); this.saveOptions(); } else { this.clearOptions(); } this.close(); return new OO.ui.Process(); }; SettingsDialog.prototype.addTab = function(params) { const settings = mw.gadgets[ params.name ] || {}; params.checkboxes = params.checkboxes || []; params.radios = params.radios || []; params.checkboxes.forEach(function(ele) { ele.widget = new OO.ui.CheckboxInputWidget({selected: settings[ ele.data ]}); }); params.radios.forEach(function(ele) { ele.widget = new OO.ui.RadioSelectInputWidget({options: ele.options, value: settings[ ele.data ]}); delete ele.options; }); params.panel = new OO.ui.TabPanelLayout( params.name, {label: params.label} ); params.panel.$element.append( params.checkboxes.map(function(ele) { return new OO.ui.FieldLayout(ele.widget, {label: ele.label, align: 'inline', help: ele.help, helpinline: true}).$element; }) ).append( params.radios.map(function(ele) { return new OO.ui.FieldLayout(ele.widget, {label: ele.label, align: 'inline', help: ele.help, helpinline: true, classes: ['multioptions-wrap']}).$element; }) ); this.gadgets.push( params ); this.content.addTabPanels( [params.panel] ); }; SettingsDialog.prototype.removeTab = function(index) { this.content.removeTabPanels( this.gadgets[index].panel ); this.gadgets.splice(index, 1); }; SettingsDialog.prototype.clearOptions = function() { this.gadgets.forEach(function(gadget) { const settings = mw.gadgets[ gadget.name ] || {}; gadget.checkboxes.forEach(function(ele) { ele.widget.setSelected( settings[ ele.data ] || ele.default ); }); gadget.radios.forEach(function(ele) { ele.widget.setValue( settings[ ele.data ] || ele.default ); }); }); }; SettingsDialog.prototype.saveOptions = function() { this.gadgets.forEach(function(gadget) { const settings = Object.fromEntries( gadget.checkboxes.map(function(ele) { return [ele.data, ele.widget.isSelected()]; }).conat( gadget.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 ); // 视情况根据新设置更新小工具,有些设置可能需要刷新页面才会生效 }); }; SettingsDialog.static = {name: 'settingsDialog', tagName: 'div', title: mw.msg('gadget-sd-title'), actions: [{action: 'save', label: mw.msg('gadget-sd-save'), flags: ['primary', 'progressive']}, {action: 'cancel', label: mw.msg('gadget-sd-cancel'), flags: 'safe'}] }; mw.settingsDialog = new SettingsDialog({}); if (!mw.windowManager) { mw.windowManager = mw.windowmanager || new OO.ui.WindowManager(); mw.windowManager.$element.appendTo( 'body' ); } mw.windowManager.addWindows( [mw.settingsDialog] ); //</nowiki> // [[category:作为模块的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:系统工具]] // {{DEFAULTSORT:SettingsDialog.js}}
返回
MediaWiki:Gadget-SettingsDialog.js
。