Edit File by line
/home/barbar84/www/wp-inclu.../js
File: backbone.js
// Returns `true` if the model is in the collection.
[1000] Fix | Delete
has: function(obj) {
[1001] Fix | Delete
return this.get(obj) != null;
[1002] Fix | Delete
},
[1003] Fix | Delete
[1004] Fix | Delete
// Get the model at the given index.
[1005] Fix | Delete
at: function(index) {
[1006] Fix | Delete
if (index < 0) index += this.length;
[1007] Fix | Delete
return this.models[index];
[1008] Fix | Delete
},
[1009] Fix | Delete
[1010] Fix | Delete
// Return models with matching attributes. Useful for simple cases of
[1011] Fix | Delete
// `filter`.
[1012] Fix | Delete
where: function(attrs, first) {
[1013] Fix | Delete
return this[first ? 'find' : 'filter'](attrs);
[1014] Fix | Delete
},
[1015] Fix | Delete
[1016] Fix | Delete
// Return the first model with matching attributes. Useful for simple cases
[1017] Fix | Delete
// of `find`.
[1018] Fix | Delete
findWhere: function(attrs) {
[1019] Fix | Delete
return this.where(attrs, true);
[1020] Fix | Delete
},
[1021] Fix | Delete
[1022] Fix | Delete
// Force the collection to re-sort itself. You don't need to call this under
[1023] Fix | Delete
// normal circumstances, as the set will maintain sort order as each item
[1024] Fix | Delete
// is added.
[1025] Fix | Delete
sort: function(options) {
[1026] Fix | Delete
var comparator = this.comparator;
[1027] Fix | Delete
if (!comparator) throw new Error('Cannot sort a set without a comparator');
[1028] Fix | Delete
options || (options = {});
[1029] Fix | Delete
[1030] Fix | Delete
var length = comparator.length;
[1031] Fix | Delete
if (_.isFunction(comparator)) comparator = comparator.bind(this);
[1032] Fix | Delete
[1033] Fix | Delete
// Run sort based on type of `comparator`.
[1034] Fix | Delete
if (length === 1 || _.isString(comparator)) {
[1035] Fix | Delete
this.models = this.sortBy(comparator);
[1036] Fix | Delete
} else {
[1037] Fix | Delete
this.models.sort(comparator);
[1038] Fix | Delete
}
[1039] Fix | Delete
if (!options.silent) this.trigger('sort', this, options);
[1040] Fix | Delete
return this;
[1041] Fix | Delete
},
[1042] Fix | Delete
[1043] Fix | Delete
// Pluck an attribute from each model in the collection.
[1044] Fix | Delete
pluck: function(attr) {
[1045] Fix | Delete
return this.map(attr + '');
[1046] Fix | Delete
},
[1047] Fix | Delete
[1048] Fix | Delete
// Fetch the default set of models for this collection, resetting the
[1049] Fix | Delete
// collection when they arrive. If `reset: true` is passed, the response
[1050] Fix | Delete
// data will be passed through the `reset` method instead of `set`.
[1051] Fix | Delete
fetch: function(options) {
[1052] Fix | Delete
options = _.extend({parse: true}, options);
[1053] Fix | Delete
var success = options.success;
[1054] Fix | Delete
var collection = this;
[1055] Fix | Delete
options.success = function(resp) {
[1056] Fix | Delete
var method = options.reset ? 'reset' : 'set';
[1057] Fix | Delete
collection[method](resp, options);
[1058] Fix | Delete
if (success) success.call(options.context, collection, resp, options);
[1059] Fix | Delete
collection.trigger('sync', collection, resp, options);
[1060] Fix | Delete
};
[1061] Fix | Delete
wrapError(this, options);
[1062] Fix | Delete
return this.sync('read', this, options);
[1063] Fix | Delete
},
[1064] Fix | Delete
[1065] Fix | Delete
// Create a new instance of a model in this collection. Add the model to the
[1066] Fix | Delete
// collection immediately, unless `wait: true` is passed, in which case we
[1067] Fix | Delete
// wait for the server to agree.
[1068] Fix | Delete
create: function(model, options) {
[1069] Fix | Delete
options = options ? _.clone(options) : {};
[1070] Fix | Delete
var wait = options.wait;
[1071] Fix | Delete
model = this._prepareModel(model, options);
[1072] Fix | Delete
if (!model) return false;
[1073] Fix | Delete
if (!wait) this.add(model, options);
[1074] Fix | Delete
var collection = this;
[1075] Fix | Delete
var success = options.success;
[1076] Fix | Delete
options.success = function(m, resp, callbackOpts) {
[1077] Fix | Delete
if (wait) collection.add(m, callbackOpts);
[1078] Fix | Delete
if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
[1079] Fix | Delete
};
[1080] Fix | Delete
model.save(null, options);
[1081] Fix | Delete
return model;
[1082] Fix | Delete
},
[1083] Fix | Delete
[1084] Fix | Delete
// **parse** converts a response into a list of models to be added to the
[1085] Fix | Delete
// collection. The default implementation is just to pass it through.
[1086] Fix | Delete
parse: function(resp, options) {
[1087] Fix | Delete
return resp;
[1088] Fix | Delete
},
[1089] Fix | Delete
[1090] Fix | Delete
// Create a new collection with an identical list of models as this one.
[1091] Fix | Delete
clone: function() {
[1092] Fix | Delete
return new this.constructor(this.models, {
[1093] Fix | Delete
model: this.model,
[1094] Fix | Delete
comparator: this.comparator
[1095] Fix | Delete
});
[1096] Fix | Delete
},
[1097] Fix | Delete
[1098] Fix | Delete
// Define how to uniquely identify models in the collection.
[1099] Fix | Delete
modelId: function(attrs) {
[1100] Fix | Delete
return attrs[this.model.prototype.idAttribute || 'id'];
[1101] Fix | Delete
},
[1102] Fix | Delete
[1103] Fix | Delete
// Get an iterator of all models in this collection.
[1104] Fix | Delete
values: function() {
[1105] Fix | Delete
return new CollectionIterator(this, ITERATOR_VALUES);
[1106] Fix | Delete
},
[1107] Fix | Delete
[1108] Fix | Delete
// Get an iterator of all model IDs in this collection.
[1109] Fix | Delete
keys: function() {
[1110] Fix | Delete
return new CollectionIterator(this, ITERATOR_KEYS);
[1111] Fix | Delete
},
[1112] Fix | Delete
[1113] Fix | Delete
// Get an iterator of all [ID, model] tuples in this collection.
[1114] Fix | Delete
entries: function() {
[1115] Fix | Delete
return new CollectionIterator(this, ITERATOR_KEYSVALUES);
[1116] Fix | Delete
},
[1117] Fix | Delete
[1118] Fix | Delete
// Private method to reset all internal state. Called when the collection
[1119] Fix | Delete
// is first initialized or reset.
[1120] Fix | Delete
_reset: function() {
[1121] Fix | Delete
this.length = 0;
[1122] Fix | Delete
this.models = [];
[1123] Fix | Delete
this._byId = {};
[1124] Fix | Delete
},
[1125] Fix | Delete
[1126] Fix | Delete
// Prepare a hash of attributes (or other model) to be added to this
[1127] Fix | Delete
// collection.
[1128] Fix | Delete
_prepareModel: function(attrs, options) {
[1129] Fix | Delete
if (this._isModel(attrs)) {
[1130] Fix | Delete
if (!attrs.collection) attrs.collection = this;
[1131] Fix | Delete
return attrs;
[1132] Fix | Delete
}
[1133] Fix | Delete
options = options ? _.clone(options) : {};
[1134] Fix | Delete
options.collection = this;
[1135] Fix | Delete
var model = new this.model(attrs, options);
[1136] Fix | Delete
if (!model.validationError) return model;
[1137] Fix | Delete
this.trigger('invalid', this, model.validationError, options);
[1138] Fix | Delete
return false;
[1139] Fix | Delete
},
[1140] Fix | Delete
[1141] Fix | Delete
// Internal method called by both remove and set.
[1142] Fix | Delete
_removeModels: function(models, options) {
[1143] Fix | Delete
var removed = [];
[1144] Fix | Delete
for (var i = 0; i < models.length; i++) {
[1145] Fix | Delete
var model = this.get(models[i]);
[1146] Fix | Delete
if (!model) continue;
[1147] Fix | Delete
[1148] Fix | Delete
var index = this.indexOf(model);
[1149] Fix | Delete
this.models.splice(index, 1);
[1150] Fix | Delete
this.length--;
[1151] Fix | Delete
[1152] Fix | Delete
// Remove references before triggering 'remove' event to prevent an
[1153] Fix | Delete
// infinite loop. #3693
[1154] Fix | Delete
delete this._byId[model.cid];
[1155] Fix | Delete
var id = this.modelId(model.attributes);
[1156] Fix | Delete
if (id != null) delete this._byId[id];
[1157] Fix | Delete
[1158] Fix | Delete
if (!options.silent) {
[1159] Fix | Delete
options.index = index;
[1160] Fix | Delete
model.trigger('remove', model, this, options);
[1161] Fix | Delete
}
[1162] Fix | Delete
[1163] Fix | Delete
removed.push(model);
[1164] Fix | Delete
this._removeReference(model, options);
[1165] Fix | Delete
}
[1166] Fix | Delete
return removed;
[1167] Fix | Delete
},
[1168] Fix | Delete
[1169] Fix | Delete
// Method for checking whether an object should be considered a model for
[1170] Fix | Delete
// the purposes of adding to the collection.
[1171] Fix | Delete
_isModel: function(model) {
[1172] Fix | Delete
return model instanceof Model;
[1173] Fix | Delete
},
[1174] Fix | Delete
[1175] Fix | Delete
// Internal method to create a model's ties to a collection.
[1176] Fix | Delete
_addReference: function(model, options) {
[1177] Fix | Delete
this._byId[model.cid] = model;
[1178] Fix | Delete
var id = this.modelId(model.attributes);
[1179] Fix | Delete
if (id != null) this._byId[id] = model;
[1180] Fix | Delete
model.on('all', this._onModelEvent, this);
[1181] Fix | Delete
},
[1182] Fix | Delete
[1183] Fix | Delete
// Internal method to sever a model's ties to a collection.
[1184] Fix | Delete
_removeReference: function(model, options) {
[1185] Fix | Delete
delete this._byId[model.cid];
[1186] Fix | Delete
var id = this.modelId(model.attributes);
[1187] Fix | Delete
if (id != null) delete this._byId[id];
[1188] Fix | Delete
if (this === model.collection) delete model.collection;
[1189] Fix | Delete
model.off('all', this._onModelEvent, this);
[1190] Fix | Delete
},
[1191] Fix | Delete
[1192] Fix | Delete
// Internal method called every time a model in the set fires an event.
[1193] Fix | Delete
// Sets need to update their indexes when models change ids. All other
[1194] Fix | Delete
// events simply proxy through. "add" and "remove" events that originate
[1195] Fix | Delete
// in other collections are ignored.
[1196] Fix | Delete
_onModelEvent: function(event, model, collection, options) {
[1197] Fix | Delete
if (model) {
[1198] Fix | Delete
if ((event === 'add' || event === 'remove') && collection !== this) return;
[1199] Fix | Delete
if (event === 'destroy') this.remove(model, options);
[1200] Fix | Delete
if (event === 'change') {
[1201] Fix | Delete
var prevId = this.modelId(model.previousAttributes());
[1202] Fix | Delete
var id = this.modelId(model.attributes);
[1203] Fix | Delete
if (prevId !== id) {
[1204] Fix | Delete
if (prevId != null) delete this._byId[prevId];
[1205] Fix | Delete
if (id != null) this._byId[id] = model;
[1206] Fix | Delete
}
[1207] Fix | Delete
}
[1208] Fix | Delete
}
[1209] Fix | Delete
this.trigger.apply(this, arguments);
[1210] Fix | Delete
}
[1211] Fix | Delete
[1212] Fix | Delete
});
[1213] Fix | Delete
[1214] Fix | Delete
// Defining an @@iterator method implements JavaScript's Iterable protocol.
[1215] Fix | Delete
// In modern ES2015 browsers, this value is found at Symbol.iterator.
[1216] Fix | Delete
/* global Symbol */
[1217] Fix | Delete
var $$iterator = typeof Symbol === 'function' && Symbol.iterator;
[1218] Fix | Delete
if ($$iterator) {
[1219] Fix | Delete
Collection.prototype[$$iterator] = Collection.prototype.values;
[1220] Fix | Delete
}
[1221] Fix | Delete
[1222] Fix | Delete
// CollectionIterator
[1223] Fix | Delete
// ------------------
[1224] Fix | Delete
[1225] Fix | Delete
// A CollectionIterator implements JavaScript's Iterator protocol, allowing the
[1226] Fix | Delete
// use of `for of` loops in modern browsers and interoperation between
[1227] Fix | Delete
// Backbone.Collection and other JavaScript functions and third-party libraries
[1228] Fix | Delete
// which can operate on Iterables.
[1229] Fix | Delete
var CollectionIterator = function(collection, kind) {
[1230] Fix | Delete
this._collection = collection;
[1231] Fix | Delete
this._kind = kind;
[1232] Fix | Delete
this._index = 0;
[1233] Fix | Delete
};
[1234] Fix | Delete
[1235] Fix | Delete
// This "enum" defines the three possible kinds of values which can be emitted
[1236] Fix | Delete
// by a CollectionIterator that correspond to the values(), keys() and entries()
[1237] Fix | Delete
// methods on Collection, respectively.
[1238] Fix | Delete
var ITERATOR_VALUES = 1;
[1239] Fix | Delete
var ITERATOR_KEYS = 2;
[1240] Fix | Delete
var ITERATOR_KEYSVALUES = 3;
[1241] Fix | Delete
[1242] Fix | Delete
// All Iterators should themselves be Iterable.
[1243] Fix | Delete
if ($$iterator) {
[1244] Fix | Delete
CollectionIterator.prototype[$$iterator] = function() {
[1245] Fix | Delete
return this;
[1246] Fix | Delete
};
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
CollectionIterator.prototype.next = function() {
[1250] Fix | Delete
if (this._collection) {
[1251] Fix | Delete
[1252] Fix | Delete
// Only continue iterating if the iterated collection is long enough.
[1253] Fix | Delete
if (this._index < this._collection.length) {
[1254] Fix | Delete
var model = this._collection.at(this._index);
[1255] Fix | Delete
this._index++;
[1256] Fix | Delete
[1257] Fix | Delete
// Construct a value depending on what kind of values should be iterated.
[1258] Fix | Delete
var value;
[1259] Fix | Delete
if (this._kind === ITERATOR_VALUES) {
[1260] Fix | Delete
value = model;
[1261] Fix | Delete
} else {
[1262] Fix | Delete
var id = this._collection.modelId(model.attributes);
[1263] Fix | Delete
if (this._kind === ITERATOR_KEYS) {
[1264] Fix | Delete
value = id;
[1265] Fix | Delete
} else { // ITERATOR_KEYSVALUES
[1266] Fix | Delete
value = [id, model];
[1267] Fix | Delete
}
[1268] Fix | Delete
}
[1269] Fix | Delete
return {value: value, done: false};
[1270] Fix | Delete
}
[1271] Fix | Delete
[1272] Fix | Delete
// Once exhausted, remove the reference to the collection so future
[1273] Fix | Delete
// calls to the next method always return done.
[1274] Fix | Delete
this._collection = void 0;
[1275] Fix | Delete
}
[1276] Fix | Delete
[1277] Fix | Delete
return {value: void 0, done: true};
[1278] Fix | Delete
};
[1279] Fix | Delete
[1280] Fix | Delete
// Backbone.View
[1281] Fix | Delete
// -------------
[1282] Fix | Delete
[1283] Fix | Delete
// Backbone Views are almost more convention than they are actual code. A View
[1284] Fix | Delete
// is simply a JavaScript object that represents a logical chunk of UI in the
[1285] Fix | Delete
// DOM. This might be a single item, an entire list, a sidebar or panel, or
[1286] Fix | Delete
// even the surrounding frame which wraps your whole app. Defining a chunk of
[1287] Fix | Delete
// UI as a **View** allows you to define your DOM events declaratively, without
[1288] Fix | Delete
// having to worry about render order ... and makes it easy for the view to
[1289] Fix | Delete
// react to specific changes in the state of your models.
[1290] Fix | Delete
[1291] Fix | Delete
// Creating a Backbone.View creates its initial element outside of the DOM,
[1292] Fix | Delete
// if an existing element is not provided...
[1293] Fix | Delete
var View = Backbone.View = function(options) {
[1294] Fix | Delete
this.cid = _.uniqueId('view');
[1295] Fix | Delete
this.preinitialize.apply(this, arguments);
[1296] Fix | Delete
_.extend(this, _.pick(options, viewOptions));
[1297] Fix | Delete
this._ensureElement();
[1298] Fix | Delete
this.initialize.apply(this, arguments);
[1299] Fix | Delete
};
[1300] Fix | Delete
[1301] Fix | Delete
// Cached regex to split keys for `delegate`.
[1302] Fix | Delete
var delegateEventSplitter = /^(\S+)\s*(.*)$/;
[1303] Fix | Delete
[1304] Fix | Delete
// List of view options to be set as properties.
[1305] Fix | Delete
var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
[1306] Fix | Delete
[1307] Fix | Delete
// Set up all inheritable **Backbone.View** properties and methods.
[1308] Fix | Delete
_.extend(View.prototype, Events, {
[1309] Fix | Delete
[1310] Fix | Delete
// The default `tagName` of a View's element is `"div"`.
[1311] Fix | Delete
tagName: 'div',
[1312] Fix | Delete
[1313] Fix | Delete
// jQuery delegate for element lookup, scoped to DOM elements within the
[1314] Fix | Delete
// current view. This should be preferred to global lookups where possible.
[1315] Fix | Delete
$: function(selector) {
[1316] Fix | Delete
return this.$el.find(selector);
[1317] Fix | Delete
},
[1318] Fix | Delete
[1319] Fix | Delete
// preinitialize is an empty function by default. You can override it with a function
[1320] Fix | Delete
// or object. preinitialize will run before any instantiation logic is run in the View
[1321] Fix | Delete
preinitialize: function(){},
[1322] Fix | Delete
[1323] Fix | Delete
// Initialize is an empty function by default. Override it with your own
[1324] Fix | Delete
// initialization logic.
[1325] Fix | Delete
initialize: function(){},
[1326] Fix | Delete
[1327] Fix | Delete
// **render** is the core function that your view should override, in order
[1328] Fix | Delete
// to populate its element (`this.el`), with the appropriate HTML. The
[1329] Fix | Delete
// convention is for **render** to always return `this`.
[1330] Fix | Delete
render: function() {
[1331] Fix | Delete
return this;
[1332] Fix | Delete
},
[1333] Fix | Delete
[1334] Fix | Delete
// Remove this view by taking the element out of the DOM, and removing any
[1335] Fix | Delete
// applicable Backbone.Events listeners.
[1336] Fix | Delete
remove: function() {
[1337] Fix | Delete
this._removeElement();
[1338] Fix | Delete
this.stopListening();
[1339] Fix | Delete
return this;
[1340] Fix | Delete
},
[1341] Fix | Delete
[1342] Fix | Delete
// Remove this view's element from the document and all event listeners
[1343] Fix | Delete
// attached to it. Exposed for subclasses using an alternative DOM
[1344] Fix | Delete
// manipulation API.
[1345] Fix | Delete
_removeElement: function() {
[1346] Fix | Delete
this.$el.remove();
[1347] Fix | Delete
},
[1348] Fix | Delete
[1349] Fix | Delete
// Change the view's element (`this.el` property) and re-delegate the
[1350] Fix | Delete
// view's events on the new element.
[1351] Fix | Delete
setElement: function(element) {
[1352] Fix | Delete
this.undelegateEvents();
[1353] Fix | Delete
this._setElement(element);
[1354] Fix | Delete
this.delegateEvents();
[1355] Fix | Delete
return this;
[1356] Fix | Delete
},
[1357] Fix | Delete
[1358] Fix | Delete
// Creates the `this.el` and `this.$el` references for this view using the
[1359] Fix | Delete
// given `el`. `el` can be a CSS selector or an HTML string, a jQuery
[1360] Fix | Delete
// context or an element. Subclasses can override this to utilize an
[1361] Fix | Delete
// alternative DOM manipulation API and are only required to set the
[1362] Fix | Delete
// `this.el` property.
[1363] Fix | Delete
_setElement: function(el) {
[1364] Fix | Delete
this.$el = el instanceof Backbone.$ ? el : Backbone.$(el);
[1365] Fix | Delete
this.el = this.$el[0];
[1366] Fix | Delete
},
[1367] Fix | Delete
[1368] Fix | Delete
// Set callbacks, where `this.events` is a hash of
[1369] Fix | Delete
//
[1370] Fix | Delete
// *{"event selector": "callback"}*
[1371] Fix | Delete
//
[1372] Fix | Delete
// {
[1373] Fix | Delete
// 'mousedown .title': 'edit',
[1374] Fix | Delete
// 'click .button': 'save',
[1375] Fix | Delete
// 'click .open': function(e) { ... }
[1376] Fix | Delete
// }
[1377] Fix | Delete
//
[1378] Fix | Delete
// pairs. Callbacks will be bound to the view, with `this` set properly.
[1379] Fix | Delete
// Uses event delegation for efficiency.
[1380] Fix | Delete
// Omitting the selector binds the event to `this.el`.
[1381] Fix | Delete
delegateEvents: function(events) {
[1382] Fix | Delete
events || (events = _.result(this, 'events'));
[1383] Fix | Delete
if (!events) return this;
[1384] Fix | Delete
this.undelegateEvents();
[1385] Fix | Delete
for (var key in events) {
[1386] Fix | Delete
var method = events[key];
[1387] Fix | Delete
if (!_.isFunction(method)) method = this[method];
[1388] Fix | Delete
if (!method) continue;
[1389] Fix | Delete
var match = key.match(delegateEventSplitter);
[1390] Fix | Delete
this.delegate(match[1], match[2], method.bind(this));
[1391] Fix | Delete
}
[1392] Fix | Delete
return this;
[1393] Fix | Delete
},
[1394] Fix | Delete
[1395] Fix | Delete
// Add a single event listener to the view's element (or a child element
[1396] Fix | Delete
// using `selector`). This only works for delegate-able events: not `focus`,
[1397] Fix | Delete
// `blur`, and not `change`, `submit`, and `reset` in Internet Explorer.
[1398] Fix | Delete
delegate: function(eventName, selector, listener) {
[1399] Fix | Delete
this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);
[1400] Fix | Delete
return this;
[1401] Fix | Delete
},
[1402] Fix | Delete
[1403] Fix | Delete
// Clears all callbacks previously bound to the view by `delegateEvents`.
[1404] Fix | Delete
// You usually don't need to use this, but may wish to if you have multiple
[1405] Fix | Delete
// Backbone views attached to the same DOM element.
[1406] Fix | Delete
undelegateEvents: function() {
[1407] Fix | Delete
if (this.$el) this.$el.off('.delegateEvents' + this.cid);
[1408] Fix | Delete
return this;
[1409] Fix | Delete
},
[1410] Fix | Delete
[1411] Fix | Delete
// A finer-grained `undelegateEvents` for removing a single delegated event.
[1412] Fix | Delete
// `selector` and `listener` are both optional.
[1413] Fix | Delete
undelegate: function(eventName, selector, listener) {
[1414] Fix | Delete
this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
[1415] Fix | Delete
return this;
[1416] Fix | Delete
},
[1417] Fix | Delete
[1418] Fix | Delete
// Produces a DOM element to be assigned to your view. Exposed for
[1419] Fix | Delete
// subclasses using an alternative DOM manipulation API.
[1420] Fix | Delete
_createElement: function(tagName) {
[1421] Fix | Delete
return document.createElement(tagName);
[1422] Fix | Delete
},
[1423] Fix | Delete
[1424] Fix | Delete
// Ensure that the View has a DOM element to render into.
[1425] Fix | Delete
// If `this.el` is a string, pass it through `$()`, take the first
[1426] Fix | Delete
// matching element, and re-assign it to `el`. Otherwise, create
[1427] Fix | Delete
// an element from the `id`, `className` and `tagName` properties.
[1428] Fix | Delete
_ensureElement: function() {
[1429] Fix | Delete
if (!this.el) {
[1430] Fix | Delete
var attrs = _.extend({}, _.result(this, 'attributes'));
[1431] Fix | Delete
if (this.id) attrs.id = _.result(this, 'id');
[1432] Fix | Delete
if (this.className) attrs['class'] = _.result(this, 'className');
[1433] Fix | Delete
this.setElement(this._createElement(_.result(this, 'tagName')));
[1434] Fix | Delete
this._setAttributes(attrs);
[1435] Fix | Delete
} else {
[1436] Fix | Delete
this.setElement(_.result(this, 'el'));
[1437] Fix | Delete
}
[1438] Fix | Delete
},
[1439] Fix | Delete
[1440] Fix | Delete
// Set attributes from a hash on this view's element. Exposed for
[1441] Fix | Delete
// subclasses using an alternative DOM manipulation API.
[1442] Fix | Delete
_setAttributes: function(attributes) {
[1443] Fix | Delete
this.$el.attr(attributes);
[1444] Fix | Delete
}
[1445] Fix | Delete
[1446] Fix | Delete
});
[1447] Fix | Delete
[1448] Fix | Delete
// Proxy Backbone class methods to Underscore functions, wrapping the model's
[1449] Fix | Delete
// `attributes` object or collection's `models` array behind the scenes.
[1450] Fix | Delete
//
[1451] Fix | Delete
// collection.filter(function(model) { return model.get('age') > 10 });
[1452] Fix | Delete
// collection.each(this.addView);
[1453] Fix | Delete
//
[1454] Fix | Delete
// `Function#apply` can be slow so we use the method's arg count, if we know it.
[1455] Fix | Delete
var addMethod = function(base, length, method, attribute) {
[1456] Fix | Delete
switch (length) {
[1457] Fix | Delete
case 1: return function() {
[1458] Fix | Delete
return base[method](this[attribute]);
[1459] Fix | Delete
};
[1460] Fix | Delete
case 2: return function(value) {
[1461] Fix | Delete
return base[method](this[attribute], value);
[1462] Fix | Delete
};
[1463] Fix | Delete
case 3: return function(iteratee, context) {
[1464] Fix | Delete
return base[method](this[attribute], cb(iteratee, this), context);
[1465] Fix | Delete
};
[1466] Fix | Delete
case 4: return function(iteratee, defaultVal, context) {
[1467] Fix | Delete
return base[method](this[attribute], cb(iteratee, this), defaultVal, context);
[1468] Fix | Delete
};
[1469] Fix | Delete
default: return function() {
[1470] Fix | Delete
var args = slice.call(arguments);
[1471] Fix | Delete
args.unshift(this[attribute]);
[1472] Fix | Delete
return base[method].apply(base, args);
[1473] Fix | Delete
};
[1474] Fix | Delete
}
[1475] Fix | Delete
};
[1476] Fix | Delete
[1477] Fix | Delete
var addUnderscoreMethods = function(Class, base, methods, attribute) {
[1478] Fix | Delete
_.each(methods, function(length, method) {
[1479] Fix | Delete
if (base[method]) Class.prototype[method] = addMethod(base, length, method, attribute);
[1480] Fix | Delete
});
[1481] Fix | Delete
};
[1482] Fix | Delete
[1483] Fix | Delete
// Support `collection.sortBy('attr')` and `collection.findWhere({id: 1})`.
[1484] Fix | Delete
var cb = function(iteratee, instance) {
[1485] Fix | Delete
if (_.isFunction(iteratee)) return iteratee;
[1486] Fix | Delete
if (_.isObject(iteratee) && !instance._isModel(iteratee)) return modelMatcher(iteratee);
[1487] Fix | Delete
if (_.isString(iteratee)) return function(model) { return model.get(iteratee); };
[1488] Fix | Delete
return iteratee;
[1489] Fix | Delete
};
[1490] Fix | Delete
var modelMatcher = function(attrs) {
[1491] Fix | Delete
var matcher = _.matches(attrs);
[1492] Fix | Delete
return function(model) {
[1493] Fix | Delete
return matcher(model.attributes);
[1494] Fix | Delete
};
[1495] Fix | Delete
};
[1496] Fix | Delete
[1497] Fix | Delete
// Underscore methods that we want to implement on the Collection.
[1498] Fix | Delete
// 90% of the core usefulness of Backbone Collections is actually implemented
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function