js_stack 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- //= require js_stack/base/marionette/1.7.0
1
+ //= require js_stack/base/marionette/1.7.3
@@ -0,0 +1,207 @@
1
+ /*! Backbone.Mutators - v0.4.2
2
+ ------------------------------
3
+ Build @ 2014-03-27
4
+ Documentation and Full License Available at:
5
+ http://asciidisco.github.com/Backbone.Mutators/index.html
6
+ git://github.com/asciidisco/Backbone.Mutators.git
7
+ Copyright (c) 2014 Sebastian Golasch <public@asciidisco.com>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a
10
+ copy of this software and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction, including without limitation
12
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
+ and/or sell copies of the Software, and to permit persons to whom the
14
+
15
+ Software is furnished to do so, subject to the following conditions:
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
+ IN THE SOFTWARE.*/
26
+ (function (root, factory, undef) {
27
+ 'use strict';
28
+
29
+ if (typeof exports === 'object') {
30
+ // Node. Does not work with strict CommonJS, but
31
+ // only CommonJS-like enviroments that support module.exports,
32
+ // like Node.
33
+ module.exports = factory(require('underscore'), require('backbone'));
34
+ } else if (typeof define === 'function' && define.amd) {
35
+ // AMD. Register as an anonymous module.
36
+ define(['underscore', 'backbone'], function (_, Backbone) {
37
+ // Check if we use the AMD branch of Back
38
+ _ = _ === undef ? root._ : _;
39
+ Backbone = Backbone === undef ? root.Backbone : Backbone;
40
+ return (root.returnExportsGlobal = factory(_, Backbone, root));
41
+ });
42
+ } else {
43
+ // Browser globals
44
+ root.returnExportsGlobal = factory(root._, root.Backbone);
45
+ }
46
+
47
+ // Usage:
48
+ //
49
+ // Note: This plugin is UMD compatible, you can use it in node, amd and vanilla js envs
50
+ //
51
+ // Vanilla JS:
52
+ // <script src="underscore.js"></script>
53
+ // <script src="backbone.js"></script>
54
+ // <script src="backbone.mutators.js"></script>
55
+ //
56
+ // Node:
57
+ // var _ = require('underscore');
58
+ // var Backbone = require('backbone');
59
+ // var Mutators = require('backbone.mutators');
60
+ //
61
+ //
62
+ // AMD:
63
+ // define(['underscore', 'backbone', 'backbone.mutators'], function (_, Backbone, Mutators) {
64
+ // // insert sample from below
65
+ // return User;
66
+ // });
67
+ //
68
+ // var User = Backbone.Model.extend({
69
+ // mutators: {
70
+ // fullname: function () {
71
+ // return this.firstname + ' ' + this.lastname;
72
+ // }
73
+ // },
74
+ //
75
+ // defaults: {
76
+ // firstname: 'Sebastian',
77
+ // lastname: 'Golasch'
78
+ // }
79
+ // });
80
+ //
81
+ // var user = new User();
82
+ // user.get('fullname') // returns 'Sebastian Golasch'
83
+ // user.toJSON() // return '{firstname: 'Sebastian', lastname: 'Golasch', fullname: 'Sebastian Golasch'}'
84
+
85
+ }(this, function (_, Backbone, root, undef) {
86
+ 'use strict';
87
+
88
+ // check if we use the amd branch of backbone and underscore
89
+ Backbone = Backbone === undef ? root.Backbone : Backbone;
90
+ _ = _ === undef ? root._ : _;
91
+
92
+ // extend backbones model prototype with the mutator functionality
93
+ var Mutator = function () {},
94
+ oldGet = Backbone.Model.prototype.get,
95
+ oldSet = Backbone.Model.prototype.set,
96
+ oldToJson = Backbone.Model.prototype.toJSON;
97
+
98
+ // This is necessary to ensure that Models declared without the mutators object do not throw and error
99
+ Mutator.prototype.mutators = {};
100
+
101
+ // override get functionality to fetch the mutator props
102
+ Mutator.prototype.get = function (attr) {
103
+ var isMutator = this.mutators !== undef;
104
+
105
+ // check if we have a getter mutation
106
+ if (isMutator === true && _.isFunction(this.mutators[attr]) === true) {
107
+ return this.mutators[attr].call(this);
108
+ }
109
+
110
+ // check if we have a deeper nested getter mutation
111
+ if (isMutator === true && _.isObject(this.mutators[attr]) === true && _.isFunction(this.mutators[attr].get) === true) {
112
+ return this.mutators[attr].get.call(this);
113
+ }
114
+
115
+ return oldGet.call(this, attr);
116
+ };
117
+
118
+ // override set functionality to set the mutator props
119
+ Mutator.prototype.set = function (key, value, options) {
120
+ var isMutator = this.mutators !== undef,
121
+ ret = null,
122
+ attrs = null;
123
+
124
+ ret = oldSet.call(this, key, value, options);
125
+
126
+ // seamleassly stolen from backbone core
127
+ // check if the setter action is triggered
128
+ // using key <-> value or object
129
+ if (_.isObject(key) || key === null) {
130
+ attrs = key;
131
+ options = value;
132
+ } else {
133
+ attrs = {};
134
+ attrs[key] = value;
135
+ }
136
+
137
+ // check if we have a deeper nested setter mutation
138
+ if (isMutator === true && _.isObject(this.mutators[key]) === true) {
139
+
140
+ // check if we need to set a single value
141
+ if (_.isFunction(this.mutators[key].set) === true) {
142
+ ret = this.mutators[key].set.call(this, key, attrs[key], options, _.bind(oldSet, this));
143
+ } else if(_.isFunction(this.mutators[key])){
144
+ ret = this.mutators[key].call(this, key, attrs[key], options, _.bind(oldSet, this));
145
+ }
146
+ }
147
+
148
+ if (isMutator === true && _.isObject(attrs)) {
149
+ _.each(attrs, _.bind(function (attr, attrKey) {
150
+ if (_.isObject(this.mutators[attrKey]) === true) {
151
+ // check if we need to set a single value
152
+
153
+ var meth = this.mutators[attrKey];
154
+ if(_.isFunction(meth.set)){
155
+ meth = meth.set;
156
+ }
157
+
158
+ if(_.isFunction(meth)){
159
+ if (options === undef || (_.isObject(options) === true && options.silent !== true && (options.mutators !== undef && options.mutators.silent !== true))) {
160
+ this.trigger('mutators:set:' + attrKey);
161
+ }
162
+ meth.call(this, attrKey, attr, options, _.bind(oldSet, this));
163
+ }
164
+
165
+ }
166
+ }, this));
167
+ }
168
+
169
+ return ret;
170
+ };
171
+
172
+ // override toJSON functionality to serialize mutator properties
173
+ Mutator.prototype.toJSON = function (options) {
174
+ // fetch ye olde values
175
+ var attr = oldToJson.call(this),
176
+ isSaving,
177
+ isTransient;
178
+ // iterate over all mutators (if there are some)
179
+ _.each(this.mutators, _.bind(function (mutator, name) {
180
+ // check if we have some getter mutations
181
+ if (_.isObject(this.mutators[name]) === true && _.isFunction(this.mutators[name].get)) {
182
+ isSaving = _.has(options || {}, 'emulateHTTP');
183
+ isTransient = this.mutators[name].transient;
184
+ if (!isSaving || !isTransient) {
185
+ attr[name] = _.bind(this.mutators[name].get, this)();
186
+ }
187
+ } else if (_.isFunction(this.mutators[name])) {
188
+ attr[name] = _.bind(this.mutators[name], this)();
189
+ }
190
+ }, this));
191
+
192
+ return attr;
193
+ };
194
+
195
+ // override get functionality to get HTML-escaped the mutator props
196
+ Mutator.prototype.escape = function (attr){
197
+ var val = this.get(attr);
198
+ return _.escape(val == null ? '' : '' + val);
199
+ };
200
+
201
+ // extend the models prototype
202
+ _.extend(Backbone.Model.prototype, Mutator.prototype);
203
+
204
+ // make mutators globally available under the Backbone namespace
205
+ Backbone.Mutators = Mutator;
206
+ return Mutator;
207
+ }));
@@ -0,0 +1,351 @@
1
+ (function(global, factory) {
2
+
3
+ // Set up lib appropriately for the environment. Start with AMD.
4
+ if (typeof define === 'function' && define.amd) {
5
+ define(['underscore', 'backbone'], factory);
6
+
7
+ // Next for Node.js or CommonJS.
8
+ } else if (typeof module !== 'undefined' && module.exports) {
9
+ module.exports = factory(require('underscore'), require('backbone'));
10
+
11
+ // Finally, use browser globals.
12
+ } else {
13
+ factory(global._, global.Backbone);
14
+ }
15
+
16
+ }(this, function(_, Backbone) {
17
+ 'use strict';
18
+
19
+ var vc, iterators, proxy;
20
+
21
+ iterators = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
22
+ 'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
23
+ 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
24
+ 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
25
+ 'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
26
+ 'isEmpty', 'chain'];
27
+
28
+ proxy = ['add', 'remove'];
29
+
30
+ /**
31
+ * Constructor for the virtual collection
32
+ * @param {Collection} collection
33
+ * @param {Function|Object} filter function, or hash of properties to match
34
+ * @param {Object} options
35
+ * @param {[Function|Object]} filter function, or hash of properties to match
36
+ * @param {[Function|String]} comparator
37
+ */
38
+ function VirtualCollection(collection, options) {
39
+ this.collection = collection;
40
+ options = options || {};
41
+ this.comparator = options.comparator;
42
+
43
+ _.bindAll(this, 'each', 'map', 'get', 'at', 'indexOf', 'sort', 'closeWith',
44
+ '_rebuildIndex', '_models', '_onAdd', '_onRemove', '_onChange', '_onReset',
45
+ '_indexAdd', '_indexRemove');
46
+
47
+ // set filter
48
+ this.filterFunction = VirtualCollection.buildFilter(options.filter);
49
+
50
+ // build index
51
+ this._rebuildIndex();
52
+
53
+ this.listenTo(this.collection, 'add', this._onAdd, this);
54
+ this.listenTo(this.collection, 'remove', this._onRemove, this);
55
+ this.listenTo(this.collection, 'change', this._onChange, this);
56
+ this.listenTo(this.collection, 'reset', this._onReset, this);
57
+
58
+ if (options.close_with) {
59
+ this.closeWith(options.close_with);
60
+ }
61
+ }
62
+
63
+ /**
64
+ * [static] Returns a function that returns true for models that meet the specified conditions
65
+ * @param {Object} hash of model attributes or {Function} filter
66
+ * @return {Function} filtering function
67
+ */
68
+ VirtualCollection.buildFilter = function (filter) {
69
+ if (!filter) {
70
+ // If no filter is passed, all models should be added
71
+ return function () { return true; };
72
+ } else if (_.isFunction(filter)) {
73
+ // If filter is passed a function, just return it
74
+ return filter;
75
+ } else if (filter.constructor === Object) {
76
+ // If filter is a hash of attributes, return a function that checks each of them
77
+ return function (model) {
78
+ return !Boolean(_(Object.keys(filter)).detect(function (key) {
79
+ return model.get(key) !== filter[key];
80
+ }));
81
+ };
82
+ }
83
+ };
84
+
85
+ vc = VirtualCollection.prototype;
86
+
87
+
88
+ // mix in Underscore method as proxies
89
+ _.each(iterators, function (method) {
90
+ vc[method] = function () {
91
+ var args = Array.prototype.slice.call(arguments);
92
+ args.unshift(this._models());
93
+ return _[method].apply(_, args);
94
+ };
95
+ });
96
+
97
+ // proxy functions to parent
98
+ _.each(proxy, function (method) {
99
+ vc[method] = function () {
100
+ var args = Array.prototype.slice.call(arguments);
101
+ return this.collection[method].apply(this.collection, args);
102
+ };
103
+ });
104
+
105
+ /**
106
+ * Returns a model if it belongs to the virtual collection
107
+ * @param {String} id
108
+ * @return {Model}
109
+ */
110
+ vc.get = function (id) {
111
+ var model = this.collection.get(id);
112
+ if (model && this.filterFunction(model)) {
113
+ return model;
114
+ }
115
+ };
116
+
117
+ /**
118
+ * Returns the model at the position in the index
119
+ * @param {Number} index
120
+ * @return {Model}
121
+ */
122
+ vc.at = function (index) {
123
+ return this.collection.get(this.index[index]);
124
+ };
125
+
126
+ vc.where = Backbone.Collection.prototype.where;
127
+ vc.findWhere = Backbone.Collection.prototype.findWhere;
128
+
129
+ /**
130
+ * Returns the index of the model in the virtual collection
131
+ * @param {Model} model
132
+ * @return {Number} index
133
+ */
134
+ vc.indexOf = function (model) {
135
+ return this.index.indexOf(model.cid);
136
+ };
137
+
138
+ /**
139
+ * Returns a JSON representation of all the models in the index
140
+ * @return {Array} JSON models
141
+ */
142
+ vc.toJSON = function() {
143
+ return _.map(this._models(), function(model) {
144
+ return model.toJSON();
145
+ });
146
+ };
147
+
148
+ /**
149
+ * Sorts the models in the virtual collection
150
+ *
151
+ * You only need to trigger this manually if you change the comparator
152
+ * @param {Object} options
153
+ * @return {VirtualCollection}
154
+ */
155
+ vc.sort = function (options) {
156
+ var self = this;
157
+ if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
158
+ options = options || {};
159
+
160
+ // Run sort based on type of `comparator`.
161
+ if (_.isString(this.comparator)) {
162
+ this.index = _.sortBy(this.index, function (cid) {
163
+ var model = this.collection.get(cid);
164
+ return model.get(this.comparator);
165
+ }, this);
166
+ } else if (this.comparator.length === 1) {
167
+ this.index = _.sortBy(this.index, function (cid) {
168
+ var model = this.collection.get(cid);
169
+ return this.comparator.call(self, model);
170
+ }, this);
171
+ } else {
172
+ this.index.sort(function (cid1, cid2) {
173
+ var model1 = self.collection.get(cid1),
174
+ model2 = self.collection.get(cid2);
175
+
176
+ return self.comparator.call(self, model1, model2);
177
+ });
178
+ }
179
+
180
+ if (!options.silent) this.trigger('sort', this, options);
181
+ return this;
182
+ };
183
+
184
+ /**
185
+ * Change the filter and update collection
186
+ *
187
+ * @param {Object} hash of model attributes or {Function} filter
188
+ * @return {VirtualCollection}
189
+ */
190
+
191
+ vc.updateFilter = function(filter){
192
+ // Reset the filter
193
+ this.filterFunction = VirtualCollection.buildFilter(filter);
194
+
195
+ // Update the models
196
+ this._rebuildIndex();
197
+
198
+ // Trigger filter event
199
+ this.trigger('filter', this, filter);
200
+
201
+ // Trigger reset event
202
+ this.trigger('reset', this, filter);
203
+
204
+ return this;
205
+ };
206
+
207
+ /**
208
+ * A utility function for unbiding listeners
209
+ * @param {View} view (marionette view)
210
+ */
211
+ vc.closeWith = function (view) {
212
+ view.on('close', function () {
213
+ this.stopListening();
214
+ }, this);
215
+ };
216
+
217
+ // private
218
+
219
+ vc._rebuildIndex = function () {
220
+ this.index = [];
221
+ this.collection.each(function (model, index) {
222
+ if (this.filterFunction(model, index)) {
223
+ this.index.push(model.cid);
224
+ }
225
+ }, this);
226
+ if (this.comparator) {
227
+ this.sort({silent: true});
228
+ }
229
+ this.length = this.index.length;
230
+ };
231
+
232
+ /**
233
+ * Returns an array of models in the virtual collection
234
+ * @return {Array}
235
+ */
236
+ vc._models = function () {
237
+ return _.map(this.index, function (cid) {
238
+ return this.collection.get(cid);
239
+ }, this);
240
+ };
241
+
242
+ /**
243
+ * Handles the collection:add event
244
+ * May update the virtual collection's index
245
+ * @param {Model} model
246
+ * @return {undefined}
247
+ */
248
+ vc._onAdd = function (model, collection, options) {
249
+ if (this.filterFunction(model)) {
250
+ this._indexAdd(model);
251
+ this.trigger('add', model, this, options);
252
+ }
253
+ };
254
+
255
+ /**
256
+ * Handles the collection:remove event
257
+ * May update the virtual collection's index
258
+ * @param {Model} model
259
+ * @return {undefined}
260
+ */
261
+ vc._onRemove = function (model, collection, options) {
262
+ if (_(this.index).contains(model.cid)) {
263
+ var i = this._indexRemove(model);
264
+ if (options) {
265
+ var options_clone = _.clone(options);
266
+ options_clone.index = i;
267
+ }
268
+
269
+ this.trigger('remove', model, this, options_clone);
270
+ }
271
+ };
272
+
273
+ /**
274
+ * Handles the collection:change event
275
+ * May update the virtual collection's index
276
+ * @param {Model} model
277
+ * @param {Object} object
278
+ */
279
+ vc._onChange = function (model, options) {
280
+ var already_here = _.contains(this.index, model.cid);
281
+ if (this.filterFunction(model)) {
282
+ if (already_here) {
283
+ this.trigger('change', model, this, options);
284
+ } else {
285
+ this._indexAdd(model);
286
+ this.trigger('add', model, this, options);
287
+ }
288
+ } else {
289
+ if (already_here) {
290
+ this._indexRemove(model);
291
+ this.trigger('remove', model, this, options);
292
+ }
293
+ }
294
+ };
295
+
296
+ /**
297
+ * Handles the collection:reset event
298
+ * @param {Collection} collection
299
+ * @param {Object} object
300
+ */
301
+ vc._onReset = function (collection, options) {
302
+ this._rebuildIndex();
303
+ this.trigger('reset', this, options);
304
+ };
305
+
306
+ /**
307
+ * Adds a model to the virtual collection index
308
+ * Inserting it in the correct order
309
+ * @param {Model} model
310
+ * @return {undefined}
311
+ */
312
+ vc._indexAdd = function (model) {
313
+ if (this.index.indexOf(model.cid) === -1) {
314
+
315
+ if (!this.comparator) { // order inherit's from parent collection
316
+ var i, orig_index = this.collection.indexOf(model);
317
+ for (i = 0; i < this.length; i++) {
318
+ if (this.collection.indexOf(this.collection.get(this.index[i])) > orig_index) {
319
+ break;
320
+ }
321
+ }
322
+ this.index.splice(i, 0, model.cid);
323
+
324
+ } else { // the virtual collection has a custom order
325
+ this.index.push(model.cid);
326
+ this.sort({silent: true});
327
+ }
328
+ this.length = this.index.length;
329
+ }
330
+ };
331
+
332
+ /**
333
+ * Removes a model from the virtual collection index
334
+ * @param {Model} model
335
+ * @return {int} the index for the removed model or -1 if not found
336
+ */
337
+ vc._indexRemove = function (model) {
338
+ var i = this.index.indexOf(model.cid);
339
+ if (i !== -1) {
340
+ this.index.splice(i, 1);
341
+ this.length = this.index.length;
342
+ }
343
+ return i;
344
+ };
345
+
346
+ _.extend(vc, Backbone.Events);
347
+
348
+ Backbone.VirtualCollection = VirtualCollection;
349
+
350
+ return VirtualCollection;
351
+ }));
@@ -1 +1 @@
1
- //= require js_stack/plugins/backbone/mutators/0.4.1
1
+ //= require js_stack/plugins/backbone/mutators/0.4.2
@@ -1 +1 @@
1
- //= require js_stack/plugins/backbone/virtualcollection/0.4.11
1
+ //= require js_stack/plugins/backbone/virtualcollection/0.4.12
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Pewiński
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-23 00:00:00.000000000 Z
12
+ date: 2014-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml_coffee_assets
@@ -115,6 +115,7 @@ files:
115
115
  - vendor/assets/javascripts/js_stack/base/marionette/1.6.2.js
