--- a/wp/wp-includes/js/backbone.js Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/js/backbone.js Tue Sep 27 16:37:53 2022 +0200
@@ -1,6 +1,6 @@
-// Backbone.js 1.4.0
+// Backbone.js 1.4.1
-// (c) 2010-2019 Jeremy Ashkenas and DocumentCloud
+// (c) 2010-2022 Jeremy Ashkenas and DocumentCloud
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
@@ -44,7 +44,7 @@
var slice = Array.prototype.slice;
// Current version of the library. Keep in sync with `package.json`.
- Backbone.VERSION = '1.4.0';
+ Backbone.VERSION = '1.4.1';
// For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
// the `$` variable.
@@ -516,7 +516,11 @@
}
// Update the `id`.
- if (this.idAttribute in attrs) this.id = this.get(this.idAttribute);
+ if (this.idAttribute in attrs) {
+ var prevId = this.id;
+ this.id = this.get(this.idAttribute);
+ this.trigger('changeId', this, prevId, options);
+ }
// Trigger all relevant attribute changes.
if (!silent) {
@@ -994,7 +998,7 @@
get: function(obj) {
if (obj == null) return void 0;
return this._byId[obj] ||
- this._byId[this.modelId(this._isModel(obj) ? obj.attributes : obj)] ||
+ this._byId[this.modelId(this._isModel(obj) ? obj.attributes : obj, obj.idAttribute)] ||
obj.cid && this._byId[obj.cid];
},
@@ -1098,8 +1102,8 @@
},
// Define how to uniquely identify models in the collection.
- modelId: function(attrs) {
- return attrs[this.model.prototype.idAttribute || 'id'];
+ modelId: function(attrs, idAttribute) {
+ return attrs[idAttribute || this.model.prototype.idAttribute || 'id'];
},
// Get an iterator of all models in this collection.
@@ -1134,7 +1138,15 @@
}
options = options ? _.clone(options) : {};
options.collection = this;
- var model = new this.model(attrs, options);
+
+ var model;
+ if (this.model.prototype) {
+ model = new this.model(attrs, options);
+ } else {
+ // ES class methods didn't have prototype
+ model = this.model(attrs, options);
+ }
+
if (!model.validationError) return model;
this.trigger('invalid', this, model.validationError, options);
return false;
@@ -1154,7 +1166,7 @@
// Remove references before triggering 'remove' event to prevent an
// infinite loop. #3693
delete this._byId[model.cid];
- var id = this.modelId(model.attributes);
+ var id = this.modelId(model.attributes, model.idAttribute);
if (id != null) delete this._byId[id];
if (!options.silent) {
@@ -1177,7 +1189,7 @@
// Internal method to create a model's ties to a collection.
_addReference: function(model, options) {
this._byId[model.cid] = model;
- var id = this.modelId(model.attributes);
+ var id = this.modelId(model.attributes, model.idAttribute);
if (id != null) this._byId[id] = model;
model.on('all', this._onModelEvent, this);
},
@@ -1185,7 +1197,7 @@
// Internal method to sever a model's ties to a collection.
_removeReference: function(model, options) {
delete this._byId[model.cid];
- var id = this.modelId(model.attributes);
+ var id = this.modelId(model.attributes, model.idAttribute);
if (id != null) delete this._byId[id];
if (this === model.collection) delete model.collection;
model.off('all', this._onModelEvent, this);
@@ -1199,13 +1211,11 @@
if (model) {
if ((event === 'add' || event === 'remove') && collection !== this) return;
if (event === 'destroy') this.remove(model, options);
- if (event === 'change') {
- var prevId = this.modelId(model.previousAttributes());
- var id = this.modelId(model.attributes);
- if (prevId !== id) {
- if (prevId != null) delete this._byId[prevId];
- if (id != null) this._byId[id] = model;
- }
+ if (event === 'changeId') {
+ var prevId = this.modelId(model.previousAttributes(), model.idAttribute);
+ var id = this.modelId(model.attributes, model.idAttribute);
+ if (prevId != null) delete this._byId[prevId];
+ if (id != null) this._byId[id] = model;
}
}
this.trigger.apply(this, arguments);
@@ -1261,7 +1271,7 @@
if (this._kind === ITERATOR_VALUES) {
value = model;
} else {
- var id = this._collection.modelId(model.attributes);
+ var id = this._collection.modelId(model.attributes, model.idAttribute);
if (this._kind === ITERATOR_KEYS) {
value = id;
} else { // ITERATOR_KEYSVALUES
@@ -1615,11 +1625,11 @@
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
var methodMap = {
- create: 'POST',
- update: 'PUT',
- patch: 'PATCH',
- delete: 'DELETE',
- read: 'GET'
+ 'create': 'POST',
+ 'update': 'PUT',
+ 'patch': 'PATCH',
+ 'delete': 'DELETE',
+ 'read': 'GET'
};
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
@@ -1712,11 +1722,11 @@
// against the current location hash.
_routeToRegExp: function(route) {
route = route.replace(escapeRegExp, '\\$&')
- .replace(optionalParam, '(?:$1)?')
- .replace(namedParam, function(match, optional) {
- return optional ? match : '([^/?]+)';
- })
- .replace(splatParam, '([^?]*?)');
+ .replace(optionalParam, '(?:$1)?')
+ .replace(namedParam, function(match, optional) {
+ return optional ? match : '([^/?]+)';
+ })
+ .replace(splatParam, '([^?]*?)');
return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$');
},