Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: backbone.js
// Backbone.js 1.4.0
[0] Fix | Delete
[1] Fix | Delete
// (c) 2010-2019 Jeremy Ashkenas and DocumentCloud
[2] Fix | Delete
// Backbone may be freely distributed under the MIT license.
[3] Fix | Delete
// For all details and documentation:
[4] Fix | Delete
// http://backbonejs.org
[5] Fix | Delete
[6] Fix | Delete
(function(factory) {
[7] Fix | Delete
[8] Fix | Delete
// Establish the root object, `window` (`self`) in the browser, or `global` on the server.
[9] Fix | Delete
// We use `self` instead of `window` for `WebWorker` support.
[10] Fix | Delete
var root = typeof self == 'object' && self.self === self && self ||
[11] Fix | Delete
typeof global == 'object' && global.global === global && global;
[12] Fix | Delete
[13] Fix | Delete
// Set up Backbone appropriately for the environment. Start with AMD.
[14] Fix | Delete
if (typeof define === 'function' && define.amd) {
[15] Fix | Delete
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
[16] Fix | Delete
// Export global even in AMD case in case this script is loaded with
[17] Fix | Delete
// others that may still expect a global Backbone.
[18] Fix | Delete
root.Backbone = factory(root, exports, _, $);
[19] Fix | Delete
});
[20] Fix | Delete
[21] Fix | Delete
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
[22] Fix | Delete
} else if (typeof exports !== 'undefined') {
[23] Fix | Delete
var _ = require('underscore'), $;
[24] Fix | Delete
try { $ = require('jquery'); } catch (e) {}
[25] Fix | Delete
factory(root, exports, _, $);
[26] Fix | Delete
[27] Fix | Delete
// Finally, as a browser global.
[28] Fix | Delete
} else {
[29] Fix | Delete
root.Backbone = factory(root, {}, root._, root.jQuery || root.Zepto || root.ender || root.$);
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
})(function(root, Backbone, _, $) {
[33] Fix | Delete
[34] Fix | Delete
// Initial Setup
[35] Fix | Delete
// -------------
[36] Fix | Delete
[37] Fix | Delete
// Save the previous value of the `Backbone` variable, so that it can be
[38] Fix | Delete
// restored later on, if `noConflict` is used.
[39] Fix | Delete
var previousBackbone = root.Backbone;
[40] Fix | Delete
[41] Fix | Delete
// Create a local reference to a common array method we'll want to use later.
[42] Fix | Delete
var slice = Array.prototype.slice;
[43] Fix | Delete
[44] Fix | Delete
// Current version of the library. Keep in sync with `package.json`.
[45] Fix | Delete
Backbone.VERSION = '1.4.0';
[46] Fix | Delete
[47] Fix | Delete
// For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
[48] Fix | Delete
// the `$` variable.
[49] Fix | Delete
Backbone.$ = $;
[50] Fix | Delete
[51] Fix | Delete
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
[52] Fix | Delete
// to its previous owner. Returns a reference to this Backbone object.
[53] Fix | Delete
Backbone.noConflict = function() {
[54] Fix | Delete
root.Backbone = previousBackbone;
[55] Fix | Delete
return this;
[56] Fix | Delete
};
[57] Fix | Delete
[58] Fix | Delete
// Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
[59] Fix | Delete
// will fake `"PATCH"`, `"PUT"` and `"DELETE"` requests via the `_method` parameter and
[60] Fix | Delete
// set a `X-Http-Method-Override` header.
[61] Fix | Delete
Backbone.emulateHTTP = false;
[62] Fix | Delete
[63] Fix | Delete
// Turn on `emulateJSON` to support legacy servers that can't deal with direct
[64] Fix | Delete
// `application/json` requests ... this will encode the body as
[65] Fix | Delete
// `application/x-www-form-urlencoded` instead and will send the model in a
[66] Fix | Delete
// form param named `model`.
[67] Fix | Delete
Backbone.emulateJSON = false;
[68] Fix | Delete
[69] Fix | Delete
// Backbone.Events
[70] Fix | Delete
// ---------------
[71] Fix | Delete
[72] Fix | Delete
// A module that can be mixed in to *any object* in order to provide it with
[73] Fix | Delete
// a custom event channel. You may bind a callback to an event with `on` or
[74] Fix | Delete
// remove with `off`; `trigger`-ing an event fires all callbacks in
[75] Fix | Delete
// succession.
[76] Fix | Delete
//
[77] Fix | Delete
// var object = {};
[78] Fix | Delete
// _.extend(object, Backbone.Events);
[79] Fix | Delete
// object.on('expand', function(){ alert('expanded'); });
[80] Fix | Delete
// object.trigger('expand');
[81] Fix | Delete
//
[82] Fix | Delete
var Events = Backbone.Events = {};
[83] Fix | Delete
[84] Fix | Delete
// Regular expression used to split event strings.
[85] Fix | Delete
var eventSplitter = /\s+/;
[86] Fix | Delete
[87] Fix | Delete
// A private global variable to share between listeners and listenees.
[88] Fix | Delete
var _listening;
[89] Fix | Delete
[90] Fix | Delete
// Iterates over the standard `event, callback` (as well as the fancy multiple
[91] Fix | Delete
// space-separated events `"change blur", callback` and jQuery-style event
[92] Fix | Delete
// maps `{event: callback}`).
[93] Fix | Delete
var eventsApi = function(iteratee, events, name, callback, opts) {
[94] Fix | Delete
var i = 0, names;
[95] Fix | Delete
if (name && typeof name === 'object') {
[96] Fix | Delete
// Handle event maps.
[97] Fix | Delete
if (callback !== void 0 && 'context' in opts && opts.context === void 0) opts.context = callback;
[98] Fix | Delete
for (names = _.keys(name); i < names.length ; i++) {
[99] Fix | Delete
events = eventsApi(iteratee, events, names[i], name[names[i]], opts);
[100] Fix | Delete
}
[101] Fix | Delete
} else if (name && eventSplitter.test(name)) {
[102] Fix | Delete
// Handle space-separated event names by delegating them individually.
[103] Fix | Delete
for (names = name.split(eventSplitter); i < names.length; i++) {
[104] Fix | Delete
events = iteratee(events, names[i], callback, opts);
[105] Fix | Delete
}
[106] Fix | Delete
} else {
[107] Fix | Delete
// Finally, standard events.
[108] Fix | Delete
events = iteratee(events, name, callback, opts);
[109] Fix | Delete
}
[110] Fix | Delete
return events;
[111] Fix | Delete
};
[112] Fix | Delete
[113] Fix | Delete
// Bind an event to a `callback` function. Passing `"all"` will bind
[114] Fix | Delete
// the callback to all events fired.
[115] Fix | Delete
Events.on = function(name, callback, context) {
[116] Fix | Delete
this._events = eventsApi(onApi, this._events || {}, name, callback, {
[117] Fix | Delete
context: context,
[118] Fix | Delete
ctx: this,
[119] Fix | Delete
listening: _listening
[120] Fix | Delete
});
[121] Fix | Delete
[122] Fix | Delete
if (_listening) {
[123] Fix | Delete
var listeners = this._listeners || (this._listeners = {});
[124] Fix | Delete
listeners[_listening.id] = _listening;
[125] Fix | Delete
// Allow the listening to use a counter, instead of tracking
[126] Fix | Delete
// callbacks for library interop
[127] Fix | Delete
_listening.interop = false;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return this;
[131] Fix | Delete
};
[132] Fix | Delete
[133] Fix | Delete
// Inversion-of-control versions of `on`. Tell *this* object to listen to
[134] Fix | Delete
// an event in another object... keeping track of what it's listening to
[135] Fix | Delete
// for easier unbinding later.
[136] Fix | Delete
Events.listenTo = function(obj, name, callback) {
[137] Fix | Delete
if (!obj) return this;
[138] Fix | Delete
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
[139] Fix | Delete
var listeningTo = this._listeningTo || (this._listeningTo = {});
[140] Fix | Delete
var listening = _listening = listeningTo[id];
[141] Fix | Delete
[142] Fix | Delete
// This object is not listening to any other events on `obj` yet.
[143] Fix | Delete
// Setup the necessary references to track the listening callbacks.
[144] Fix | Delete
if (!listening) {
[145] Fix | Delete
this._listenId || (this._listenId = _.uniqueId('l'));
[146] Fix | Delete
listening = _listening = listeningTo[id] = new Listening(this, obj);
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
// Bind callbacks on obj.
[150] Fix | Delete
var error = tryCatchOn(obj, name, callback, this);
[151] Fix | Delete
_listening = void 0;
[152] Fix | Delete
[153] Fix | Delete
if (error) throw error;
[154] Fix | Delete
// If the target obj is not Backbone.Events, track events manually.
[155] Fix | Delete
if (listening.interop) listening.on(name, callback);
[156] Fix | Delete
[157] Fix | Delete
return this;
[158] Fix | Delete
};
[159] Fix | Delete
[160] Fix | Delete
// The reducing API that adds a callback to the `events` object.
[161] Fix | Delete
var onApi = function(events, name, callback, options) {
[162] Fix | Delete
if (callback) {
[163] Fix | Delete
var handlers = events[name] || (events[name] = []);
[164] Fix | Delete
var context = options.context, ctx = options.ctx, listening = options.listening;
[165] Fix | Delete
if (listening) listening.count++;
[166] Fix | Delete
[167] Fix | Delete
handlers.push({callback: callback, context: context, ctx: context || ctx, listening: listening});
[168] Fix | Delete
}
[169] Fix | Delete
return events;
[170] Fix | Delete
};
[171] Fix | Delete
[172] Fix | Delete
// An try-catch guarded #on function, to prevent poisoning the global
[173] Fix | Delete
// `_listening` variable.
[174] Fix | Delete
var tryCatchOn = function(obj, name, callback, context) {
[175] Fix | Delete
try {
[176] Fix | Delete
obj.on(name, callback, context);
[177] Fix | Delete
} catch (e) {
[178] Fix | Delete
return e;
[179] Fix | Delete
}
[180] Fix | Delete
};
[181] Fix | Delete
[182] Fix | Delete
// Remove one or many callbacks. If `context` is null, removes all
[183] Fix | Delete
// callbacks with that function. If `callback` is null, removes all
[184] Fix | Delete
// callbacks for the event. If `name` is null, removes all bound
[185] Fix | Delete
// callbacks for all events.
[186] Fix | Delete
Events.off = function(name, callback, context) {
[187] Fix | Delete
if (!this._events) return this;
[188] Fix | Delete
this._events = eventsApi(offApi, this._events, name, callback, {
[189] Fix | Delete
context: context,
[190] Fix | Delete
listeners: this._listeners
[191] Fix | Delete
});
[192] Fix | Delete
[193] Fix | Delete
return this;
[194] Fix | Delete
};
[195] Fix | Delete
[196] Fix | Delete
// Tell this object to stop listening to either specific events ... or
[197] Fix | Delete
// to every object it's currently listening to.
[198] Fix | Delete
Events.stopListening = function(obj, name, callback) {
[199] Fix | Delete
var listeningTo = this._listeningTo;
[200] Fix | Delete
if (!listeningTo) return this;
[201] Fix | Delete
[202] Fix | Delete
var ids = obj ? [obj._listenId] : _.keys(listeningTo);
[203] Fix | Delete
for (var i = 0; i < ids.length; i++) {
[204] Fix | Delete
var listening = listeningTo[ids[i]];
[205] Fix | Delete
[206] Fix | Delete
// If listening doesn't exist, this object is not currently
[207] Fix | Delete
// listening to obj. Break out early.
[208] Fix | Delete
if (!listening) break;
[209] Fix | Delete
[210] Fix | Delete
listening.obj.off(name, callback, this);
[211] Fix | Delete
if (listening.interop) listening.off(name, callback);
[212] Fix | Delete
}
[213] Fix | Delete
if (_.isEmpty(listeningTo)) this._listeningTo = void 0;
[214] Fix | Delete
[215] Fix | Delete
return this;
[216] Fix | Delete
};
[217] Fix | Delete
[218] Fix | Delete
// The reducing API that removes a callback from the `events` object.
[219] Fix | Delete
var offApi = function(events, name, callback, options) {
[220] Fix | Delete
if (!events) return;
[221] Fix | Delete
[222] Fix | Delete
var context = options.context, listeners = options.listeners;
[223] Fix | Delete
var i = 0, names;
[224] Fix | Delete
[225] Fix | Delete
// Delete all event listeners and "drop" events.
[226] Fix | Delete
if (!name && !context && !callback) {
[227] Fix | Delete
for (names = _.keys(listeners); i < names.length; i++) {
[228] Fix | Delete
listeners[names[i]].cleanup();
[229] Fix | Delete
}
[230] Fix | Delete
return;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
names = name ? [name] : _.keys(events);
[234] Fix | Delete
for (; i < names.length; i++) {
[235] Fix | Delete
name = names[i];
[236] Fix | Delete
var handlers = events[name];
[237] Fix | Delete
[238] Fix | Delete
// Bail out if there are no events stored.
[239] Fix | Delete
if (!handlers) break;
[240] Fix | Delete
[241] Fix | Delete
// Find any remaining events.
[242] Fix | Delete
var remaining = [];
[243] Fix | Delete
for (var j = 0; j < handlers.length; j++) {
[244] Fix | Delete
var handler = handlers[j];
[245] Fix | Delete
if (
[246] Fix | Delete
callback && callback !== handler.callback &&
[247] Fix | Delete
callback !== handler.callback._callback ||
[248] Fix | Delete
context && context !== handler.context
[249] Fix | Delete
) {
[250] Fix | Delete
remaining.push(handler);
[251] Fix | Delete
} else {
[252] Fix | Delete
var listening = handler.listening;
[253] Fix | Delete
if (listening) listening.off(name, callback);
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
// Replace events if there are any remaining. Otherwise, clean up.
[258] Fix | Delete
if (remaining.length) {
[259] Fix | Delete
events[name] = remaining;
[260] Fix | Delete
} else {
[261] Fix | Delete
delete events[name];
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
return events;
[266] Fix | Delete
};
[267] Fix | Delete
[268] Fix | Delete
// Bind an event to only be triggered a single time. After the first time
[269] Fix | Delete
// the callback is invoked, its listener will be removed. If multiple events
[270] Fix | Delete
// are passed in using the space-separated syntax, the handler will fire
[271] Fix | Delete
// once for each event, not once for a combination of all events.
[272] Fix | Delete
Events.once = function(name, callback, context) {
[273] Fix | Delete
// Map the event into a `{event: once}` object.
[274] Fix | Delete
var events = eventsApi(onceMap, {}, name, callback, this.off.bind(this));
[275] Fix | Delete
if (typeof name === 'string' && context == null) callback = void 0;
[276] Fix | Delete
return this.on(events, callback, context);
[277] Fix | Delete
};
[278] Fix | Delete
[279] Fix | Delete
// Inversion-of-control versions of `once`.
[280] Fix | Delete
Events.listenToOnce = function(obj, name, callback) {
[281] Fix | Delete
// Map the event into a `{event: once}` object.
[282] Fix | Delete
var events = eventsApi(onceMap, {}, name, callback, this.stopListening.bind(this, obj));
[283] Fix | Delete
return this.listenTo(obj, events);
[284] Fix | Delete
};
[285] Fix | Delete
[286] Fix | Delete
// Reduces the event callbacks into a map of `{event: onceWrapper}`.
[287] Fix | Delete
// `offer` unbinds the `onceWrapper` after it has been called.
[288] Fix | Delete
var onceMap = function(map, name, callback, offer) {
[289] Fix | Delete
if (callback) {
[290] Fix | Delete
var once = map[name] = _.once(function() {
[291] Fix | Delete
offer(name, once);
[292] Fix | Delete
callback.apply(this, arguments);
[293] Fix | Delete
});
[294] Fix | Delete
once._callback = callback;
[295] Fix | Delete
}
[296] Fix | Delete
return map;
[297] Fix | Delete
};
[298] Fix | Delete
[299] Fix | Delete
// Trigger one or many events, firing all bound callbacks. Callbacks are
[300] Fix | Delete
// passed the same arguments as `trigger` is, apart from the event name
[301] Fix | Delete
// (unless you're listening on `"all"`, which will cause your callback to
[302] Fix | Delete
// receive the true name of the event as the first argument).
[303] Fix | Delete
Events.trigger = function(name) {
[304] Fix | Delete
if (!this._events) return this;
[305] Fix | Delete
[306] Fix | Delete
var length = Math.max(0, arguments.length - 1);
[307] Fix | Delete
var args = Array(length);
[308] Fix | Delete
for (var i = 0; i < length; i++) args[i] = arguments[i + 1];
[309] Fix | Delete
[310] Fix | Delete
eventsApi(triggerApi, this._events, name, void 0, args);
[311] Fix | Delete
return this;
[312] Fix | Delete
};
[313] Fix | Delete
[314] Fix | Delete
// Handles triggering the appropriate event callbacks.
[315] Fix | Delete
var triggerApi = function(objEvents, name, callback, args) {
[316] Fix | Delete
if (objEvents) {
[317] Fix | Delete
var events = objEvents[name];
[318] Fix | Delete
var allEvents = objEvents.all;
[319] Fix | Delete
if (events && allEvents) allEvents = allEvents.slice();
[320] Fix | Delete
if (events) triggerEvents(events, args);
[321] Fix | Delete
if (allEvents) triggerEvents(allEvents, [name].concat(args));
[322] Fix | Delete
}
[323] Fix | Delete
return objEvents;
[324] Fix | Delete
};
[325] Fix | Delete
[326] Fix | Delete
// A difficult-to-believe, but optimized internal dispatch function for
[327] Fix | Delete
// triggering events. Tries to keep the usual cases speedy (most internal
[328] Fix | Delete
// Backbone events have 3 arguments).
[329] Fix | Delete
var triggerEvents = function(events, args) {
[330] Fix | Delete
var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
[331] Fix | Delete
switch (args.length) {
[332] Fix | Delete
case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
[333] Fix | Delete
case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
[334] Fix | Delete
case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
[335] Fix | Delete
case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
[336] Fix | Delete
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
[337] Fix | Delete
}
[338] Fix | Delete
};
[339] Fix | Delete
[340] Fix | Delete
// A listening class that tracks and cleans up memory bindings
[341] Fix | Delete
// when all callbacks have been offed.
[342] Fix | Delete
var Listening = function(listener, obj) {
[343] Fix | Delete
this.id = listener._listenId;
[344] Fix | Delete
this.listener = listener;
[345] Fix | Delete
this.obj = obj;
[346] Fix | Delete
this.interop = true;
[347] Fix | Delete
this.count = 0;
[348] Fix | Delete
this._events = void 0;
[349] Fix | Delete
};
[350] Fix | Delete
[351] Fix | Delete
Listening.prototype.on = Events.on;
[352] Fix | Delete
[353] Fix | Delete
// Offs a callback (or several).
[354] Fix | Delete
// Uses an optimized counter if the listenee uses Backbone.Events.
[355] Fix | Delete
// Otherwise, falls back to manual tracking to support events
[356] Fix | Delete
// library interop.
[357] Fix | Delete
Listening.prototype.off = function(name, callback) {
[358] Fix | Delete
var cleanup;
[359] Fix | Delete
if (this.interop) {
[360] Fix | Delete
this._events = eventsApi(offApi, this._events, name, callback, {
[361] Fix | Delete
context: void 0,
[362] Fix | Delete
listeners: void 0
[363] Fix | Delete
});
[364] Fix | Delete
cleanup = !this._events;
[365] Fix | Delete
} else {
[366] Fix | Delete
this.count--;
[367] Fix | Delete
cleanup = this.count === 0;
[368] Fix | Delete
}
[369] Fix | Delete
if (cleanup) this.cleanup();
[370] Fix | Delete
};
[371] Fix | Delete
[372] Fix | Delete
// Cleans up memory bindings between the listener and the listenee.
[373] Fix | Delete
Listening.prototype.cleanup = function() {
[374] Fix | Delete
delete this.listener._listeningTo[this.obj._listenId];
[375] Fix | Delete
if (!this.interop) delete this.obj._listeners[this.id];
[376] Fix | Delete
};
[377] Fix | Delete
[378] Fix | Delete
// Aliases for backwards compatibility.
[379] Fix | Delete
Events.bind = Events.on;
[380] Fix | Delete
Events.unbind = Events.off;
[381] Fix | Delete
[382] Fix | Delete
// Allow the `Backbone` object to serve as a global event bus, for folks who
[383] Fix | Delete
// want global "pubsub" in a convenient place.
[384] Fix | Delete
_.extend(Backbone, Events);
[385] Fix | Delete
[386] Fix | Delete
// Backbone.Model
[387] Fix | Delete
// --------------
[388] Fix | Delete
[389] Fix | Delete
// Backbone **Models** are the basic data object in the framework --
[390] Fix | Delete
// frequently representing a row in a table in a database on your server.
[391] Fix | Delete
// A discrete chunk of data and a bunch of useful, related methods for
[392] Fix | Delete
// performing computations and transformations on that data.
[393] Fix | Delete
[394] Fix | Delete
// Create a new model with the specified attributes. A client id (`cid`)
[395] Fix | Delete
// is automatically generated and assigned for you.
[396] Fix | Delete
var Model = Backbone.Model = function(attributes, options) {
[397] Fix | Delete
var attrs = attributes || {};
[398] Fix | Delete
options || (options = {});
[399] Fix | Delete
this.preinitialize.apply(this, arguments);
[400] Fix | Delete
this.cid = _.uniqueId(this.cidPrefix);
[401] Fix | Delete
this.attributes = {};
[402] Fix | Delete
if (options.collection) this.collection = options.collection;
[403] Fix | Delete
if (options.parse) attrs = this.parse(attrs, options) || {};
[404] Fix | Delete
var defaults = _.result(this, 'defaults');
[405] Fix | Delete
attrs = _.defaults(_.extend({}, defaults, attrs), defaults);
[406] Fix | Delete
this.set(attrs, options);
[407] Fix | Delete
this.changed = {};
[408] Fix | Delete
this.initialize.apply(this, arguments);
[409] Fix | Delete
};
[410] Fix | Delete
[411] Fix | Delete
// Attach all inheritable methods to the Model prototype.
[412] Fix | Delete
_.extend(Model.prototype, Events, {
[413] Fix | Delete
[414] Fix | Delete
// A hash of attributes whose current and previous value differ.
[415] Fix | Delete
changed: null,
[416] Fix | Delete
[417] Fix | Delete
// The value returned during the last failed validation.
[418] Fix | Delete
validationError: null,
[419] Fix | Delete
[420] Fix | Delete
// The default name for the JSON `id` attribute is `"id"`. MongoDB and
[421] Fix | Delete
// CouchDB users may want to set this to `"_id"`.
[422] Fix | Delete
idAttribute: 'id',
[423] Fix | Delete
[424] Fix | Delete
// The prefix is used to create the client id which is used to identify models locally.
[425] Fix | Delete
// You may want to override this if you're experiencing name clashes with model ids.
[426] Fix | Delete
cidPrefix: 'c',
[427] Fix | Delete
[428] Fix | Delete
// preinitialize is an empty function by default. You can override it with a function
[429] Fix | Delete
// or object. preinitialize will run before any instantiation logic is run in the Model.
[430] Fix | Delete
preinitialize: function(){},
[431] Fix | Delete
[432] Fix | Delete
// Initialize is an empty function by default. Override it with your own
[433] Fix | Delete
// initialization logic.
[434] Fix | Delete
initialize: function(){},
[435] Fix | Delete
[436] Fix | Delete
// Return a copy of the model's `attributes` object.
[437] Fix | Delete
toJSON: function(options) {
[438] Fix | Delete
return _.clone(this.attributes);
[439] Fix | Delete
},
[440] Fix | Delete
[441] Fix | Delete
// Proxy `Backbone.sync` by default -- but override this if you need
[442] Fix | Delete
// custom syncing semantics for *this* particular model.
[443] Fix | Delete
sync: function() {
[444] Fix | Delete
return Backbone.sync.apply(this, arguments);
[445] Fix | Delete
},
[446] Fix | Delete
[447] Fix | Delete
// Get the value of an attribute.
[448] Fix | Delete
get: function(attr) {
[449] Fix | Delete
return this.attributes[attr];
[450] Fix | Delete
},
[451] Fix | Delete
[452] Fix | Delete
// Get the HTML-escaped value of an attribute.
[453] Fix | Delete
escape: function(attr) {
[454] Fix | Delete
return _.escape(this.get(attr));
[455] Fix | Delete
},
[456] Fix | Delete
[457] Fix | Delete
// Returns `true` if the attribute contains a value that is not null
[458] Fix | Delete
// or undefined.
[459] Fix | Delete
has: function(attr) {
[460] Fix | Delete
return this.get(attr) != null;
[461] Fix | Delete
},
[462] Fix | Delete
[463] Fix | Delete
// Special-cased proxy to underscore's `_.matches` method.
[464] Fix | Delete
matches: function(attrs) {
[465] Fix | Delete
return !!_.iteratee(attrs, this)(this.attributes);
[466] Fix | Delete
},
[467] Fix | Delete
[468] Fix | Delete
// Set a hash of model attributes on the object, firing `"change"`. This is
[469] Fix | Delete
// the core primitive operation of a model, updating the data and notifying
[470] Fix | Delete
// anyone who needs to know about the change in state. The heart of the beast.
[471] Fix | Delete
set: function(key, val, options) {
[472] Fix | Delete
if (key == null) return this;
[473] Fix | Delete
[474] Fix | Delete
// Handle both `"key", value` and `{key: value}` -style arguments.
[475] Fix | Delete
var attrs;
[476] Fix | Delete
if (typeof key === 'object') {
[477] Fix | Delete
attrs = key;
[478] Fix | Delete
options = val;
[479] Fix | Delete
} else {
[480] Fix | Delete
(attrs = {})[key] = val;
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
options || (options = {});
[484] Fix | Delete
[485] Fix | Delete
// Run validation.
[486] Fix | Delete
if (!this._validate(attrs, options)) return false;
[487] Fix | Delete
[488] Fix | Delete
// Extract attributes and options.
[489] Fix | Delete
var unset = options.unset;
[490] Fix | Delete
var silent = options.silent;
[491] Fix | Delete
var changes = [];
[492] Fix | Delete
var changing = this._changing;
[493] Fix | Delete
this._changing = true;
[494] Fix | Delete
[495] Fix | Delete
if (!changing) {
[496] Fix | Delete
this._previousAttributes = _.clone(this.attributes);
[497] Fix | Delete
this.changed = {};
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function