116
116
  - vendor/assets/javascripts/js_stack/base/marionette/1.6.4.js
117
117
  - vendor/assets/javascripts/js_stack/base/marionette/1.7.0.js
118
+ - vendor/assets/javascripts/js_stack/base/marionette/1.7.3.js
118
119
  - vendor/assets/javascripts/js_stack/base/underscore.js
119
120
  - vendor/assets/javascripts/js_stack/base/underscore/1.5.2.js
120
121
  - vendor/assets/javascripts/js_stack/base/underscore/1.6.0.js
@@ -133,6 +134,7 @@ files:
133
134
  - vendor/assets/javascripts/js_stack/plugins/backbone/associations/0.6.1.js
134
135
  - vendor/assets/javascripts/js_stack/plugins/backbone/deepmodel/0.10.4.js
135
136
  - vendor/assets/javascripts/js_stack/plugins/backbone/mutators/0.4.1.js
137
+ - vendor/assets/javascripts/js_stack/plugins/backbone/mutators/0.4.2.js
136
138
  - vendor/assets/javascripts/js_stack/plugins/backbone/pageable/1.3.2.js
137
139
  - vendor/assets/javascripts/js_stack/plugins/backbone/pageable/1.4.5.js
138
140
  - vendor/assets/javascripts/js_stack/plugins/backbone/routefilter/0.2.0.js
@@ -141,6 +143,7 @@ files:
141
143
  - vendor/assets/javascripts/js_stack/plugins/backbone/validation/0.8.1.js
142
144
  - vendor/assets/javascripts/js_stack/plugins/backbone/validation/0.9.1.js
143
145
  - vendor/assets/javascripts/js_stack/plugins/backbone/virtualcollection/0.4.11.js
146
+ - vendor/assets/javascripts/js_stack/plugins/backbone/virtualcollection/0.4.12.js
144
147
  - vendor/assets/javascripts/js_stack/plugins/backbone/virtualcollection/0.4.5.js
145
148
  - vendor/assets/javascripts/js_stack/plugins/backbone/virtualcollection/0.4.8.js
146
149
  - vendor/assets/javascripts/js_stack/plugins/cocktail.js