X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.apisandbox.js;h=a7470da768a4ad4b2850a5a3d8927ab5a4b5d0a5;hb=82337cd3bdc0263e5123c603149a517c72f9c897;hp=39252dd29df307598a7d90b3b99f8b70d73dd658;hpb=cde659e4dae4a9eb6cf49521b5250b89b7f8d9d9;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 39252dd29d..a7470da768 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -1,4 +1,3 @@ -/* eslint-disable no-use-before-define */ ( function ( $, mw, OO ) { 'use strict'; var ApiSandbox, Util, WidgetMethods, Validators, @@ -14,6 +13,71 @@ moduleInfoCache = {}, baseRequestParams; + /** + * A wrapper for a widget that provides an enable/disable button + * + * @class + * @private + * @constructor + * @param {OO.ui.Widget} widget + * @param {Object} [config] Configuration options + */ + function OptionalWidget( widget, config ) { + var k; + + config = config || {}; + + this.widget = widget; + this.$cover = config.$cover || + $( '
' ).addClass( 'mw-apisandbox-optionalWidget-cover' ); + this.checkbox = new OO.ui.CheckboxInputWidget( config.checkbox ) + .on( 'change', this.onCheckboxChange, [], this ); + + OptionalWidget[ 'super' ].call( this, config ); + + // Forward most methods for convenience + for ( k in this.widget ) { + if ( $.isFunction( this.widget[ k ] ) && !this[ k ] ) { + this[ k ] = this.widget[ k ].bind( this.widget ); + } + } + + this.$cover.on( 'click', this.onOverlayClick.bind( this ) ); + + this.$element + .addClass( 'mw-apisandbox-optionalWidget' ) + .append( + this.$cover, + $( '
' ).addClass( 'mw-apisandbox-optionalWidget-fields' ).append( + $( '
' ).addClass( 'mw-apisandbox-optionalWidget-widget' ).append( + widget.$element + ), + $( '
' ).addClass( 'mw-apisandbox-optionalWidget-checkbox' ).append( + this.checkbox.$element + ) + ) + ); + + this.setDisabled( widget.isDisabled() ); + } + OO.inheritClass( OptionalWidget, OO.ui.Widget ); + OptionalWidget.prototype.onCheckboxChange = function ( checked ) { + this.setDisabled( !checked ); + }; + OptionalWidget.prototype.onOverlayClick = function () { + this.setDisabled( false ); + if ( $.isFunction( this.widget.focus ) ) { + this.widget.focus(); + } + }; + OptionalWidget.prototype.setDisabled = function ( disabled ) { + OptionalWidget[ 'super' ].prototype.setDisabled.call( this, disabled ); + this.widget.setDisabled( this.isDisabled() ); + this.checkbox.setSelected( !this.isDisabled() ); + this.$cover.toggle( this.isDisabled() ); + return this; + }; + WidgetMethods = { textInputWidget: { getApiValue: function () { @@ -320,8 +384,10 @@ * @return {OO.ui.Widget} */ createWidgetForParameter: function ( pi, opts ) { - var widget, innerWidget, finalWidget, items, $button, $content, func, - multiMode = 'none'; + var widget, innerWidget, finalWidget, items, $content, func, + multiModeButton = null, + multiModeInput = null, + multiModeAllowed = false; opts = opts || {}; @@ -378,7 +444,8 @@ $.extend( widget, WidgetMethods.textInputWidget ); $.extend( widget, WidgetMethods.passwordWidget ); widget.setValidation( Validators.generic ); - multiMode = 'enter'; + multiModeAllowed = true; + multiModeInput = widget; break; case 'integer': @@ -394,7 +461,8 @@ if ( Util.apiBool( pi.enforcerange ) ) { widget.setRange( pi.min || -Infinity, pi.max || Infinity ); } - multiMode = 'enter'; + multiModeAllowed = true; + multiModeInput = widget; break; case 'limit': @@ -417,7 +485,8 @@ pi.apiSandboxMax = mw.config.get( 'apihighlimits' ) ? pi.highmax : pi.max; widget.paramInfo = pi; $.extend( widget, WidgetMethods.textInputWidget ); - multiMode = 'enter'; + multiModeAllowed = true; + multiModeInput = widget; break; case 'timestamp': @@ -431,7 +500,7 @@ widget.paramInfo = pi; $.extend( widget, WidgetMethods.textInputWidget ); $.extend( widget, WidgetMethods.dateTimeInputWidget ); - multiMode = 'indicator'; + multiModeAllowed = true; break; case 'upload': @@ -531,25 +600,13 @@ break; } - if ( Util.apiBool( pi.multi ) && multiMode !== 'none' ) { + if ( Util.apiBool( pi.multi ) && multiModeAllowed ) { innerWidget = widget; - switch ( multiMode ) { - case 'enter': - $content = innerWidget.$element; - break; - - case 'indicator': - $button = innerWidget.$indicator; - $button.css( 'cursor', 'pointer' ); - $button.attr( 'tabindex', 0 ); - $button.parent().append( $button ); - innerWidget.setIndicator( 'next' ); - $content = innerWidget.$element; - break; - - default: - throw new Error( 'Unknown multiMode "' + multiMode + '"' ); - } + + multiModeButton = new OO.ui.ButtonWidget( { + label: mw.message( 'apisandbox-add-multi' ).text() + } ); + $content = innerWidget.$element.add( multiModeButton.$element ); widget = new OO.ui.PopupTagMultiselectWidget( { allowArbitrary: true, @@ -557,6 +614,7 @@ $overlay: true, popup: { classes: [ 'mw-apisandbox-popup' ], + padded: true, $content: $content } } ); @@ -574,22 +632,11 @@ return false; } }; - switch ( multiMode ) { - case 'enter': - innerWidget.connect( null, { enter: func } ); - break; - - case 'indicator': - $button.on( { - click: func, - keypress: function ( e ) { - if ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) { - func(); - } - } - } ); - break; + + if ( multiModeInput ) { + multiModeInput.on( 'enter', func ); } + multiModeButton.on( 'click', func ); } if ( Util.apiBool( pi.required ) || opts.nooptional ) { @@ -1829,71 +1876,6 @@ return ret; }; - /** - * A wrapper for a widget that provides an enable/disable button - * - * @class - * @private - * @constructor - * @param {OO.ui.Widget} widget - * @param {Object} [config] Configuration options - */ - function OptionalWidget( widget, config ) { - var k; - - config = config || {}; - - this.widget = widget; - this.$cover = config.$cover || - $( '
' ).addClass( 'mw-apisandbox-optionalWidget-cover' ); - this.checkbox = new OO.ui.CheckboxInputWidget( config.checkbox ) - .on( 'change', this.onCheckboxChange, [], this ); - - OptionalWidget[ 'super' ].call( this, config ); - - // Forward most methods for convenience - for ( k in this.widget ) { - if ( $.isFunction( this.widget[ k ] ) && !this[ k ] ) { - this[ k ] = this.widget[ k ].bind( this.widget ); - } - } - - this.$cover.on( 'click', this.onOverlayClick.bind( this ) ); - - this.$element - .addClass( 'mw-apisandbox-optionalWidget' ) - .append( - this.$cover, - $( '
' ).addClass( 'mw-apisandbox-optionalWidget-fields' ).append( - $( '
' ).addClass( 'mw-apisandbox-optionalWidget-widget' ).append( - widget.$element - ), - $( '
' ).addClass( 'mw-apisandbox-optionalWidget-checkbox' ).append( - this.checkbox.$element - ) - ) - ); - - this.setDisabled( widget.isDisabled() ); - } - OO.inheritClass( OptionalWidget, OO.ui.Widget ); - OptionalWidget.prototype.onCheckboxChange = function ( checked ) { - this.setDisabled( !checked ); - }; - OptionalWidget.prototype.onOverlayClick = function () { - this.setDisabled( false ); - if ( $.isFunction( this.widget.focus ) ) { - this.widget.focus(); - } - }; - OptionalWidget.prototype.setDisabled = function ( disabled ) { - OptionalWidget[ 'super' ].prototype.setDisabled.call( this, disabled ); - this.widget.setDisabled( this.isDisabled() ); - this.checkbox.setSelected( !this.isDisabled() ); - this.$cover.toggle( this.isDisabled() ); - return this; - }; - $( ApiSandbox.init ); module.exports = ApiSandbox;