From 979042f645bac6727cafc36c9b69c30e8cd9ceed Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Tue, 30 May 2017 16:23:58 -0700 Subject: [PATCH] Update OOjs to v2.1.0 Release notes: https://phabricator.wikimedia.org/diffusion/GOJS/browse/master/History.md;v2.1.0 Change-Id: I63fb9c2145e1c3e63ce1acf5f020e9208ca21f04 --- maintenance/resources/update-oojs.sh | 3 + resources/lib/oojs/AUTHORS.txt | 10 +++ resources/lib/oojs/LICENSE-MIT | 20 ++++++ resources/lib/oojs/README.md | 98 ++++++++++++++++++++++++++++ resources/lib/oojs/oojs.jquery.js | 77 +++++++++++++++------- 5 files changed, 184 insertions(+), 24 deletions(-) create mode 100644 resources/lib/oojs/AUTHORS.txt create mode 100644 resources/lib/oojs/LICENSE-MIT create mode 100644 resources/lib/oojs/README.md diff --git a/maintenance/resources/update-oojs.sh b/maintenance/resources/update-oojs.sh index d3e778c643..267bd96170 100755 --- a/maintenance/resources/update-oojs.sh +++ b/maintenance/resources/update-oojs.sh @@ -38,6 +38,9 @@ fi # Copy file(s) rsync --force ./node_modules/oojs/dist/oojs.jquery.js "$REPO_DIR/$TARGET_DIR" +rsync --force ./node_modules/oojs/dist/AUTHORS.txt "$REPO_DIR/$TARGET_DIR" +rsync --force ./node_modules/oojs/dist/LICENSE-MIT "$REPO_DIR/$TARGET_DIR" +rsync --force ./node_modules/oojs/dist/README.md "$REPO_DIR/$TARGET_DIR" # Clean up temporary area rm -rf "$NPM_DIR" diff --git a/resources/lib/oojs/AUTHORS.txt b/resources/lib/oojs/AUTHORS.txt new file mode 100644 index 0000000000..97fee0aeea --- /dev/null +++ b/resources/lib/oojs/AUTHORS.txt @@ -0,0 +1,10 @@ +Bartosz Dziewoński +C. Scott Ananian +David Chan +Ed Sanders +James D. Forrester +Moriel Schottlender +Ori Livneh +Roan Kattouw +Timo Tijhof +Trevor Parscal diff --git a/resources/lib/oojs/LICENSE-MIT b/resources/lib/oojs/LICENSE-MIT new file mode 100644 index 0000000000..c6bbee2be5 --- /dev/null +++ b/resources/lib/oojs/LICENSE-MIT @@ -0,0 +1,20 @@ +Copyright 2011-2017 OOjs Team and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/resources/lib/oojs/README.md b/resources/lib/oojs/README.md new file mode 100644 index 0000000000..ec14576f2f --- /dev/null +++ b/resources/lib/oojs/README.md @@ -0,0 +1,98 @@ +[![npm](https://img.shields.io/npm/v/oojs.svg?style=flat)](https://www.npmjs.com/package/oojs) [![David](https://img.shields.io/david/dev/wikimedia/oojs.svg?style=flat)](https://david-dm.org/wikimedia/oojs#info=devDependencies) + +OOjs +================= + +OOjs is a JavaScript library for working with objects. + +Key features include inheritance, mixins and utilities for working with objects. + +
+/* Example */
+( function ( oo ) {
+    function Animal() {}
+    function Magic() {}
+    function Unicorn() {
+        Animal.call( this );
+        Magic.call( this );
+    }
+    oo.inheritClass( Unicorn, Animal );
+    oo.mixinClass( Unicorn, Magic );
+}( OO ) );
+
+ +Quick start +---------- + +This library is available as an [npm](https://npmjs.org/) package! Install it right away: +
+npm install oojs
+
+ +Or clone the repo, `git clone https://phabricator.wikimedia.org/diffusion/GOJS/oojs.git`. + +ECMAScript 5 +---------- + +OOjs requires a modern ECMAScript 5 environment. It is not necessarily compatible with ES3 engines (such as for IE 6-8). For ES3 environments, the old 1.x releases are available but not recommended. + +jQuery +---------- + +If your project uses jQuery, use the optimised `oojs.jquery.js` build instead. + +This build assumes jQuery is present and omits various chunks of code in favour of references to jQuery. + +jQuery 3.0.0 or higher is required. + +Versioning +---------- + +We use the Semantic Versioning guidelines as much as possible. + +Releases will be numbered in the following format: + +`..` + +For more information on SemVer, please visit http://semver.org/. + +Bug tracker +----------- + +Found a bug? Please report it in the [issue tracker](https://phabricator.wikimedia.org/maniphest/task/edit/form/1/?projects=OOjs)! + +Release +---------- + +Release process: +
+$ cd path/to/oojs/
+$ git remote update
+$ git checkout -B release -t origin/master
+
+# Ensure tests pass
+$ npm install && npm test
+
+# Avoid using "npm version patch" because that creates
+# both a commit and a tag, and we shouldn't tag until after
+# the commit is merged.
+
+# Update release notes
+# Copy the resulting list into a new section on History.md
+$ git log --format='* %s (%aN)' --no-merges --reverse v$(node -e 'console.log(require("./package.json").version);')...HEAD
+$ edit History.md
+
+# Update the version number
+$ edit package.json
+
+$ git add -p
+$ git commit -m "Tag vX.X.X"
+$ git review
+
+# After merging:
+$ git remote update
+$ git checkout origin/master
+$ git tag "vX.X.X"
+$ git push --tags
+$ npm publish
+
diff --git a/resources/lib/oojs/oojs.jquery.js b/resources/lib/oojs/oojs.jquery.js index f93051c705..8cc6f1182d 100644 --- a/resources/lib/oojs/oojs.jquery.js +++ b/resources/lib/oojs/oojs.jquery.js @@ -1,12 +1,12 @@ /*! - * OOjs v2.0.0 optimised for jQuery + * OOjs v2.1.0 optimised for jQuery * https://www.mediawiki.org/wiki/OOjs * * Copyright 2011-2017 OOjs Team and other contributors. * Released under the MIT license * https://oojs.mit-license.org * - * Date: 2017-04-05T02:18:04Z + * Date: 2017-05-30T22:56:52Z */ ( function ( global ) { @@ -683,6 +683,24 @@ oo.isPlainObject = $.isPlainObject; } } + /** + * @private + * @param {OO.EventEmitter} ee + * @param {Function|string} method Function or method name + * @param {Object} binding + */ + function addBinding( ee, event, binding ) { + var bindings; + // Auto-initialize bindings list + if ( hasOwn.call( ee.bindings, event ) ) { + bindings = ee.bindings[ event ]; + } else { + bindings = ee.bindings[ event ] = []; + } + // Add binding + bindings.push( binding ); + } + /* Methods */ /** @@ -699,21 +717,14 @@ oo.isPlainObject = $.isPlainObject; * @chainable */ 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 +737,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 +821,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 +843,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 +869,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 +1134,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 ); @@ -1572,6 +1599,8 @@ oo.Factory.prototype.create = function ( name ) { }; /* eslint-env node */ + +/* istanbul ignore next */ if ( typeof module !== 'undefined' && module.exports ) { module.exports = oo; } else { -- 2.20.1