diff --git a/wp-includes/js/backbone.js b/wp-includes/js/backbone.js index fd64012a35..2f8db37212 100644 --- a/wp-includes/js/backbone.js +++ b/wp-includes/js/backbone.js @@ -1,4 +1,4 @@ -// Backbone.js 1.4.1 +// Backbone.js 1.5.0 // (c) 2010-2022 Jeremy Ashkenas and DocumentCloud // Backbone may be freely distributed under the MIT license. @@ -44,7 +44,7 @@ var slice = Array.prototype.slice; // Current version of the library. Keep in sync with `package.json`. - Backbone.VERSION = '1.4.1'; + Backbone.VERSION = '1.5.0'; // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns // the `$` variable. @@ -404,7 +404,11 @@ if (options.collection) this.collection = options.collection; if (options.parse) attrs = this.parse(attrs, options) || {}; var defaults = _.result(this, 'defaults'); + + // Just _.defaults would work fine, but the additional _.extends + // is in there for historical reasons. See #3843. attrs = _.defaults(_.extend({}, defaults, attrs), defaults); + this.set(attrs, options); this.changed = {}; this.initialize.apply(this, arguments); @@ -1080,9 +1084,23 @@ var collection = this; var success = options.success; options.success = function(m, resp, callbackOpts) { - if (wait) collection.add(m, callbackOpts); + if (wait) { + m.off('error', this._forwardPristineError, this); + collection.add(m, callbackOpts); + } if (success) success.call(callbackOpts.context, m, resp, callbackOpts); }; + // In case of wait:true, our collection is not listening to any + // of the model's events yet, so it will not forward the error + // event. In this special case, we need to listen for it + // separately and handle the event just once. + // (The reason we don't need to do this for the sync event is + // in the success handler above: we add the model first, which + // causes the collection to listen, and then invoke the callback + // that triggers the event.) + if (wait) { + model.once('error', this._forwardPristineError, this); + } model.save(null, options); return model; }, @@ -1177,6 +1195,7 @@ removed.push(model); this._removeReference(model, options); } + if (models.length > 0 && !options.silent) delete options.index; return removed; }, @@ -1219,8 +1238,19 @@ } } this.trigger.apply(this, arguments); - } + }, + // Internal callback method used in `create`. It serves as a + // stand-in for the `_onModelEvent` method, which is not yet bound + // during the `wait` period of the `create` call. We still want to + // forward any `'error'` event at the end of the `wait` period, + // hence a customized callback. + _forwardPristineError: function(model, collection, options) { + // Prevent double forward if the model was already in the + // collection before the call to `create`. + if (this.has(model)) return; + this._onModelEvent('error', model, collection, options); + } }); // Defining an @@iterator method implements JavaScript's Iterable protocol. @@ -1846,6 +1876,7 @@ // Is pushState desired ... is it available? this.options = _.extend({root: '/'}, this.options, options); this.root = this.options.root; + this._trailingSlash = this.options.trailingSlash; this._wantsHashChange = this.options.hashChange !== false; this._hasHashChange = 'onhashchange' in window && (document.documentMode === void 0 || document.documentMode > 7); this._useHashChange = this._wantsHashChange && this._hasHashChange; @@ -1988,9 +2019,9 @@ // Normalize the fragment. fragment = this.getFragment(fragment || ''); - // Don't include a trailing slash on the root. + // Strip trailing slash on the root unless _trailingSlash is true var rootPath = this.root; - if (fragment === '' || fragment.charAt(0) === '?') { + if (!this._trailingSlash && (fragment === '' || fragment.charAt(0) === '?')) { rootPath = rootPath.slice(0, -1) || '/'; } var url = rootPath + fragment; diff --git a/wp-includes/js/backbone.min.js b/wp-includes/js/backbone.min.js index 60ac51658e..b674cc22b7 100644 --- a/wp-includes/js/backbone.min.js +++ b/wp-includes/js/backbone.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(n){var s="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global;if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(t,e,i){s.Backbone=n(s,i,t,e)});else if("undefined"!=typeof exports){var t,e=require("underscore");try{t=require("jquery")}catch(t){}n(s,exports,e,t)}else s.Backbone=n(s,{},s._,s.jQuery||s.Zepto||s.ender||s.$)}(function(t,h,b,e){function a(t,e,i,n,s){var r,o=0;if(i&&"object"==typeof i){void 0!==n&&"context"in s&&void 0===s.context&&(s.context=n);for(r=b.keys(i);othis.length?this.length:n)<0&&(n+=this.length+1),[]),r=[],o=[],h=[],a={},u=e.add,c=e.merge,l=e.remove,d=!1,f=this.comparator&&null==n&&!1!==e.sort,p=b.isString(this.comparator)?this.comparator:null,g=0;gthis.length?this.length:n)<0&&(n+=this.length+1),[]),r=[],o=[],h=[],a={},l=e.add,c=e.merge,u=e.remove,d=!1,f=this.comparator&&null==n&&!1!==e.sort,p=b.isString(this.comparator)?this.comparator:null,g=0;gadd_data( 'json2', 'conditional', 'lt IE 8' ); $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.4', 1 ); - $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.4.1', 1 ); + $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.5.0', 1 ); $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 ); did_action( 'init' ) && $scripts->localize( diff --git a/wp-includes/version.php b/wp-includes/version.php index 531f2a88c7..c7b284e966 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56390'; +$wp_version = '6.4-alpha-56391'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.