میدیاویکی:Gadget-libSettings.js

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
تێبینی: دوای پاشەکەوتکردن، پێویستە کاشی وێبگەڕەکەت پاک بکەیتەوە تا گۆڕانکارییەکان ببینیت. بۆ گووگڵ کڕۆم، فایەرفۆکس، مایکرۆسۆفت ئێج و سافاری: پەنجە لەسەر دوگمەی ⇧ Shift ڕاگرە و کرتە لەسەر Reload بکە. بۆ وردەکاری و ڕێنمایییەکان لەسەر وێبگەڕەکانی تر، بڕوانە ئێرە.
/* Unminified and untranspiled code at https://github.com/galobtter/libSettings - this obviously shouldn't be edited directly. */ !function(n){var i={};function o(e){if(i[e])return i[e].exports;var t=i[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.m=n,o.c=i,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)o.d(n,i,function(e){return t[e]}.bind(null,i));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=2)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(s,OO.EventEmitter),i(s,[{key:"change",value:function(){this.emit("change")}},{key:"UI",value:function(){return mw.log.error("UI not defined by extending class "+this.type+"Option.")}},{key:"buildUI",value:function(e){return this.UI(this[e])}},{key:"getUIvalue",value:function(){return mw.log.error("getUIvalue not defined by extending class "+this.type+"Option.")}},{key:"getCustomUIValue",value:function(){var e=this.getUIvalue();if(e!==this.defaultValue)return e}},{key:"value",get:function(){return void 0!==this.customValue?this.customValue:this.defaultValue}}]),s);function s(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return t.name=e.name,t.defaultValue=e.defaultValue,t.UIconfig=e.UIconfig||{},t.label=e.label,t.help=e.help,t.validInput=!0,t}t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r,s=n(0);var a=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,((r=s)&&r.__esModule?r:{default:r}).default),i(u,[{key:"validate",value:function(){var e=this;return this.UIelement.getValidity().then(function(){e.validInput=!0},function(){e.validInput=!1})}},{key:"UI",value:function(e){var t=this;return this.UIconfig.name=this.name,this.UIconfig.value=e,this.UIconfig.classes=["libSettings-"+this.className],this.UIelement=new OO.ui[this.widget](this.UIconfig),this.UIelement.connect(this,{change:function(){t.validate().then(function(){return t.change()})}}),this.validate(),new OO.ui.FieldLayout(this.UIelement,{text:this.label,help:this.help,helpInline:this.helpInline,align:"top"})}},{key:"getUIvalue",value:function(){return this.UIelement.getValue()}}]),u);function u(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,e));return t.type="Text",t.className="textInput",t.widget="TextInputWidget",t}t.default=a},function(e,t,n){"use strict";var i=c(n(0)),o=c(n(3)),r=c(n(5)),s=c(n(6)),a=c(n(1)),u=c(n(7)),l=c(n(8));function c(e){return e&&e.__esModule?e:{default:e}}mw.util.addCSS(".libSettings-numberInput {\n\tmax-width: 15em\n}"),mw.libs.libSettings={},mw.libs.libSettings.Option=i.default,mw.libs.libSettings.Settings=o.default,mw.libs.libSettings.CheckboxOption=r.default,mw.libs.libSettings.DateOption=s.default,mw.libs.libSettings.TextOption=a.default,mw.libs.libSettings.NumberOption=u.default,mw.libs.libSettings.DropdownOption=l.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r,s=n(4),a=(r=s)&&r.__esModule?r:{default:r};var u=(i(l,[{key:"runOverOptionsConfig",value:function(t){this.optionsConfig.forEach(function(e){e.preferences.forEach(function(e){e.header?e.options.forEach(function(e){return t(e)}):t(e)})})}},{key:"load",value:function(){this.optionsText=mw.user.options.get(this.optionName),this.userOptions=JSON.parse(this.optionsText)||{}}},{key:"transfer",value:function(){var n=this;return this.runOverOptionsConfig(function(e){var t=n.userOptions[e.name];void 0!==t&&(e.customValue=t)}),this.options={},this.runOverOptionsConfig(function(e){n.options[e.name]=e.value}),this.options}},{key:"get",value:function(){return this.options||(this.saveSettings&&this.load(),this.transfer()),this.options}},{key:"notifySave",value:function(e){this.notifyUponSave&&(e?mw.notify(this.saveMessage):mw.notify(this.saveFailMessage))}},{key:"save",value:function(){var t=this;return this.newUserOptions={},this.runOverOptionsConfig(function(e){t.newUserOptions[e.name]=e.getCustomUIValue()}),this.saveSettings?mw.loader.using("mediawiki.api").then(function(){return t.API=new mw.Api({ajax:{headers:{"Api-User-Agent":"Script "+t.scriptName+" using libSettings."}}}),t.API.saveOption(t.optionName,JSON.stringify(t.newUserOptions)).then(function(){return t.notifySave(!0)},function(){return t.notifySave(!1)})}):(this.notifySave(!0),function(){return t.newUserOptions})}},{key:"displayMain",value:function(){var i=this;if(!this.windowManager){var e=(0,a.default)();e.static.name="settingsDialog",e.static.title=this.title,e.static.actions=[{action:"save",label:this.saveSettingsLabel,flags:["primary","progressive"]},{label:this.cancelLabel,flags:["safe","destructive"]},{action:"showDefault",label:this.showDefaultsLabel}],0<Object.keys(this.userOptions).length&&e.static.actions.push({action:"showCurrentSettings",label:this.showCurrentSettingsLabel}),this.settingsDialog=new e({size:this.size,classes:["settingsDialog"]},this),this.runOverOptionsConfig(function(e){e.connect(i.settingsDialog,{change:"changeHandler"})}),this.windowManager=new OO.ui.WindowManager,document.body.appendChild(this.windowManager.$element[0]),this.windowManager.addWindows([this.settingsDialog]),this.windowManager.on("closing",function(e,t,n){n&&n.then(function(){i.reloadUponSave&&window.location.reload()})})}return this.windowManager.openWindow(this.settingsDialog),this.windowManager}},{key:"display",value:function(){var e=this;return this.get(),mw.loader.using(["oojs-ui-core","oojs-ui-widgets","oojs-ui-windows"]).then(function(){return e.displayMain()})}}]),l);function l(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,l),mw.messages.set({"ls-saveMessage":"Settings for $1 successfully saved.","ls-saveFailMessage":"Could not save settings for $1.","ls-save":"پاشەکەوتکردنی ڕێکخستنەکان","ls-cancel":"پاشگەزبوونەوە","ls-showDefaults":"پیشاندانی بارە بنچینەیییەکان","ls-showCurrentSettings":"پیشاندانی ڕێکخستنەکانی ھەنووکە"}),this.optionsConfig=t.optionsConfig,this.scriptName=t.scriptName,this.optionName="userjs-"+(t.optionName||t.scriptName),this.size=t.size,this.title=t.title||"ڕێکخستنەکان",this.saveSettings=void 0===t.saveSettings||t.saveSettings,this.notifyUponSave=void 0!==t.notifyUponSave?t.notifyUponSave:this.saveSettings,this.reloadUponSave=void 0!==t.reloadUponSave?t.reloadUponSave:this.saveSettings,this.userOptions=t.userOptions||{},this.runOverOptionsConfig(function(e){void 0===e.helpInline&&(e.helpInline=t.helpInline)}),this.height=t.height,this.saveSettingsLabel=t.saveSettingsLabel||mw.msg("ls-save"),this.cancelLabel=t.cancelLabel||mw.msg("ls-cancel"),this.showDefaultsLabel=t.showDefaultsLabel||mw.msg("ls-showDefaults"),this.showCurrentSettingsLabel=t.showCurrentSettingsLabel||mw.msg("ls-showCurrentSettings"),this.saveMessage=mw.msg("ls-saveMessage",this.scriptName),this.saveFailMessage=mw.msg("ls-saveFailMessage",this.scriptName)}t.default=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});function s(e,t,n){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,t);if(void 0===i){var o=Object.getPrototypeOf(e);return null===o?void 0:s(o,t,n)}if("value"in i)return i.value;var r=i.get;return void 0!==r?r.call(n):void 0}var o=function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e};function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.default=function(){var r=function(e){function r(e,t,n,i){a(this,r);var o=u(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e,t));return o.element=n,o.element.preferences.forEach(function(e){if(e.header){e.UIconfig=e.UIconfig||{},e.UIconfig.label=e.header;var t=new OO.ui.FieldsetLayout(e.UIconfig),n=e.options.map(function(e){return e.buildUI(i)});t.addItems(n),o.$element.append(t.$element)}else o.$element.append(e.buildUI(i).$element)}),o}return l(r,e),o(r,[{key:"setupOutlineItem",value:function(){this.outlineItem.setLabel(this.element.title),this.outlineItem.setLevel(this.element.level)}}]),r}(OO.ui.PageLayout);return function(e){function i(e,t){a(this,i);var n=u(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));return n.settings=t,n}return l(i,e),o(i,[{key:"genInternalUI",value:function(t){var e=this.settings.optionsConfig.filter(function(e){return!e.hide}),n=1===e.length,i=void 0,o=e.map(function(e){return new r(e.title,{padded:n,scrollabe:!1},e,t)});return n?i=o[0]:(i=new OO.ui.BookletLayout({outlined:!0})).addPages(o),this.outerHeight=o[0].$element.outerHeight(!0),i}},{key:"setupUI",value:function(e){this.content=this.genInternalUI(e),this.$body.html(this.content.$element),this.changeHandler()}},{key:"getSetupProcess",value:function(){var e=this,t=s(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"getSetupProcess",this).call(this);return t.next(function(){return e.setupUI("value")}),t}},{key:"changeHandler",value:function(){var n=!0,i=!1,o=!1;this.settings.runOverOptionsConfig(function(e){e.validInput||(n=!1);var t=e.getUIvalue();t!==e.value&&(i=!0),t!==e.defaultValue&&(o=!0)}),this.actions.setAbilities({save:n&&i,showDefault:o,showCurrentSettings:i})}},{key:"regenUI",value:function(e){var t=void 0;this.content.getCurrentPageName&&(t=this.content.getCurrentPageName()),this.setupUI(e),t&&this.content.setPage(t)}},{key:"getActionProcess",value:function(e){var t=this;return"save"===e?new OO.ui.Process(function(){var e=t.settings.save();t.pushPending(),t.close(e)}):"showDefault"===e?new OO.ui.Process(function(){t.regenUI("defaultValue")}):"showCurrentSettings"===e?new OO.ui.Process(function(){t.regenUI("value")}):s(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"getActionProcess",this).call(this,e)}},{key:"getHoldProcess",value:function(e){var t=this,n=s(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"getHoldProcess",this).call(this,e);return e&&(n.next(e),n.next(function(){return t.popPending()})),n}},{key:"getBodyHeight",value:function(){return this.settings.height||1*this.content.$element.outerWidth(!0)/1.61803398875}}]),i}(OO.ui.ProcessDialog)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r,s=n(0);var a=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,((r=s)&&r.__esModule?r:{default:r}).default),i(u,[{key:"UI",value:function(e){return this.UIconfig.name=this.name,this.UIconfig.selected=e,this.UIelement=new OO.ui.CheckboxInputWidget(this.UIconfig),this.UIelement.connect(this,{change:"change"}),new OO.ui.FieldLayout(this.UIelement,{help:this.help,label:this.label,helpInline:this.helpInline,align:"inline"})}},{key:"getUIvalue",value:function(){return this.UIelement.isSelected()}}]),u);function u(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,e,"Checkbox"))}t.default=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,o=n(0);var r=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(s,((i=o)&&i.__esModule?i:{default:i}).default),s);function s(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,e));return t.type="Date",t}t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r,s=n(1);var a=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,((r=s)&&r.__esModule?r:{default:r}).default),i(u,[{key:"getUIvalue",value:function(){return Number(function e(t,n,i){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var r=Object.getPrototypeOf(t);return null===r?void 0:e(r,n,i)}if("value"in o)return o.value;var s=o.get;return void 0!==s?s.call(i):void 0}(u.prototype.__proto__||Object.getPrototypeOf(u.prototype),"getUIvalue",this).call(this))}}]),u);function u(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,e));return t.type="Number",t.className="numberInput",t.widget="NumberInputWidget",t}t.default=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e};function o(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var r,s=n(0);var a=(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,((r=s)&&r.__esModule?r:{default:r}).default),i(u,[{key:"UI",value:function(n){var i=this;return this.UIconfig.name=this.name,this.UIconfig.options=this.values,this.UIconfig.options.some(function(e,t){if(e.data===n)return i.UIconfig.options.unshift(i.UIconfig.options.splice(t,1)[0]),!0}),this.UIelement=new OO.ui.DropdownInputWidget(this.UIconfig),this.UIelement.connect(this,{change:"change"}),new OO.ui.FieldLayout(this.UIelement,{text:this.label,help:this.help,helpInline:this.helpInline,align:"top"})}},{key:"getUIvalue",value:function(){return this.UIelement.getValue()}}]),u);function u(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,e,"Dropdown"));return t.values=e.values,t}t.default=a}]);