From 5a4f74f9196b486b2d736fcbdada60151ace46a3 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sun, 26 Jan 2025 16:42:44 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension.json | 1 + .../ve.ui.MWParameterDropdownInputWidget.js | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 modules/ve.ui.MWParameterDropdownInputWidget.js diff --git a/extension.json b/extension.json index a092be2..2337e8d 100644 --- a/extension.json +++ b/extension.json @@ -132,6 +132,7 @@ }, "ve.ext.isekai.misc": { "scripts": [ + "ve.ui.MWParameterDropdownInputWidget.js", "ve.ext.isekai.misc.js" ], "targets": [ diff --git a/modules/ve.ui.MWParameterDropdownInputWidget.js b/modules/ve.ui.MWParameterDropdownInputWidget.js new file mode 100644 index 0000000..ccffa6d --- /dev/null +++ b/modules/ve.ui.MWParameterDropdownInputWidget.js @@ -0,0 +1,48 @@ +/*! + * VisualEditor UserInterface MWParameterDropdownInputWidget class. + * + * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * Creates an ve.ui.MWParameterDropdownInputWidget object. + * + * @class + * @extends OO.ui.DropdownWidget + * + * @constructor + */ +ve.ui.MWParameterDropdownInputWidget = function VeUiMWParameterDropdownInputWidget( config, defaultValue ) { + console.log('MWParameterDropdownInputWidget defaultValue', defaultValue); + if ( typeof config !== "undefined" ) { + config.options = parseOptions( defaultValue ); + } + console.log('MWParameterDropdownInputWidget params', config.options); + // Parent constructor + ve.ui.MWParameterDropdownInputWidget.parent.apply( this, [ config ] ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWParameterDropdownInputWidget, OO.ui.DropdownInputWidget ); + +/* Methods */ +function parseOptions ( optionsText ) { + var optionLine = optionsText.split('\n'); + var options = []; + optionLine.forEach( ( optionText ) => { + if ( optionText.trim().length > 0 ) { + var data = optionText.split( ':' ); + if ( data.length >= 2 ) { + var optionValue = data[ 0 ].trim(); + var optionLabel = data.slice( 1 ).join( ':' ).trim(); + options.push( { + data: optionValue, + label: optionLabel + } ); + } + } + } ); + return options; +}