From e6d5c6a9c963c4113b309064e54edf2d2b613de3 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 3 Mar 2018 20:38:14 +0100 Subject: [PATCH] mediawiki.special.apisandbox: Reorder functions This avoids forward references and /* eslint-disable no-use-before-define */ can removed. Change-Id: If26a9c275665d20864687cd99d3679b362291fa9 --- .../mediawiki.special.apisandbox.js | 131 +++++++++--------- 1 file changed, 65 insertions(+), 66 deletions(-) diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 39252dd29d..df87c9cc9f 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 () { @@ -1829,71 +1893,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; -- 2.20.1