chaplin-on-rails 0.7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +42 -0
  3. data/Rakefile +38 -0
  4. data/lib/chaplin-on-rails.rb +2 -0
  5. data/lib/chaplin-on-rails/engine.rb +6 -0
  6. data/lib/chaplin-on-rails/version.rb +3 -0
  7. data/lib/generators/chaplin/helpers.rb +94 -0
  8. data/lib/generators/chaplin/install/install_generator.rb +68 -0
  9. data/lib/generators/chaplin/install/templates/app_template.js.coffee +65 -0
  10. data/lib/generators/chaplin/install/templates/application.js.coffee +13 -0
  11. data/lib/generators/chaplin/install/templates/javascripts/controllers/base/controller.js.coffee +8 -0
  12. data/lib/generators/chaplin/install/templates/javascripts/lib/support.js.coffee +19 -0
  13. data/lib/generators/chaplin/install/templates/javascripts/lib/utils.js.coffee +18 -0
  14. data/lib/generators/chaplin/install/templates/javascripts/lib/view_helper.js.coffee +16 -0
  15. data/lib/generators/chaplin/install/templates/javascripts/models/base/collection.js.coffee +9 -0
  16. data/lib/generators/chaplin/install/templates/javascripts/models/base/model.js.coffee +9 -0
  17. data/lib/generators/chaplin/install/templates/javascripts/routes.js.coffee +9 -0
  18. data/lib/generators/chaplin/install/templates/javascripts/views/base/collection_view.coffee +11 -0
  19. data/lib/generators/chaplin/install/templates/javascripts/views/base/view.coffee +15 -0
  20. data/lib/generators/chaplin/install/templates/javascripts/views/layout.js.coffee +8 -0
  21. data/lib/generators/chaplin/install/templates/requirejs.yml +6 -0
  22. data/test/chaplin-on-rails_test.rb +19 -0
  23. data/test/dummy/README.rdoc +261 -0
  24. data/test/dummy/Rakefile +7 -0
  25. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  26. data/test/dummy/app/controllers/application_controller.rb +3 -0
  27. data/test/dummy/app/controllers/home_controller.rb +5 -0
  28. data/test/dummy/app/helpers/application_helper.rb +2 -0
  29. data/test/dummy/app/helpers/home_helper.rb +2 -0
  30. data/test/dummy/app/views/home/index.html.erb +1 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/config.ru +4 -0
  33. data/test/dummy/config/application.rb +59 -0
  34. data/test/dummy/config/boot.rb +10 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +37 -0
  38. data/test/dummy/config/environments/production.rb +67 -0
  39. data/test/dummy/config/environments/test.rb +37 -0
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/test/dummy/config/initializers/inflections.rb +15 -0
  42. data/test/dummy/config/initializers/mime_types.rb +5 -0
  43. data/test/dummy/config/initializers/secret_token.rb +7 -0
  44. data/test/dummy/config/initializers/session_store.rb +8 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +5 -0
  47. data/test/dummy/config/routes.rb +58 -0
  48. data/test/dummy/db/development.sqlite3 +0 -0
  49. data/test/dummy/db/test.sqlite3 +0 -0
  50. data/test/dummy/log/development.log +186 -0
  51. data/test/dummy/log/test.log +35 -0
  52. data/test/dummy/public/404.html +26 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +25 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/dummy/script/rails +6 -0
  57. data/test/dummy/tmp/cache/assets/C75/D70/sprockets%2F1781f0919424c1d3014e066757a81eaa +0 -0
  58. data/test/dummy/tmp/cache/assets/C80/150/sprockets%2F0d3881005b0646df783d5c24683d34f5 +0 -0
  59. data/test/dummy/tmp/cache/assets/C89/4B0/sprockets%2F1f6245087eeb4c854a03a4644c964579 +0 -0
  60. data/test/dummy/tmp/cache/assets/C8D/980/sprockets%2F7184f95c8e290cbc2451767559f01d08 +0 -0
  61. data/test/dummy/tmp/cache/assets/CA8/130/sprockets%2F695a47c24c7804e27afc2208426ae133 +0 -0
  62. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  63. data/test/dummy/tmp/cache/assets/CDE/EC0/sprockets%2F32bce1758d7525013970c7bb7d77aa28 +0 -0
  64. data/test/dummy/tmp/cache/assets/CEB/750/sprockets%2F72f4d157b237c37ed75f49bd217824c7 +0 -0
  65. data/test/dummy/tmp/cache/assets/CF6/290/sprockets%2F95f8b25659fb7a430d68b27a5f72f666 +0 -0
  66. data/test/dummy/tmp/cache/assets/CF9/7C0/sprockets%2F40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  67. data/test/dummy/tmp/cache/assets/D08/A30/sprockets%2F1310a2826dcae357ba9f383e86b638a1 +0 -0
  68. data/test/dummy/tmp/cache/assets/D09/100/sprockets%2F4dc073204163e0850bf7fcb55ff8b552 +0 -0
  69. data/test/dummy/tmp/cache/assets/D0A/A40/sprockets%2F09e4e8ba330b24f9f87a63a910d422f3 +0 -0
  70. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  71. data/test/dummy/tmp/cache/assets/D38/B80/sprockets%2F42c6d981cbd6ae6061c7088a2321a8ed +0 -0
  72. data/test/dummy/tmp/cache/assets/D3E/070/sprockets%2F45f1913b6d3645a3d166ff4ff250e4cc +0 -0
  73. data/test/dummy/tmp/cache/assets/D4E/D00/sprockets%2F1a6846f0a837ae2524e2f9ec89e6ef43 +0 -0
  74. data/test/dummy/tmp/cache/assets/D57/BC0/sprockets%2F50db33dbb1258913cb2fbd562ab1294b +0 -0
  75. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  76. data/test/dummy/tmp/cache/assets/D63/C90/sprockets%2Fb70150e50cbcbc59c55ffb3c53a35575 +0 -0
  77. data/test/dummy/tmp/cache/assets/D6F/C70/sprockets%2F667a4890bf4c03f50b452d1db278fcfe +0 -0
  78. data/test/dummy/tmp/cache/assets/D79/470/sprockets%2F1cb96b862f7c7497af494aa19d0cbd55 +0 -0
  79. data/test/dummy/tmp/cache/assets/D7A/930/sprockets%2F3964cc67ad46beb69c444bb51f486e2f +0 -0
  80. data/test/dummy/tmp/cache/assets/D8B/B40/sprockets%2F11b945abcf62b02fcfb34f52f6aa1481 +0 -0
  81. data/test/dummy/tmp/cache/assets/D92/990/sprockets%2F4b34320d2682dc0fd9b107f3ef2cae7d +0 -0
  82. data/test/dummy/tmp/cache/assets/D98/8B0/sprockets%2Fedbef6e0d0a4742346cf479f2c522eb0 +0 -0
  83. data/test/dummy/tmp/cache/assets/DC8/010/sprockets%2F34cce381cfe1aa4be1ca560f118dd998 +0 -0
  84. data/test/dummy/tmp/cache/assets/DCD/ED0/sprockets%2F77ca908f86a8be3506de6fe60b1e0baa +0 -0
  85. data/test/dummy/tmp/cache/assets/DCE/890/sprockets%2Fd54185fb144acd9d1d15ed0e4ebf9f44 +0 -0
  86. data/test/dummy/tmp/cache/assets/DCE/D00/sprockets%2Fed31b7ea3cfb14d43a87c89deb0390f7 +0 -0
  87. data/test/dummy/tmp/cache/assets/DCF/610/sprockets%2Fda58bc8db5dd9cb124a85c507d591fd2 +0 -0
  88. data/test/dummy/tmp/cache/assets/E11/4E0/sprockets%2F86e145a39f85cceeaffdff91ebb61449 +0 -0
  89. data/test/test_helper.rb +7 -0
  90. data/vendor/assets/javascripts/backbone.js +1497 -0
  91. data/vendor/assets/javascripts/chaplin.js.coffee +2377 -0
  92. data/vendor/assets/javascripts/underscore.js +1222 -0
  93. metadata +292 -0
