X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Flib%2Foojs%2Foojs.jquery.js;h=b51c5d12a1b31ec3973049aae5245bcf4d7cb351;hb=c4e5a9dd97ce98e410fcdee8c5fda96f03fd8b25;hp=f93051c70525cf75553558656c7e672cbf27e4cb;hpb=d42d6bd868fd5b579080639995e6a7e23851fcf3;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/lib/oojs/oojs.jquery.js b/resources/lib/oojs/oojs.jquery.js index f93051c705..b51c5d12a1 100644 --- a/resources/lib/oojs/oojs.jquery.js +++ b/resources/lib/oojs/oojs.jquery.js @@ -1,18 +1,17 @@ /*! - * OOjs v2.0.0 optimised for jQuery + * OOjs v2.2.0 optimised for jQuery * https://www.mediawiki.org/wiki/OOjs * - * Copyright 2011-2017 OOjs Team and other contributors. + * Copyright 2011-2018 OOjs Team and other contributors. * Released under the MIT license * https://oojs.mit-license.org * - * Date: 2017-04-05T02:18:04Z + * Date: 2018-04-03T19:45:13Z */ ( function ( global ) { 'use strict'; -/* exported toString */ var /** * Namespace for all classes, static methods and static properties. @@ -22,6 +21,8 @@ var oo = {}, // Optimisation: Local reference to Object.prototype.hasOwnProperty hasOwn = oo.hasOwnProperty, + // Marking this as "exported" doesn't work when parserOptions.sourceType is module + // eslint-disable-next-line no-unused-vars toString = oo.toString; /* Class Methods */ @@ -87,12 +88,9 @@ oo.inheritClass = function ( targetFn, originFn ) { targetConstructor = targetFn.prototype.constructor; - // Using ['super'] instead of .super because 'super' is not supported - // by IE 8 and below (bug 63303). - // Provide .parent as alias for code supporting older browsers which + // [DEPRECATED] Provide .parent as alias for code supporting older browsers which // allows people to comply with their style guide. - // eslint-disable-next-line dot-notation - targetFn[ 'super' ] = targetFn.parent = originFn; + targetFn.super = targetFn.parent = originFn; targetFn.prototype = Object.create( originFn.prototype, { // Restore constructor property of targetFn @@ -263,7 +261,7 @@ oo.deleteProp = function ( obj ) { } delete prop[ arguments[ i ] ]; // Walk back through props removing any plain empty objects - while ( ( prop = props.pop() ) && oo.isPlainObject( prop ) && !Object.keys( prop ).length ) { + while ( props.length > 1 && ( prop = props.pop() ) && oo.isPlainObject( prop ) && !Object.keys( prop ).length ) { delete props[ props.length - 1 ][ arguments[ props.length ] ]; } }; @@ -394,9 +392,7 @@ oo.compare = function ( a, b, asymmetrical ) { for ( k in a ) { if ( !hasOwn.call( a, k ) || a[ k ] === undefined || a[ k ] === b[ k ] ) { - // Support es3-shim: Without the hasOwn filter, comparing [] to {} will be false in ES3 - // because the shimmed "forEach" is enumerable and shows up in Array but not Object. - // Also ignore undefined values, because there is no conceptual difference between + // Ignore undefined values, because there is no conceptual difference between // a key that is absent and a key that is present but whose value is undefined. continue; } @@ -683,6 +679,24 @@ oo.isPlainObject = $.isPlainObject; } } + /** + * @private + * @param {OO.EventEmitter} eventEmitter Event emitter + * @param {string} event Event name + * @param {Object} binding + */ + function addBinding( eventEmitter, event, binding ) { + var bindings; + // Auto-initialize bindings list + if ( hasOwn.call( eventEmitter.bindings, event ) ) { + bindings = eventEmitter.bindings[ event ]; + } else { + bindings = eventEmitter.bindings[ event ] = []; + } + // Add binding + bindings.push( binding ); + } + /* Methods */ /** @@ -695,25 +709,18 @@ oo.isPlainObject = $.isPlainObject; * @param {Function|string} method Function or method name to call when event occurs * @param {Array} [args] Arguments to pass to listener, will be prepended to emitted arguments * @param {Object} [context=null] Context object for function or method call - * @throws {Error} Listener argument is not a function or a valid method name * @chainable + * @throws {Error} Listener argument is not a function or a valid method name */ oo.EventEmitter.prototype.on = function ( event, method, args, context ) { - var bindings; - validateMethod( method, context ); - if ( hasOwn.call( this.bindings, event ) ) { - bindings = this.bindings[ event ]; - } else { - // Auto-initialize bindings list - bindings = this.bindings[ event ] = []; - } - // Add binding - bindings.push( { + // Ensure consistent object shape (optimisation) + addBinding( this, event, { method: method, args: args, - context: ( arguments.length < 4 ) ? null : context + context: ( arguments.length < 4 ) ? null : context, + once: false } ); return this; }; @@ -726,12 +733,16 @@ oo.isPlainObject = $.isPlainObject; * @chainable */ oo.EventEmitter.prototype.once = function ( event, listener ) { - var eventEmitter = this, - wrapper = function () { - eventEmitter.off( event, wrapper ); - return listener.apply( this, arguments ); - }; - return this.on( event, wrapper ); + validateMethod( listener ); + + // Ensure consistent object shape (optimisation) + addBinding( this, event, { + method: listener, + args: undefined, + context: null, + once: true + } ); + return this; }; /** @@ -806,6 +817,11 @@ oo.isPlainObject = $.isPlainObject; } else { method = binding.method; } + if ( binding.once ) { + // Must unbind before calling method to avoid + // any nested triggers. + this.off( event, method ); + } method.apply( binding.context, binding.args ? binding.args.concat( args ) : args @@ -823,7 +839,7 @@ oo.isPlainObject = $.isPlainObject; * @param {Object.|Object.|Object.} methods List of * event bindings keyed by event name containing either method names, functions or arrays containing * method name or function followed by a list of arguments to be passed to callback before emitted - * arguments + * arguments. * @chainable */ oo.EventEmitter.prototype.connect = function ( context, methods ) { @@ -849,8 +865,13 @@ oo.isPlainObject = $.isPlainObject; * * @param {Object} context Object to disconnect methods from * @param {Object.|Object.|Object.} [methods] List of - * event bindings keyed by event name. Values can be either method names or functions, but must be - * consistent with those used in the corresponding call to "connect". + * event bindings keyed by event name. Values can be either method names, functions or arrays + * containing a method name. + * NOTE: To allow matching call sites with connect(), array values are allowed to contain the + * parameters as well, but only the method name is used to find bindings. Tt is discouraged to + * have multiple bindings for the same event to the same listener, but if used (and only the + * parameters vary), disconnecting one variation of (event name, event listener, parameters) + * will disconnect other variations as well. * @chainable */ oo.EventEmitter.prototype.disconnect = function ( context, methods ) { @@ -1109,8 +1130,10 @@ oo.isPlainObject = $.isPlainObject; // Remove the item from the current index this.items.splice( existingIndex, 1 ); - // Adjust new index after removal - newIndex--; + // If necessary, adjust new index after removal + if ( existingIndex < newIndex ) { + newIndex--; + } // Move the item to the new index this.items.splice( newIndex, 0, item ); @@ -1305,9 +1328,9 @@ oo.SortedEmitterList.prototype.setSortingCallback = function ( sortingCallback ) /** * Add items to the sorted list. * - * @chainable * @param {OO.EventEmitter|OO.EventEmitter[]} items Item to add or * an array of items to add + * @chainable */ oo.SortedEmitterList.prototype.addItems = function ( items ) { var index, i, insertionIndex; @@ -1373,6 +1396,12 @@ oo.SortedEmitterList.prototype.findInsertionIndex = function ( item ) { /* global hasOwn */ /** + * A map interface for associating arbitrary data with a symbolic name. Used in + * place of a plain object to provide additional {@link #method-register registration} + * or {@link #method-lookup lookup} functionality. + * + * See . + * * @class OO.Registry * @mixins OO.EventEmitter * @@ -1572,6 +1601,8 @@ oo.Factory.prototype.create = function ( name ) { }; /* eslint-env node */ + +/* istanbul ignore next */ if ( typeof module !== 'undefined' && module.exports ) { module.exports = oo; } else {