Update OOjs to v2.0.0
authorJames D. Forrester <jforrester@wikimedia.org>
Wed, 5 Apr 2017 15:40:22 +0000 (08:40 -0700)
committerJames D. Forrester <jforrester@wikimedia.org>
Wed, 5 Apr 2017 15:42:26 +0000 (08:42 -0700)
Release notes:
 https://phabricator.wikimedia.org/diffusion/GOJS/browse/master/History.md;v2.0.0

Change-Id: I5bbc3e0ec7c4789c6b476c0fb039e0292027c014

RELEASE-NOTES-1.29
resources/lib/oojs/oojs.jquery.js

index 6dbc749..b1157fe 100644 (file)
@@ -70,6 +70,7 @@ production.
 * Updated oyejorge/less.php from v1.7.0.10 to v1.7.0.14.
 * Updated monolog from v1.18.2 to 1.22.1.
 * Updated wikimedia/composer-merge-plugin from v1.3.1 to v1.4.0.
+* Updated OOjs from v1.1.10 to v2.0.0.
 
 ==== New external libraries ====
 * Added wikimedia/timestamp v1.0.0.
index 3857f99..f93051c 100644 (file)
@@ -1,18 +1,18 @@
 /*!
- * OOjs v1.1.10 optimised for jQuery
+ * OOjs v2.0.0 optimised for jQuery
  * https://www.mediawiki.org/wiki/OOjs
  *
- * Copyright 2011-2015 OOjs Team and other contributors.
+ * Copyright 2011-2017 OOjs Team and other contributors.
  * Released under the MIT license
- * http://oojs.mit-license.org
+ * https://oojs.mit-license.org
  *
- * Date: 2015-11-11T16:49:11Z
+ * Date: 2017-04-05T02:18:04Z
  */
 ( function ( global ) {
 
 'use strict';
 
-/*exported toString */
+/* exported toString */
 var
        /**
         * Namespace for all classes, static methods and static properties.
@@ -22,21 +22,7 @@ var
        oo = {},
        // Optimisation: Local reference to Object.prototype.hasOwnProperty
        hasOwn = oo.hasOwnProperty,
-       toString = oo.toString,
-       // Object.create() is impossible to fully polyfill, so don't require it
-       createObject = Object.create || ( function () {
-               // Reusable constructor function
-               function Empty() {}
-               return function ( prototype, properties ) {
-                       var obj;
-                       Empty.prototype = prototype;
-                       obj = new Empty();
-                       if ( properties && hasOwn.call( properties, 'constructor' ) ) {
-                               obj.constructor = properties.constructor.value;
-                       }
-                       return obj;
-               };
-       } )();
+       toString = oo.toString;
 
 /* Class Methods */
 
@@ -92,8 +78,11 @@ oo.initClass = function ( fn ) {
 oo.inheritClass = function ( targetFn, originFn ) {
        var targetConstructor;
 
+       if ( !originFn ) {
+               throw new Error( 'inheritClass: Origin is not a function (actually ' + originFn + ')' );
+       }
        if ( targetFn.prototype instanceof originFn ) {
-               throw new Error( 'Target already inherits from origin' );
+               throw new Error( 'inheritClass: Target already inherits from origin' );
        }
 
        targetConstructor = targetFn.prototype.constructor;
@@ -102,9 +91,10 @@ oo.inheritClass = function ( targetFn, originFn ) {
        // by IE 8 and below (bug 63303).
        // 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.prototype = createObject( originFn.prototype, {
+       targetFn.prototype = Object.create( originFn.prototype, {
                // Restore constructor property of targetFn
                constructor: {
                        value: targetConstructor,
@@ -116,7 +106,7 @@ oo.inheritClass = function ( targetFn, originFn ) {
 
        // Extend static properties - always initialize both sides
        oo.initClass( originFn );
-       targetFn.static = createObject( originFn.static );
+       targetFn.static = Object.create( originFn.static );
 };
 
 /**
@@ -153,6 +143,10 @@ oo.inheritClass = function ( targetFn, originFn ) {
 oo.mixinClass = function ( targetFn, originFn ) {
        var key;
 
+       if ( !originFn ) {
+               throw new Error( 'mixinClass: Origin is not a function (actually ' + originFn + ')' );
+       }
+
        // Copy prototype properties
        for ( key in originFn.prototype ) {
                if ( key !== 'constructor' && hasOwn.call( originFn.prototype, key ) ) {
@@ -173,13 +167,26 @@ oo.mixinClass = function ( targetFn, originFn ) {
        }
 };
 
+/**
+ * Test whether one class is a subclass of another, without instantiating it.
+ *
+ * Every class is considered a subclass of Object and of itself.
+ *
+ * @param {Function} testFn The class to be tested
+ * @param {Function} baseFn The base class
+ * @return {boolean} Whether testFn is a subclass of baseFn (or equal to it)
+ */
+oo.isSubclass = function ( testFn, baseFn ) {
+       return testFn === baseFn || testFn.prototype instanceof baseFn;
+};
+
 /* Object Methods */
 
 /**
  * Get a deeply nested property of an object using variadic arguments, protecting against
  * undefined property errors.
  *
- * `quux = oo.getProp( obj, 'foo', 'bar', 'baz' );` is equivalent to `quux = obj.foo.bar.baz;`
+ * `quux = OO.getProp( obj, 'foo', 'bar', 'baz' );` is equivalent to `quux = obj.foo.bar.baz;`
  * except that the former protects against JS errors if one of the intermediate properties
  * is undefined. Instead of throwing an error, this function will return undefined in
  * that case.
@@ -218,7 +225,7 @@ oo.getProp = function ( obj ) {
 oo.setProp = function ( obj ) {
        var i,
                prop = obj;
-       if ( Object( obj ) !== obj ) {
+       if ( Object( obj ) !== obj || arguments.length < 2 ) {
                return;
        }
        for ( i = 1; i < arguments.length - 2; i++ ) {
@@ -233,6 +240,34 @@ oo.setProp = function ( obj ) {
        prop[ arguments[ arguments.length - 2 ] ] = arguments[ arguments.length - 1 ];
 };
 
+/**
+ * Delete a deeply nested property of an object using variadic arguments, protecting against
+ * undefined property errors, and deleting resulting empty objects.
+ *
+ * @param {Object} obj
+ * @param {...Mixed} [keys]
+ */
+oo.deleteProp = function ( obj ) {
+       var i,
+               prop = obj,
+               props = [ prop ];
+       if ( Object( obj ) !== obj || arguments.length < 2 ) {
+               return;
+       }
+       for ( i = 1; i < arguments.length - 1; i++ ) {
+               if ( prop[ arguments[ i ] ] === undefined || Object( prop[ arguments[ i ] ] ) !== prop[ arguments[ i ] ] ) {
+                       return;
+               }
+               prop = prop[ arguments[ i ] ];
+               props.push( prop );
+       }
+       delete prop[ arguments[ i ] ];
+       // Walk back through props removing any plain empty objects
+       while ( ( prop = props.pop() ) && oo.isPlainObject( prop ) && !Object.keys( prop ).length ) {
+               delete props[ props.length - 1 ][ arguments[ props.length ] ];
+       }
+};
+
 /**
  * Create a new object that is an instance of the same
  * constructor as the input, inherits from the same object
@@ -258,7 +293,7 @@ oo.setProp = function ( obj ) {
 oo.cloneObject = function ( origin ) {
        var key, r;
 
-       r = createObject( origin.constructor.prototype );
+       r = Object.create( origin.constructor.prototype );
 
        for ( key in origin ) {
                if ( hasOwn.call( origin, key ) ) {
@@ -314,7 +349,7 @@ oo.binarySearch = function ( arr, searchFunc, forInsertion ) {
                right = arr.length;
        while ( left < right ) {
                // Equivalent to Math.floor( ( left + right ) / 2 ) but much faster
-               /*jshint bitwise:false */
+               // eslint-disable-next-line no-bitwise
                mid = ( left + right ) >> 1;
                cmpResult = searchFunc( arr[ mid ] );
                if ( cmpResult < 0 ) {
@@ -479,10 +514,9 @@ oo.getHash.keySortReplacer = function ( key, val ) {
                        normalized[ keys[ i ] ] = val[ keys[ i ] ];
                }
                return normalized;
-
-       // Primitive values and arrays get stable hashes
-       // by default. Lets those be stringified as-is.
        } else {
+               // Primitive values and arrays get stable hashes
+               // by default. Lets those be stringified as-is.
                return val;
        }
 };
@@ -592,11 +626,11 @@ oo.simpleArrayDifference = function ( a, b ) {
        return simpleArrayCombine( a, b, false );
 };
 
-/*global $ */
+/* global $ */
 
 oo.isPlainObject = $.isPlainObject;
 
-/*global hasOwn */
+/* global hasOwn */
 
 ( function () {
 
@@ -1091,7 +1125,18 @@ oo.isPlainObject = $.isPlainObject;
         * Don't call this directly unless you know what you're doing.
         * Use #addItems instead.
         *
-        * @private
+        * This method can be extended in child classes to produce
+        * different behavior when an item is inserted. For example,
+        * inserted items may also be attached to the DOM or may
+        * interact with some other nodes in certain ways. Extending
+        * this method is allowed, but if overriden, the aggregation
+        * of events must be preserved, or behavior of emitted events
+        * will be broken.
+        *
+        * If you are extending this method, please make sure the
+        * parent method is called.
+        *
+        * @protected
         * @param {OO.EventEmitter} item Items to add
         * @param {number} index Index to add items at
         * @return {number} The index the item was added at
@@ -1297,7 +1342,7 @@ oo.SortedEmitterList.prototype.addItems = function ( items ) {
 
                // Insert item at the insertion index
                index = this.insertItem( items[ i ], insertionIndex );
-               this.emit( 'add', items[ i ], insertionIndex );
+               this.emit( 'add', items[ i ], index );
        }
 
        return this;
@@ -1325,7 +1370,7 @@ oo.SortedEmitterList.prototype.findInsertionIndex = function ( item ) {
 
 };
 
-/*global hasOwn */
+/* global hasOwn */
 
 /**
  * @class OO.Registry
@@ -1421,8 +1466,6 @@ oo.Registry.prototype.lookup = function ( name ) {
        }
 };
 
-/*global createObject */
-
 /**
  * @class OO.Factory
  * @extends OO.Registry
@@ -1431,7 +1474,7 @@ oo.Registry.prototype.lookup = function ( name ) {
  */
 oo.Factory = function OoFactory() {
        // Parent constructor
-       oo.Factory.parent.call( this );
+       oo.Factory.super.call( this );
 };
 
 /* Inheritance */
@@ -1468,7 +1511,7 @@ oo.Factory.prototype.register = function ( constructor ) {
        }
 
        // Parent method
-       oo.Factory.parent.prototype.register.call( this, name, constructor );
+       oo.Factory.super.prototype.register.call( this, name, constructor );
 };
 
 /**
@@ -1490,7 +1533,7 @@ oo.Factory.prototype.unregister = function ( constructor ) {
        }
 
        // Parent method
-       oo.Factory.parent.prototype.unregister.call( this, name );
+       oo.Factory.super.prototype.unregister.call( this, name );
 };
 
 /**
@@ -1523,12 +1566,12 @@ oo.Factory.prototype.create = function ( name ) {
        // the constructor's prototype (which also makes it an "instanceof" the constructor),
        // then invoke the constructor with the object as context, and return it (ignoring
        // the constructor's return value).
-       obj = createObject( constructor.prototype );
+       obj = Object.create( constructor.prototype );
        constructor.apply( obj, args );
        return obj;
 };
 
-/*jshint node:true */
+/* eslint-env node */
 if ( typeof module !== 'undefined' && module.exports ) {
        module.exports = oo;
 } else {