@@ -0,0 +1,35 @@
1
+ Connecting to database specified by database.yml
2
+ Connecting to database specified by database.yml
3
+  (0.4ms) begin transaction
4
+ Compiled backbone.js (1ms) (pid 69453)
5
+  (0.1ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+  (0.1ms) rollback transaction
8
+  (0.0ms) begin transaction
9
+ Compiled underscore.js (0ms) (pid 69453)
10
+  (0.1ms) rollback transaction
11
+ Connecting to database specified by database.yml
12
+  (0.3ms) begin transaction
13
+  (0.1ms) rollback transaction
14
+  (0.1ms) begin transaction
15
+ Compiled chaplin.js (813ms) (pid 69741)
16
+  (0.1ms) rollback transaction
17
+  (0.0ms) begin transaction
18
+  (0.0ms) rollback transaction
19
+ Connecting to database specified by database.yml
20
+  (0.3ms) begin transaction
21
+ Compiled backbone.js (1ms) (pid 89843)
22
+  (0.1ms) rollback transaction
23
+  (0.1ms) begin transaction
24
+ Compiled chaplin.js (931ms) (pid 89843)
25
+  (0.1ms) rollback transaction
26
+  (0.0ms) begin transaction
27
+ Compiled underscore.js (0ms) (pid 89843)
28
+  (0.1ms) rollback transaction
29
+ Connecting to database specified by database.yml
30
+  (0.2ms) begin transaction
31
+  (0.1ms) rollback transaction
32
+  (0.0ms) begin transaction
33
+  (0.0ms) rollback transaction
34
+  (0.0ms) begin transaction
35
+  (0.0ms) rollback transaction
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,1497 @@
1
+ // Backbone.js 0.9.9
2
+
3
+ // (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
4
+ // Backbone may be freely distributed under the MIT license.
5
+ // For all details and documentation:
6
+ // http://backbonejs.org
7
+
8
+ (function(){
9
+
10
+ // Initial Setup
11
+ // -------------
12
+
13
+ // Save a reference to the global object (`window` in the browser, `exports`
14
+ // on the server).
15
+ var root = this;
16
+
17
+ // Save the previous value of the `Backbone` variable, so that it can be
18
+ // restored later on, if `noConflict` is used.
19
+ var previousBackbone = root.Backbone;
20
+
21
+ // Create a local reference to array methods.
22
+ var array = [];
23
+ var push = array.push;
24
+ var slice = array.slice;
25
+ var splice = array.splice;
26
+
27
+ // The top-level namespace. All public Backbone classes and modules will
28
+ // be attached to this. Exported for both CommonJS and the browser.
29
+ var Backbone;
30
+ if (typeof exports !== 'undefined') {
31
+ Backbone = exports;
32
+ } else {
33
+ Backbone = root.Backbone = {};
34
+ }
35
+
36
+ // Current version of the library. Keep in sync with `package.json`.
37
+ Backbone.VERSION = '0.9.9';
38
+
39
+ // Require Underscore, if we're on the server, and it's not already present.
40
+ var _ = root._;
41
+ if (!_ && (typeof require !== 'undefined')) _ = require('underscore');
42
+
43
+ // For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable.
44
+ Backbone.$ = root.jQuery || root.Zepto || root.ender;
45
+
46
+ // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
47
+ // to its previous owner. Returns a reference to this Backbone object.
48
+ Backbone.noConflict = function() {
49
+ root.Backbone = previousBackbone;
50
+ return this;
51
+ };
52
+
53
+ // Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
54
+ // will fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and
55
+ // set a `X-Http-Method-Override` header.
56
+ Backbone.emulateHTTP = false;
57
+
58
+ // Turn on `emulateJSON` to support legacy servers that can't deal with direct
59
+ // `application/json` requests ... will encode the body as
60
+ // `application/x-www-form-urlencoded` instead and will send the model in a
61
+ // form param named `model`.
62
+ Backbone.emulateJSON = false;
63
+
64
+ // Backbone.Events
65
+ // ---------------
66
+
67
+ // Regular expression used to split event strings.
68
+ var eventSplitter = /\s+/;
69
+
70
+ // Implement fancy features of the Events API such as multiple event
71
+ // names `"change blur"` and jQuery-style event maps `{change: action}`
72
+ // in terms of the existing API.
73
+ var eventsApi = function(obj, action, name, rest) {
74
+ if (!name) return true;
75
+ if (typeof name === 'object') {
76
+ for (var key in name) {
77
+ obj[action].apply(obj, [key, name[key]].concat(rest));
78
+ }
79
+ } else if (eventSplitter.test(name)) {
80
+ var names = name.split(eventSplitter);
81
+ for (var i = 0, l = names.length; i < l; i++) {
82
+ obj[action].apply(obj, [names[i]].concat(rest));
83
+ }
84
+ } else {
85
+ return true;
86
+ }
87
+ };
88
+
89
+ // Optimized internal dispatch function for triggering events. Tries to
90
+ // keep the usual cases speedy (most Backbone events have 3 arguments).
91
+ var triggerEvents = function(obj, events, args) {
92
+ var ev, i = -1, l = events.length;
93
+ switch (args.length) {
94
+ case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx);
95
+ return;
96
+ case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0]);
97
+ return;
98
+ case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1]);
99
+ return;
100
+ case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1], args[2]);
101
+ return;
102
+ default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
103
+ }
104
+ };
105
+
106
+ // A module that can be mixed in to *any object* in order to provide it with
107
+ // custom events. You may bind with `on` or remove with `off` callback
108
+ // functions to an event; `trigger`-ing an event fires all callbacks in
109
+ // succession.
110
+ //
111
+ // var object = {};
112
+ // _.extend(object, Backbone.Events);
113
+ // object.on('expand', function(){ alert('expanded'); });
114
+ // object.trigger('expand');
115
+ //
116
+ var Events = Backbone.Events = {
117
+
118
+ // Bind one or more space separated events, or an events map,
119
+ // to a `callback` function. Passing `"all"` will bind the callback to
120
+ // all events fired.
121
+ on: function(name, callback, context) {
122
+ if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this;
123
+ this._events || (this._events = {});
124
+ var list = this._events[name] || (this._events[name] = []);
125
+ list.push({callback: callback, context: context, ctx: context || this});
126
+ return this;
127
+ },
128
+
129
+ // Bind events to only be triggered a single time. After the first time
130
+ // the callback is invoked, it will be removed.
131
+ once: function(name, callback, context) {
132
+ if (!(eventsApi(this, 'once', name, [callback, context]) && callback)) return this;
133
+ var self = this;
134
+ var once = _.once(function() {
135
+ self.off(name, once);
136
+ callback.apply(this, arguments);
137
+ });
138
+ once._callback = callback;
139
+ this.on(name, once, context);
140
+ return this;
141
+ },
142
+
143
+ // Remove one or many callbacks. If `context` is null, removes all
144
+ // callbacks with that function. If `callback` is null, removes all
145
+ // callbacks for the event. If `name` is null, removes all bound
146
+ // callbacks for all events.
147
+ off: function(name, callback, context) {
148
+ var list, ev, events, names, i, l, j, k;
149
+ if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this;
150
+ if (!name && !callback && !context) {
151
+ this._events = {};
152
+ return this;
153
+ }
154
+
155
+ names = name ? [name] : _.keys(this._events);
156
+ for (i = 0, l = names.length; i < l; i++) {
157
+ name = names[i];
158
+ if (list = this._events[name]) {
159
+ events = [];
160
+ if (callback || context) {
161
+ for (j = 0, k = list.length; j < k; j++) {
162
+ ev = list[j];
163
+ if ((callback && callback !== ev.callback &&
164
+ callback !== ev.callback._callback) ||
165
+ (context && context !== ev.context)) {
166
+ events.push(ev);
167
+ }
168
+ }
169
+ }
170
+ this._events[name] = events;
171
+ }
172
+ }
173
+
174
+ return this;
175
+ },
176
+
177
+ // Trigger one or many events, firing all bound callbacks. Callbacks are
178
+ // passed the same arguments as `trigger` is, apart from the event name
179
+ // (unless you're listening on `"all"`, which will cause your callback to
180
+ // receive the true name of the event as the first argument).
181
+ trigger: function(name) {
182
+ if (!this._events) return this;
183
+ var args = slice.call(arguments, 1);
184
+ if (!eventsApi(this, 'trigger', name, args)) return this;
185
+ var events = this._events[name];
186
+ var allEvents = this._events.all;
187
+ if (events) triggerEvents(this, events, args);
188
+ if (allEvents) triggerEvents(this, allEvents, arguments);
189
+ return this;
190
+ },
191
+
192
+ // An inversion-of-control version of `on`. Tell *this* object to listen to
193
+ // an event in another object ... keeping track of what it's listening to.
194
+ listenTo: function(object, events, callback) {
195
+ var listeners = this._listeners || (this._listeners = {});
196
+ var id = object._listenerId || (object._listenerId = _.uniqueId('l'));
197
+ listeners[id] = object;
198
+ object.on(events, callback || this, this);
199
+ return this;
200
+ },
201
+
202
+ // Tell this object to stop listening to either specific events ... or
203
+ // to every object it's currently listening to.
204
+ stopListening: function(object, events, callback) {
205
+ var listeners = this._listeners;
206
+ if (!listeners) return;
207
+ if (object) {
208
+ object.off(events, callback, this);
209
+ if (!events && !callback) delete listeners[object._listenerId];
210
+ } else {
211
+ for (var id in listeners) {
212
+ listeners[id].off(null, null, this);
213
+ }
214
+ this._listeners = {};
215
+ }
216
+ return this;
217
+ }
218
+ };
219
+
220
+ // Aliases for backwards compatibility.
221
+ Events.bind = Events.on;
222
+ Events.unbind = Events.off;
223
+
224
+ // Allow the `Backbone` object to serve as a global event bus, for folks who
225
+ // want global "pubsub" in a convenient place.
226
+ _.extend(Backbone, Events);
227
+
228
+ // Backbone.Model
229
+ // --------------
230
+
231
+ // Create a new model, with defined attributes. A client id (`cid`)
232
+ // is automatically generated and assigned for you.
233
+ var Model = Backbone.Model = function(attributes, options) {
234
+ var defaults;
235
+ var attrs = attributes || {};
236
+ this.cid = _.uniqueId('c');
237
+ this.attributes = {};
238
+ if (options && options.collection) this.collection = options.collection;
239
+ if (options && options.parse) attrs = this.parse(attrs, options) || {};
240
+ if (defaults = _.result(this, 'defaults')) {
241
+ attrs = _.defaults({}, attrs, defaults);
242
+ }
243
+ this.set(attrs, options);
244
+ this.changed = {};
245
+ this.initialize.apply(this, arguments);
246
+ };
247
+
248
+ // Attach all inheritable methods to the Model prototype.
249
+ _.extend(Model.prototype, Events, {
250
+
251
+ // A hash of attributes whose current and previous value differ.
252
+ changed: null,
253
+
254
+ // The default name for the JSON `id` attribute is `"id"`. MongoDB and
255
+ // CouchDB users may want to set this to `"_id"`.
256
+ idAttribute: 'id',
257
+
258
+ // Initialize is an empty function by default. Override it with your own
259
+ // initialization logic.
260
+ initialize: function(){},
261
+
262
+ // Return a copy of the model's `attributes` object.
263
+ toJSON: function(options) {
264
+ return _.clone(this.attributes);
265
+ },
266
+
267
+ // Proxy `Backbone.sync` by default.
268
+ sync: function() {
269
+ return Backbone.sync.apply(this, arguments);
270
+ },
271
+
272
+ // Get the value of an attribute.
273
+ get: function(attr) {
274
+ return this.attributes[attr];
275
+ },
276
+
277
+ // Get the HTML-escaped value of an attribute.
278
+ escape: function(attr) {
279
+ return _.escape(this.get(attr));
280
+ },
281
+
282
+ // Returns `true` if the attribute contains a value that is not null
283
+ // or undefined.
284
+ has: function(attr) {
285
+ return this.get(attr) != null;
286
+ },
287
+
288
+ // ----------------------------------------------------------------------
289
+
290
+ // Set a hash of model attributes on the object, firing `"change"` unless
291
+ // you choose to silence it.
292
+ set: function(key, val, options) {
293
+ var attr, attrs, unset, changes, silent, changing, prev, current;
294
+ if (key == null) return this;
295
+
296
+ // Handle both `"key", value` and `{key: value}` -style arguments.
297
+ if (typeof key === 'object') {
298
+ attrs = key;
299
+ options = val;
300
+ } else {
301
+ (attrs = {})[key] = val;
302
+ }
303
+
304
+ options || (options = {});
305
+
306
+ // Run validation.
307
+ if (!this._validate(attrs, options)) return false;
308
+
309
+ // Extract attributes and options.
310
+ unset = options.unset;
311
+ silent = options.silent;
312
+ changes = [];
313
+ changing = this._changing;
314
+ this._changing = true;
315
+
316
+ if (!changing) {
317
+ this._previousAttributes = _.clone(this.attributes);
318
+ this.changed = {};
319
+ }
320
+ current = this.attributes, prev = this._previousAttributes;
321
+
322
+ // Check for changes of `id`.
323
+ if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
324
+
325
+ // For each `set` attribute, update or delete the current value.
326
+ for (attr in attrs) {
327
+ val = attrs[attr];
328
+ if (!_.isEqual(current[attr], val)) changes.push(attr);
329
+ if (!_.isEqual(prev[attr], val)) {
330
+ this.changed[attr] = val;
331
+ } else {
332
+ delete this.changed[attr];
333
+ }
334
+ unset ? delete current[attr] : current[attr] = val;
335
+ }
336
+
337
+ // Trigger all relevant attribute changes.
338
+ if (!silent) {
339
+ if (changes.length) this._pending = true;
340
+ for (var i = 0, l = changes.length; i < l; i++) {
341
+ this.trigger('change:' + changes[i], this, current[changes[i]], options);
342
+ }
343
+ }
344
+
345
+ if (changing) return this;
346
+ if (!silent) {
347
+ while (this._pending) {
348
+ this._pending = false;
349
+ this.trigger('change', this, options);
350
+ }
351
+ }
352
+ this._pending = false;
353
+ this._changing = false;
354
+ return this;
355
+ },
356
+
357
+ // Remove an attribute from the model, firing `"change"` unless you choose
358
+ // to silence it. `unset` is a noop if the attribute doesn't exist.
359
+ unset: function(attr, options) {
360
+ return this.set(attr, void 0, _.extend({}, options, {unset: true}));
361
+ },
362
+
363
+ // Clear all attributes on the model, firing `"change"` unless you choose
364
+ // to silence it.
365
+ clear: function(options) {
366
+ var attrs = {};
367
+ for (var key in this.attributes) attrs[key] = void 0;
368
+ return this.set(attrs, _.extend({}, options, {unset: true}));
369
+ },
370
+
371
+ // Determine if the model has changed since the last `"change"` event.
372
+ // If you specify an attribute name, determine if that attribute has changed.
373
+ hasChanged: function(attr) {
374
+ if (attr == null) return !_.isEmpty(this.changed);
375
+ return _.has(this.changed, attr);
376
+ },
377
+
378
+ // Return an object containing all the attributes that have changed, or
379
+ // false if there are no changed attributes. Useful for determining what
380
+ // parts of a view need to be updated and/or what attributes need to be
381
+ // persisted to the server. Unset attributes will be set to undefined.
382
+ // You can also pass an attributes object to diff against the model,
383
+ // determining if there *would be* a change.
384
+ changedAttributes: function(diff) {
385
+ if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
386
+ var val, changed = false;
387
+ var old = this._changing ? this._previousAttributes : this.attributes;
388
+ for (var attr in diff) {
389
+ if (_.isEqual(old[attr], (val = diff[attr]))) continue;
390
+ (changed || (changed = {}))[attr] = val;
391
+ }
392
+ return changed;
393
+ },
394
+
395
+ // Get the previous value of an attribute, recorded at the time the last
396
+ // `"change"` event was fired.
397
+ previous: function(attr) {
398
+ if (attr == null || !this._previousAttributes) return null;
399
+ return this._previousAttributes[attr];
400
+ },
401
+
402
+ // Get all of the attributes of the model at the time of the previous
403
+ // `"change"` event.
404
+ previousAttributes: function() {
405
+ return _.clone(this._previousAttributes);
406
+ },
407
+
408
+ // ---------------------------------------------------------------------
409
+
410
+ // Fetch the model from the server. If the server's representation of the
411
+ // model differs from its current attributes, they will be overriden,
412
+ // triggering a `"change"` event.
413
+ fetch: function(options) {
414
+ options = options ? _.clone(options) : {};
415
+ if (options.parse === void 0) options.parse = true;
416
+ var success = options.success;
417
+ options.success = function(model, resp, options) {
418
+ if (!model.set(model.parse(resp, options), options)) return false;
419
+ if (success) success(model, resp, options);
420
+ };
421
+ return this.sync('read', this, options);
422
+ },
423
+
424
+ // Set a hash of model attributes, and sync the model to the server.
425
+ // If the server returns an attributes hash that differs, the model's
426
+ // state will be `set` again.
427
+ save: function(key, val, options) {
428
+ var attrs, success, method, xhr, attributes = this.attributes;
429
+
430
+ // Handle both `"key", value` and `{key: value}` -style arguments.
431
+ if (key == null || typeof key === 'object') {
432
+ attrs = key;
433
+ options = val;
434
+ } else {
435
+ (attrs = {})[key] = val;
436
+ }
437
+
438
+ // If we're not waiting and attributes exist, save acts as `set(attr).save(null, opts)`.
439
+ if (attrs && (!options || !options.wait) && !this.set(attrs, options)) return false;
440
+
441
+ options = _.extend({validate: true}, options);
442
+
443
+ // Do not persist invalid models.
444
+ if (!this._validate(attrs, options)) return false;
445
+
446
+ // Set temporary attributes if `{wait: true}`.
447
+ if (attrs && options.wait) {
448
+ this.attributes = _.extend({}, attributes, attrs);
449
+ }
450
+
451
+ // After a successful server-side save, the client is (optionally)
452
+ // updated with the server-side state.
453
+ if (options.parse === void 0) options.parse = true;
454
+ success = options.success;
455
+ options.success = function(model, resp, options) {
456
+ // Ensure attributes are restored during synchronous saves.
457
+ model.attributes = attributes;
458
+ var serverAttrs = model.parse(resp, options);
459
+ if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
460
+ if (_.isObject(serverAttrs) && !model.set(serverAttrs, options)) {
461
+ return false;
462
+ }
463
+ if (success) success(model, resp, options);
464
+ };
465
+
466
+ // Finish configuring and sending the Ajax request.
467
+ method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
468
+ if (method == 'patch') options.attrs = attrs;
469
+ xhr = this.sync(method, this, options);
470
+
471
+ // Restore attributes.
472
+ if (attrs && options.wait) this.attributes = attributes;
473
+
474
+ return xhr;
475
+ },
476
+
477
+ // Destroy this model on the server if it was already persisted.
478
+ // Optimistically removes the model from its collection, if it has one.
479
+ // If `wait: true` is passed, waits for the server to respond before removal.
480
+ destroy: function(options) {
481
+ options = options ? _.clone(options) : {};
482
+ var model = this;
483
+ var success = options.success;
484
+
485
+ var destroy = function() {
486
+ model.trigger('destroy', model, model.collection, options);
487
+ };
488
+
489
+ options.success = function(model, resp, options) {
490
+ if (options.wait || model.isNew()) destroy();
491
+ if (success) success(model, resp, options);
492
+ };
493
+
494
+ if (this.isNew()) {
495
+ options.success(this, null, options);
496
+ return false;
497
+ }
498
+
499
+ var xhr = this.sync('delete', this, options);
500
+ if (!options.wait) destroy();
501
+ return xhr;
502
+ },
503
+
504
+ // Default URL for the model's representation on the server -- if you're
505
+ // using Backbone's restful methods, override this to change the endpoint
506
+ // that will be called.
507
+ url: function() {
508
+ var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError();
509
+ if (this.isNew()) return base;
510
+ return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id);
511
+ },
512
+
513
+ // **parse** converts a response into the hash of attributes to be `set` on
514
+ // the model. The default implementation is just to pass the response along.
515
+ parse: function(resp, options) {
516
+ return resp;
517
+ },
518
+
519
+ // Create a new model with identical attributes to this one.
520
+ clone: function() {
521
+ return new this.constructor(this.attributes);
522
+ },
523
+
524
+ // A model is new if it has never been saved to the server, and lacks an id.
525
+ isNew: function() {
526
+ return this.id == null;
527
+ },
528
+
529
+ // Check if the model is currently in a valid state.
530
+ isValid: function(options) {
531
+ return !this.validate || !this.validate(this.attributes, options);
532
+ },
533
+
534
+ // Run validation against the next complete set of model attributes,
535
+ // returning `true` if all is well. Otherwise, fire a general
536
+ // `"error"` event and call the error callback, if specified.
537
+ _validate: function(attrs, options) {
538
+ if (!options.validate || !this.validate) return true;
539
+ attrs = _.extend({}, this.attributes, attrs);
540
+ var error = this.validationError = this.validate(attrs, options) || null;
541
+ if (!error) return true;
542
+ this.trigger('invalid', this, error, options || {});
543
+ return false;
544
+ }
545
+
546
+ });
547
+
548
+ // Backbone.Collection
549
+ // -------------------
550
+
551
+ // Provides a standard collection class for our sets of models, ordered
552
+ // or unordered. If a `comparator` is specified, the Collection will maintain
553
+ // its models in sort order, as they're added and removed.
554
+ var Collection = Backbone.Collection = function(models, options) {
555
+ options || (options = {});
556
+ if (options.model) this.model = options.model;
557
+ if (options.comparator !== void 0) this.comparator = options.comparator;
558
+ this.models = [];
559
+ this._reset();
560
+ this.initialize.apply(this, arguments);
561
+ if (models) this.reset(models, _.extend({silent: true}, options));
562
+ };
563
+
564
+ // Define the Collection's inheritable methods.
565
+ _.extend(Collection.prototype, Events, {
566
+
567
+ // The default model for a collection is just a **Backbone.Model**.
568
+ // This should be overridden in most cases.
569
+ model: Model,
570
+
571
+ // Initialize is an empty function by default. Override it with your own
572
+ // initialization logic.
573
+ initialize: function(){},
574
+
575
+ // The JSON representation of a Collection is an array of the
576
+ // models' attributes.
577
+ toJSON: function(options) {
578
+ return this.map(function(model){ return model.toJSON(options); });
579
+ },
580
+
581
+ // Proxy `Backbone.sync` by default.
582
+ sync: function() {
583
+ return Backbone.sync.apply(this, arguments);
584
+ },
585
+
586
+ // Add a model, or list of models to the set.
587
+ add: function(models, options) {
588
+ models = _.isArray(models) ? models.slice() : [models];
589
+ options || (options = {});
590
+ var i, l, model, attrs, existing, doSort, add, at, sort, sortAttr;
591
+ add = [];
592
+ at = options.at;
593
+ sort = this.comparator && (at == null) && options.sort != false;
594
+ sortAttr = _.isString(this.comparator) ? this.comparator : null;
595
+
596
+ // Turn bare objects into model references, and prevent invalid models
597
+ // from being added.
598
+ for (i = 0, l = models.length; i < l; i++) {
599
+ if (!(model = this._prepareModel(attrs = models[i], options))) {
600
+ this.trigger('invalid', this, attrs, options);
601
+ continue;
602
+ }
603
+
604
+ // If a duplicate is found, prevent it from being added and
605
+ // optionally merge it into the existing model.
606
+ if (existing = this.get(model)) {
607
+ if (options.merge) {
608
+ existing.set(attrs === model ? model.attributes : attrs, options);
609
+ if (sort && !doSort && existing.hasChanged(sortAttr)) doSort = true;
610
+ }
611
+ continue;
612
+ }
613
+
614
+ // This is a new model, push it to the `add` list.
615
+ add.push(model);
616
+
617
+ // Listen to added models' events, and index models for lookup by
618
+ // `id` and by `cid`.
619
+ model.on('all', this._onModelEvent, this);
620
+ this._byId[model.cid] = model;
621
+ if (model.id != null) this._byId[model.id] = model;
622
+ }
623
+
624
+ // See if sorting is needed, update `length` and splice in new models.
625
+ if (add.length) {
626
+ if (sort) doSort = true;
627
+ this.length += add.length;
628
+ if (at != null) {
629
+ splice.apply(this.models, [at, 0].concat(add));
630
+ } else {
631
+ push.apply(this.models, add);
632
+ }
633
+ }
634
+
635
+ // Silently sort the collection if appropriate.
636
+ if (doSort) this.sort({silent: true});
637
+
638
+ if (options.silent) return this;
639
+
640
+ // Trigger `add` events.
641
+ for (i = 0, l = add.length; i < l; i++) {
642
+ (model = add[i]).trigger('add', model, this, options);
643
+ }
644
+
645
+ // Trigger `sort` if the collection was sorted.
646
+ if (doSort) this.trigger('sort', this, options);
647
+
648
+ return this;
649
+ },
650
+
651
+ // Remove a model, or a list of models from the set.
652
+ remove: function(models, options) {
653
+ models = _.isArray(models) ? models.slice() : [models];
654
+ options || (options = {});
655
+ var i, l, index, model;
656
+ for (i = 0, l = models.length; i < l; i++) {
657
+ model = this.get(models[i]);
658
+ if (!model) continue;
659
+ delete this._byId[model.id];
660
+ delete this._byId[model.cid];
661
+ index = this.indexOf(model);
662
+ this.models.splice(index, 1);
663
+ this.length--;
664
+ if (!options.silent) {
665
+ options.index = index;
666
+ model.trigger('remove', model, this, options);
667
+ }
668
+ this._removeReference(model);
669
+ }
670
+ return this;
671
+ },
672
+
673
+ // Add a model to the end of the collection.
674
+ push: function(model, options) {
675
+ model = this._prepareModel(model, options);
676
+ this.add(model, _.extend({at: this.length}, options));
677
+ return model;
678
+ },
679
+
680
+ // Remove a model from the end of the collection.
681
+ pop: function(options) {
682
+ var model = this.at(this.length - 1);
683
+ this.remove(model, options);
684
+ return model;
685
+ },
686
+
687
+ // Add a model to the beginning of the collection.
688
+ unshift: function(model, options) {
689
+ model = this._prepareModel(model, options);
690
+ this.add(model, _.extend({at: 0}, options));
691
+ return model;
692
+ },
693
+
694
+ // Remove a model from the beginning of the collection.
695
+ shift: function(options) {
696
+ var model = this.at(0);
697
+ this.remove(model, options);
698
+ return model;
699
+ },
700
+
701
+ // Slice out a sub-array of models from the collection.
702
+ slice: function(begin, end) {
703
+ return this.models.slice(begin, end);
704
+ },
705
+
706
+ // Get a model from the set by id.
707
+ get: function(obj) {
708
+ if (obj == null) return void 0;
709
+ this._idAttr || (this._idAttr = this.model.prototype.idAttribute);
710
+ return this._byId[obj.id || obj.cid || obj[this._idAttr] || obj];
711
+ },
712
+
713
+ // Get the model at the given index.
714
+ at: function(index) {
715
+ return this.models[index];
716
+ },
717
+
718
+ // Return models with matching attributes. Useful for simple cases of `filter`.
719
+ where: function(attrs) {
720
+ if (_.isEmpty(attrs)) return [];
721
+ return this.filter(function(model) {
722
+ for (var key in attrs) {
723
+ if (attrs[key] !== model.get(key)) return false;
724
+ }
725
+ return true;
726
+ });
727
+ },
728
+
729
+ // Force the collection to re-sort itself. You don't need to call this under
730
+ // normal circumstances, as the set will maintain sort order as each item
731
+ // is added.
732
+ sort: function(options) {
733
+ if (!this.comparator) {
734
+ throw new Error('Cannot sort a set without a comparator');
735
+ }
736
+ options || (options = {});
737
+
738
+ // Run sort based on type of `comparator`.
739
+ if (_.isString(this.comparator) || this.comparator.length === 1) {
740
+ this.models = this.sortBy(this.comparator, this);
741
+ } else {
742
+ this.models.sort(_.bind(this.comparator, this));
743
+ }
744
+
745
+ if (!options.silent) this.trigger('sort', this, options);
746
+ return this;
747
+ },
748
+
749
+ // Pluck an attribute from each model in the collection.
750
+ pluck: function(attr) {
751
+ return _.invoke(this.models, 'get', attr);
752
+ },
753
+
754
+ // Smartly update a collection with a change set of models, adding,
755
+ // removing, and merging as necessary.
756
+ update: function(models, options) {
757
+ options = _.extend({add: true, merge: true, remove: true}, options);
758
+ if (options.parse) models = this.parse(models, options);
759
+ var model, i, l, existing;
760
+ var add = [], remove = [], modelMap = {};
761
+
762
+ // Allow a single model (or no argument) to be passed.
763
+ if (!_.isArray(models)) models = models ? [models] : [];
764
+
765
+ // Proxy to `add` for this case, no need to iterate...
766
+ if (options.add && !options.remove) return this.add(models, options);
767
+
768
+ // Determine which models to add and merge, and which to remove.
769
+ for (i = 0, l = models.length; i < l; i++) {
770
+ model = models[i];
771
+ existing = this.get(model);
772
+ if (options.remove && existing) modelMap[existing.cid] = true;
773
+ if ((options.add && !existing) || (options.merge && existing)) {
774
+ add.push(model);
775
+ }
776
+ }
777
+ if (options.remove) {
778
+ for (i = 0, l = this.models.length; i < l; i++) {
779
+ model = this.models[i];
780
+ if (!modelMap[model.cid]) remove.push(model);
781
+ }
782
+ }
783
+
784
+ // Remove models (if applicable) before we add and merge the rest.
785
+ if (remove.length) this.remove(remove, options);
786
+ if (add.length) this.add(add, options);
787
+ return this;
788
+ },
789
+
790
+ // When you have more items than you want to add or remove individually,
791
+ // you can reset the entire set with a new list of models, without firing
792
+ // any `add` or `remove` events. Fires `reset` when finished.
793
+ reset: function(models, options) {
794
+ options || (options = {});
795
+ if (options.parse) models = this.parse(models, options);
796
+ for (var i = 0, l = this.models.length; i < l; i++) {
797
+ this._removeReference(this.models[i]);
798
+ }
799
+ options.previousModels = this.models.slice();
800
+ this._reset();
801
+ if (models) this.add(models, _.extend({silent: true}, options));
802
+ if (!options.silent) this.trigger('reset', this, options);
803
+ return this;
804
+ },
805
+
806
+ // Fetch the default set of models for this collection, resetting the
807
+ // collection when they arrive. If `update: true` is passed, the response
808
+ // data will be passed through the `update` method instead of `reset`.
809
+ fetch: function(options) {
810
+ options = options ? _.clone(options) : {};
811
+ if (options.parse === void 0) options.parse = true;
812
+ var success = options.success;
813
+ options.success = function(collection, resp, options) {
814
+ var method = options.update ? 'update' : 'reset';
815
+ collection[method](resp, options);
816
+ if (success) success(collection, resp, options);
817
+ };
818
+ return this.sync('read', this, options);
819
+ },
820
+
821
+ // Create a new instance of a model in this collection. Add the model to the
822
+ // collection immediately, unless `wait: true` is passed, in which case we
823
+ // wait for the server to agree.
824
+ create: function(model, options) {
825
+ options = options ? _.clone(options) : {};
826
+ if (!(model = this._prepareModel(model, options))) return false;
827
+ if (!options.wait) this.add(model, options);
828
+ var collection = this;
829
+ var success = options.success;
830
+ options.success = function(model, resp, options) {
831
+ if (options.wait) collection.add(model, options);
832
+ if (success) success(model, resp, options);
833
+ };
834
+ model.save(null, options);
835
+ return model;
836
+ },
837
+
838
+ // **parse** converts a response into a list of models to be added to the
839
+ // collection. The default implementation is just to pass it through.
840
+ parse: function(resp, options) {
841
+ return resp;
842
+ },
843
+
844
+ // Create a new collection with an identical list of models as this one.
845
+ clone: function() {
846
+ return new this.constructor(this.models);
847
+ },
848
+
849
+ // Reset all internal state. Called when the collection is reset.
850
+ _reset: function() {
851
+ this.length = 0;
852
+ this.models.length = 0;
853
+ this._byId = {};
854
+ },
855
+
856
+ // Prepare a model or hash of attributes to be added to this collection.
857
+ _prepareModel: function(attrs, options) {
858
+ if (attrs instanceof Model) {
859
+ if (!attrs.collection) attrs.collection = this;
860
+ return attrs;
861
+ }
862
+ options || (options = {});
863
+ options.collection = this;
864
+ var model = new this.model(attrs, options);
865
+ if (!model._validate(attrs, options)) return false;
866
+ return model;
867
+ },
868
+
869
+ // Internal method to remove a model's ties to a collection.
870
+ _removeReference: function(model) {
871
+ if (this === model.collection) delete model.collection;
872
+ model.off('all', this._onModelEvent, this);
873
+ },
874
+
875
+ // Internal method called every time a model in the set fires an event.
876
+ // Sets need to update their indexes when models change ids. All other
877
+ // events simply proxy through. "add" and "remove" events that originate
878
+ // in other collections are ignored.
879
+ _onModelEvent: function(event, model, collection, options) {
880
+ if ((event === 'add' || event === 'remove') && collection !== this) return;
881
+ if (event === 'destroy') this.remove(model, options);
882
+ if (model && event === 'change:' + model.idAttribute) {
883
+ delete this._byId[model.previous(model.idAttribute)];
884
+ if (model.id != null) this._byId[model.id] = model;
885
+ }
886
+ this.trigger.apply(this, arguments);
887
+ },
888
+
889
+ sortedIndex: function (model, value, context) {
890
+ value || (value = this.comparator);
891
+ var iterator = _.isFunction(value) ? value : function(model) {
892
+ return model.get(value);
893
+ };
894
+ return _.sortedIndex(this.models, model, iterator, context);
895
+ }
896
+
897
+ });
898
+
899
+ // Underscore methods that we want to implement on the Collection.
900
+ var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
901
+ 'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
902
+ 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
903
+ 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
904
+ 'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
905
+ 'isEmpty', 'chain'];
906
+
907
+ // Mix in each Underscore method as a proxy to `Collection#models`.
908
+ _.each(methods, function(method) {
909
+ Collection.prototype[method] = function() {
910
+ var args = slice.call(arguments);
911
+ args.unshift(this.models);
912
+ return _[method].apply(_, args);
913
+ };
914
+ });
915
+
916
+ // Underscore methods that take a property name as an argument.
917
+ var attributeMethods = ['groupBy', 'countBy', 'sortBy'];
918
+
919
+ // Use attributes instead of properties.
920
+ _.each(attributeMethods, function(method) {
921
+ Collection.prototype[method] = function(value, context) {
922
+ var iterator = _.isFunction(value) ? value : function(model) {
923
+ return model.get(value);
924
+ };
925
+ return _[method](this.models, iterator, context);
926
+ };
927
+ });
928
+
929
+ // Backbone.Router
930
+ // ---------------
931
+
932
+ // Routers map faux-URLs to actions, and fire events when routes are
933
+ // matched. Creating a new one sets its `routes` hash, if not set statically.
934
+ var Router = Backbone.Router = function(options) {
935
+ options || (options = {});
936
+ if (options.routes) this.routes = options.routes;
937
+ this._bindRoutes();
938
+ this.initialize.apply(this, arguments);
939
+ };
940
+
941
+ // Cached regular expressions for matching named param parts and splatted
942
+ // parts of route strings.
943
+ var optionalParam = /\((.*?)\)/g;
944
+ var namedParam = /(\(\?)?:\w+/g;
945
+ var splatParam = /\*\w+/g;
946
+ var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
947
+
948
+ // Set up all inheritable **Backbone.Router** properties and methods.
949
+ _.extend(Router.prototype, Events, {
950
+
951
+ // Initialize is an empty function by default. Override it with your own
952
+ // initialization logic.
953
+ initialize: function(){},
954
+
955
+ // Manually bind a single named route to a callback. For example:
956
+ //
957
+ // this.route('search/:query/p:num', 'search', function(query, num) {
958
+ // ...
959
+ // });
960
+ //
961
+ route: function(route, name, callback) {
962
+ if (!_.isRegExp(route)) route = this._routeToRegExp(route);
963
+ if (!callback) callback = this[name];
964
+ Backbone.history.route(route, _.bind(function(fragment) {
965
+ var args = this._extractParameters(route, fragment);
966
+ callback && callback.apply(this, args);
967
+ this.trigger.apply(this, ['route:' + name].concat(args));
968
+ this.trigger('route', name, args);
969
+ Backbone.history.trigger('route', this, name, args);
970
+ }, this));
971
+ return this;
972
+ },
973
+
974
+ // Simple proxy to `Backbone.history` to save a fragment into the history.
975
+ navigate: function(fragment, options) {
976
+ Backbone.history.navigate(fragment, options);
977
+ return this;
978
+ },
979
+
980
+ // Bind all defined routes to `Backbone.history`. We have to reverse the
981
+ // order of the routes here to support behavior where the most general
982
+ // routes can be defined at the bottom of the route map.
983
+ _bindRoutes: function() {
984
+ if (!this.routes) return;
985
+ var route, routes = _.keys(this.routes);
986
+ while ((route = routes.pop()) != null) {
987
+ this.route(route, this.routes[route]);
988
+ }
989
+ },
990
+
991
+ // Convert a route string into a regular expression, suitable for matching
992
+ // against the current location hash.
993
+ _routeToRegExp: function(route) {
994
+ route = route.replace(escapeRegExp, '\\$&')
995
+ .replace(optionalParam, '(?:$1)?')
996
+ .replace(namedParam, function(match, optional){
997
+ return optional ? match : '([^\/]+)';
998
+ })
999
+ .replace(splatParam, '(.*?)');
1000
+ return new RegExp('^' + route + '$');
1001
+ },
1002
+
1003
+ // Given a route, and a URL fragment that it matches, return the array of
1004
+ // extracted parameters.
1005
+ _extractParameters: function(route, fragment) {
1006
+ return route.exec(fragment).slice(1);
1007
+ }
1008
+
1009
+ });
1010
+
1011
+ // Backbone.History
1012
+ // ----------------
1013
+
1014
+ // Handles cross-browser history management, based on URL fragments. If the
1015
+ // browser does not support `onhashchange`, falls back to polling.
1016
+ var History = Backbone.History = function() {
1017
+ this.handlers = [];
1018
+ _.bindAll(this, 'checkUrl');
1019
+
1020
+ // Ensure that `History` can be used outside of the browser.
1021
+ if (typeof window !== 'undefined') {
1022
+ this.location = window.location;
1023
+ this.history = window.history;
1024
+ }
1025
+ };
1026
+
1027
+ // Cached regex for stripping a leading hash/slash and trailing space.
1028
+ var routeStripper = /^[#\/]|\s+$/g;
1029
+
1030
+ // Cached regex for stripping leading and trailing slashes.
1031
+ var rootStripper = /^\/+|\/+$/g;
1032
+
1033
+ // Cached regex for detecting MSIE.
1034
+ var isExplorer = /msie [\w.]+/;
1035
+
1036
+ // Cached regex for removing a trailing slash.
1037
+ var trailingSlash = /\/$/;
1038
+
1039
+ // Has the history handling already been started?
1040
+ History.started = false;
1041
+
1042
+ // Set up all inheritable **Backbone.History** properties and methods.
1043
+ _.extend(History.prototype, Events, {
1044
+
1045
+ // The default interval to poll for hash changes, if necessary, is
1046
+ // twenty times a second.
1047
+ interval: 50,
1048
+
1049
+ // Gets the true hash value. Cannot use location.hash directly due to bug
1050
+ // in Firefox where location.hash will always be decoded.
1051
+ getHash: function(window) {
1052
+ var match = (window || this).location.href.match(/#(.*)$/);
1053
+ return match ? match[1] : '';
1054
+ },
1055
+
1056
+ // Get the cross-browser normalized URL fragment, either from the URL,
1057
+ // the hash, or the override.
1058
+ getFragment: function(fragment, forcePushState) {
1059
+ if (fragment == null) {
1060
+ if (this._hasPushState || !this._wantsHashChange || forcePushState) {
1061
+ fragment = this.location.pathname;
1062
+ var root = this.root.replace(trailingSlash, '');
1063
+ if (!fragment.indexOf(root)) fragment = fragment.substr(root.length);
1064
+ } else {
1065
+ fragment = this.getHash();
1066
+ }
1067
+ }
1068
+ return fragment.replace(routeStripper, '');
1069
+ },
1070
+
1071
+ // Start the hash change handling, returning `true` if the current URL matches
1072
+ // an existing route, and `false` otherwise.
1073
+ start: function(options) {
1074
+ if (History.started) throw new Error("Backbone.history has already been started");
1075
+ History.started = true;
1076
+
1077
+ // Figure out the initial configuration. Do we need an iframe?
1078
+ // Is pushState desired ... is it available?
1079
+ this.options = _.extend({}, {root: '/'}, this.options, options);
1080
+ this.root = this.options.root;
1081
+ this._wantsHashChange = this.options.hashChange !== false;
1082
+ this._wantsPushState = !!this.options.pushState;
1083
+ this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState);
1084
+ var fragment = this.getFragment();
1085
+ var docMode = document.documentMode;
1086
+ var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7));
1087
+
1088
+ // Normalize root to always include a leading and trailing slash.
1089
+ this.root = ('/' + this.root + '/').replace(rootStripper, '/');
1090
+
1091
+ if (oldIE && this._wantsHashChange) {
1092
+ this.iframe = Backbone.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow;
1093
+ this.navigate(fragment);
1094
+ }
1095
+
1096
+ // Depending on whether we're using pushState or hashes, and whether
1097
+ // 'onhashchange' is supported, determine how we check the URL state.
1098
+ if (this._hasPushState) {
1099
+ Backbone.$(window).on('popstate', this.checkUrl);
1100
+ } else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) {
1101
+ Backbone.$(window).on('hashchange', this.checkUrl);
1102
+ } else if (this._wantsHashChange) {
1103
+ this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
1104
+ }
1105
+
1106
+ // Determine if we need to change the base url, for a pushState link
1107
+ // opened by a non-pushState browser.
1108
+ this.fragment = fragment;
1109
+ var loc = this.location;
1110
+ var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;
1111
+
1112
+ // If we've started off with a route from a `pushState`-enabled browser,
1113
+ // but we're currently in a browser that doesn't support it...
1114
+ if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) {
1115
+ this.fragment = this.getFragment(null, true);
1116
+ this.location.replace(this.root + this.location.search + '#' + this.fragment);
1117
+ // Return immediately as browser will do redirect to new url
1118
+ return true;
1119
+
1120
+ // Or if we've started out with a hash-based route, but we're currently
1121
+ // in a browser where it could be `pushState`-based instead...
1122
+ } else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
1123
+ this.fragment = this.getHash().replace(routeStripper, '');
1124
+ this.history.replaceState({}, document.title, this.root + this.fragment + loc.search);
1125
+ }
1126
+
1127
+ if (!this.options.silent) return this.loadUrl();
1128
+ },
1129
+
1130
+ // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
1131
+ // but possibly useful for unit testing Routers.
1132
+ stop: function() {
1133
+ Backbone.$(window).off('popstate', this.checkUrl).off('hashchange', this.checkUrl);
1134
+ clearInterval(this._checkUrlInterval);
1135
+ History.started = false;
1136
+ },
1137
+
1138
+ // Add a route to be tested when the fragment changes. Routes added later
1139
+ // may override previous routes.
1140
+ route: function(route, callback) {
1141
+ this.handlers.unshift({route: route, callback: callback});
1142
+ },
1143
+
1144
+ // Checks the current URL to see if it has changed, and if it has,
1145
+ // calls `loadUrl`, normalizing across the hidden iframe.
1146
+ checkUrl: function(e) {
1147
+ var current = this.getFragment();
1148
+ if (current === this.fragment && this.iframe) {
1149
+ current = this.getFragment(this.getHash(this.iframe));
1150
+ }
1151
+ if (current === this.fragment) return false;
1152
+ if (this.iframe) this.navigate(current);
1153
+ this.loadUrl() || this.loadUrl(this.getHash());
1154
+ },
1155
+
1156
+ // Attempt to load the current URL fragment. If a route succeeds with a
1157
+ // match, returns `true`. If no defined routes matches the fragment,
1158
+ // returns `false`.
1159
+ loadUrl: function(fragmentOverride) {
1160
+ var fragment = this.fragment = this.getFragment(fragmentOverride);
1161
+ var matched = _.any(this.handlers, function(handler) {
1162
+ if (handler.route.test(fragment)) {
1163
+ handler.callback(fragment);
1164
+ return true;
1165
+ }
1166
+ });
1167
+ return matched;
1168
+ },
1169
+
1170
+ // Save a fragment into the hash history, or replace the URL state if the
1171
+ // 'replace' option is passed. You are responsible for properly URL-encoding
1172
+ // the fragment in advance.
1173
+ //
1174
+ // The options object can contain `trigger: true` if you wish to have the
1175
+ // route callback be fired (not usually desirable), or `replace: true`, if
1176
+ // you wish to modify the current URL without adding an entry to the history.
1177
+ navigate: function(fragment, options) {
1178
+ if (!History.started) return false;
1179
+ if (!options || options === true) options = {trigger: options};
1180
+ fragment = this.getFragment(fragment || '');
1181
+ if (this.fragment === fragment) return;
1182
+ this.fragment = fragment;
1183
+ var url = this.root + fragment;
1184
+
1185
+ // If pushState is available, we use it to set the fragment as a real URL.
1186
+ if (this._hasPushState) {
1187
+ this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
1188
+
1189
+ // If hash changes haven't been explicitly disabled, update the hash
1190
+ // fragment to store history.
1191
+ } else if (this._wantsHashChange) {
1192
+ this._updateHash(this.location, fragment, options.replace);
1193
+ if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) {
1194
+ // Opening and closing the iframe tricks IE7 and earlier to push a
1195
+ // history entry on hash-tag change. When replace is true, we don't
1196
+ // want this.
1197
+ if(!options.replace) this.iframe.document.open().close();
1198
+ this._updateHash(this.iframe.location, fragment, options.replace);
1199
+ }
1200
+
1201
+ // If you've told us that you explicitly don't want fallback hashchange-
1202
+ // based history, then `navigate` becomes a page refresh.
1203
+ } else {
1204
+ return this.location.assign(url);
1205
+ }
1206
+ if (options.trigger) this.loadUrl(fragment);
1207
+ },
1208
+
1209
+ // Update the hash location, either replacing the current entry, or adding
1210
+ // a new one to the browser history.
1211
+ _updateHash: function(location, fragment, replace) {
1212
+ if (replace) {
1213
+ var href = location.href.replace(/(javascript:|#).*$/, '');
1214
+ location.replace(href + '#' + fragment);
1215
+ } else {
1216
+ // Some browsers require that `hash` contains a leading #.
1217
+ location.hash = '#' + fragment;
1218
+ }
1219
+ }
1220
+
1221
+ });
1222
+
1223
+ // Create the default Backbone.history.
1224
+ Backbone.history = new History;
1225
+
1226
+ // Backbone.View
1227
+ // -------------
1228
+
1229
+ // Creating a Backbone.View creates its initial element outside of the DOM,
1230
+ // if an existing element is not provided...
1231
+ var View = Backbone.View = function(options) {
1232
+ this.cid = _.uniqueId('view');
1233
+ this._configure(options || {});
1234
+ this._ensureElement();
1235
+ this.initialize.apply(this, arguments);
1236
+ this.delegateEvents();
1237
+ };
1238
+
1239
+ // Cached regex to split keys for `delegate`.
1240
+ var delegateEventSplitter = /^(\S+)\s*(.*)$/;
1241
+
1242
+ // List of view options to be merged as properties.
1243
+ var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
1244
+
1245
+ // Set up all inheritable **Backbone.View** properties and methods.
1246
+ _.extend(View.prototype, Events, {
1247
+
1248
+ // The default `tagName` of a View's element is `"div"`.
1249
+ tagName: 'div',
1250
+
1251
+ // jQuery delegate for element lookup, scoped to DOM elements within the
1252
+ // current view. This should be prefered to global lookups where possible.
1253
+ $: function(selector) {
1254
+ return this.$el.find(selector);
1255
+ },
1256
+
1257
+ // Initialize is an empty function by default. Override it with your own
1258
+ // initialization logic.
1259
+ initialize: function(){},
1260
+
1261
+ // **render** is the core function that your view should override, in order
1262
+ // to populate its element (`this.el`), with the appropriate HTML. The
1263
+ // convention is for **render** to always return `this`.
1264
+ render: function() {
1265
+ return this;
1266
+ },
1267
+
1268
+ // Remove this view by taking the element out of the DOM, and removing any
1269
+ // applicable Backbone.Events listeners.
1270
+ remove: function() {
1271
+ this.$el.remove();
1272
+ this.stopListening();
1273
+ return this;
1274
+ },
1275
+
1276
+ // Change the view's element (`this.el` property), including event
1277
+ // re-delegation.
1278
+ setElement: function(element, delegate) {
1279
+ if (this.$el) this.undelegateEvents();
1280
+ this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
1281
+ this.el = this.$el[0];
1282
+ if (delegate !== false) this.delegateEvents();
1283
+ return this;
1284
+ },
1285
+
1286
+ // Set callbacks, where `this.events` is a hash of
1287
+ //
1288
+ // *{"event selector": "callback"}*
1289
+ //
1290
+ // {
1291
+ // 'mousedown .title': 'edit',
1292
+ // 'click .button': 'save'
1293
+ // 'click .open': function(e) { ... }
1294
+ // }
1295
+ //
1296
+ // pairs. Callbacks will be bound to the view, with `this` set properly.
1297
+ // Uses event delegation for efficiency.
1298
+ // Omitting the selector binds the event to `this.el`.
1299
+ // This only works for delegate-able events: not `focus`, `blur`, and
1300
+ // not `change`, `submit`, and `reset` in Internet Explorer.
1301
+ delegateEvents: function(events) {
1302
+ if (!(events || (events = _.result(this, 'events')))) return;
1303
+ this.undelegateEvents();
1304
+ for (var key in events) {
1305
+ var method = events[key];
1306
+ if (!_.isFunction(method)) method = this[events[key]];
1307
+ if (!method) throw new Error('Method "' + events[key] + '" does not exist');
1308
+ var match = key.match(delegateEventSplitter);
1309
+ var eventName = match[1], selector = match[2];
1310
+ method = _.bind(method, this);
1311
+ eventName += '.delegateEvents' + this.cid;
1312
+ if (selector === '') {
1313
+ this.$el.on(eventName, method);
1314
+ } else {
1315
+ this.$el.on(eventName, selector, method);
1316
+ }
1317
+ }
1318
+ },
1319
+
1320
+ // Clears all callbacks previously bound to the view with `delegateEvents`.
1321
+ // You usually don't need to use this, but may wish to if you have multiple
1322
+ // Backbone views attached to the same DOM element.
1323
+ undelegateEvents: function() {
1324
+ this.$el.off('.delegateEvents' + this.cid);
1325
+ },
1326
+
1327
+ // Performs the initial configuration of a View with a set of options.
1328
+ // Keys with special meaning *(model, collection, id, className)*, are
1329
+ // attached directly to the view.
1330
+ _configure: function(options) {
1331
+ if (this.options) options = _.extend({}, _.result(this, 'options'), options);
1332
+ _.extend(this, _.pick(options, viewOptions));
1333
+ this.options = options;
1334
+ },
1335
+
1336
+ // Ensure that the View has a DOM element to render into.
1337
+ // If `this.el` is a string, pass it through `$()`, take the first
1338
+ // matching element, and re-assign it to `el`. Otherwise, create
1339
+ // an element from the `id`, `className` and `tagName` properties.
1340
+ _ensureElement: function() {
1341
+ if (!this.el) {
1342
+ var attrs = _.extend({}, _.result(this, 'attributes'));
1343
+ if (this.id) attrs.id = _.result(this, 'id');
1344
+ if (this.className) attrs['class'] = _.result(this, 'className');
1345
+ var $el = Backbone.$('<' + _.result(this, 'tagName') + '>').attr(attrs);
1346
+ this.setElement($el, false);
1347
+ } else {
1348
+ this.setElement(_.result(this, 'el'), false);
1349
+ }
1350
+ }
1351
+
1352
+ });
1353
+
1354
+ // Backbone.sync
1355
+ // -------------
1356
+
1357
+ // Map from CRUD to HTTP for our default `Backbone.sync` implementation.
1358
+ var methodMap = {
1359
+ 'create': 'POST',
1360
+ 'update': 'PUT',
1361
+ 'patch': 'PATCH',
1362
+ 'delete': 'DELETE',
1363
+ 'read': 'GET'
1364
+ };
1365
+
1366
+ // Override this function to change the manner in which Backbone persists
1367
+ // models to the server. You will be passed the type of request, and the
1368
+ // model in question. By default, makes a RESTful Ajax request
1369
+ // to the model's `url()`. Some possible customizations could be:
1370
+ //
1371
+ // * Use `setTimeout` to batch rapid-fire updates into a single request.
1372
+ // * Send up the models as XML instead of JSON.
1373
+ // * Persist models via WebSockets instead of Ajax.
1374
+ //
1375
+ // Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
1376
+ // as `POST`, with a `_method` parameter containing the true HTTP method,
1377
+ // as well as all requests with the body as `application/x-www-form-urlencoded`
1378
+ // instead of `application/json` with the model in a param named `model`.
1379
+ // Useful when interfacing with server-side languages like **PHP** that make
1380
+ // it difficult to read the body of `PUT` requests.
1381
+ Backbone.sync = function(method, model, options) {
1382
+ var type = methodMap[method];
1383
+
1384
+ // Default options, unless specified.
1385
+ _.defaults(options || (options = {}), {
1386
+ emulateHTTP: Backbone.emulateHTTP,
1387
+ emulateJSON: Backbone.emulateJSON
1388
+ });
1389
+
1390
+ // Default JSON-request options.
1391
+ var params = {type: type, dataType: 'json'};
1392
+
1393
+ // Ensure that we have a URL.
1394
+ if (!options.url) {
1395
+ params.url = _.result(model, 'url') || urlError();
1396
+ }
1397
+
1398
+ // Ensure that we have the appropriate request data.
1399
+ if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
1400
+ params.contentType = 'application/json';
1401
+ params.data = JSON.stringify(options.attrs || model.toJSON(options));
1402
+ }
1403
+
1404
+ // For older servers, emulate JSON by encoding the request into an HTML-form.
1405
+ if (options.emulateJSON) {
1406
+ params.contentType = 'application/x-www-form-urlencoded';
1407
+ params.data = params.data ? {model: params.data} : {};
1408
+ }
1409
+
1410
+ // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
1411
+ // And an `X-HTTP-Method-Override` header.
1412
+ if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
1413
+ params.type = 'POST';
1414
+ if (options.emulateJSON) params.data._method = type;
1415
+ var beforeSend = options.beforeSend;
1416
+ options.beforeSend = function(xhr) {
1417
+ xhr.setRequestHeader('X-HTTP-Method-Override', type);
1418
+ if (beforeSend) return beforeSend.apply(this, arguments);
1419
+ };
1420
+ }
1421
+
1422
+ // Don't process data on a non-GET request.
1423
+ if (params.type !== 'GET' && !options.emulateJSON) {
1424
+ params.processData = false;
1425
+ }
1426
+
1427
+ var success = options.success;
1428
+ options.success = function(resp) {
1429
+ if (success) success(model, resp, options);
1430
+ model.trigger('sync', model, resp, options);
1431
+ };
1432
+
1433
+ var error = options.error;
1434
+ options.error = function(xhr) {
1435
+ if (error) error(model, xhr, options);
1436
+ model.trigger('error', model, xhr, options);
1437
+ };
1438
+
1439
+ // Make the request, allowing the user to override any Ajax options.
1440
+ var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
1441
+ model.trigger('request', model, xhr, options);
1442
+ return xhr;
1443
+ };
1444
+
1445
+ // Set the default implementation of `Backbone.ajax` to proxy through to `$`.
1446
+ Backbone.ajax = function() {
1447
+ return Backbone.$.ajax.apply(Backbone.$, arguments);
1448
+ };
1449
+
1450
+ // Helpers
1451
+ // -------
1452
+
1453
+ // Helper function to correctly set up the prototype chain, for subclasses.
1454
+ // Similar to `goog.inherits`, but uses a hash of prototype properties and
1455
+ // class properties to be extended.
1456
+ var extend = function(protoProps, staticProps) {
1457
+ var parent = this;
1458
+ var child;
1459
+
1460
+ // The constructor function for the new subclass is either defined by you
1461
+ // (the "constructor" property in your `extend` definition), or defaulted
1462
+ // by us to simply call the parent's constructor.
1463
+ if (protoProps && _.has(protoProps, 'constructor')) {
1464
+ child = protoProps.constructor;
1465
+ } else {
1466
+ child = function(){ return parent.apply(this, arguments); };
1467
+ }
1468
+
1469
+ // Add static properties to the constructor function, if supplied.
1470
+ _.extend(child, parent, staticProps);
1471
+
1472
+ // Set the prototype chain to inherit from `parent`, without calling
1473
+ // `parent`'s constructor function.
1474
+ var Surrogate = function(){ this.constructor = child; };
1475
+ Surrogate.prototype = parent.prototype;
1476
+ child.prototype = new Surrogate;
1477
+
1478
+ // Add prototype properties (instance properties) to the subclass,
1479
+ // if supplied.
1480
+ if (protoProps) _.extend(child.prototype, protoProps);
1481
+
1482
+ // Set a convenience property in case the parent's prototype is needed
1483
+ // later.
1484
+ child.__super__ = parent.prototype;
1485
+
1486
+ return child;
1487
+ };
1488
+
1489
+ // Set up inheritance for the model, collection, router, view and history.
1490
+ Model.extend = Collection.extend = Router.extend = View.extend = History.extend = extend;
1491
+
1492
+ // Throw an error when a URL is needed, and none is supplied.
1493
+ var urlError = function() {
1494
+ throw new Error('A "url" property or function must be specified');
1495
+ };
1496
+
1497
+ }).call(this);