Update to spinejs 1.1.0 to support jquery 1.9.

This commit is contained in:
Martin Edenhofer 2013-05-10 15:03:26 +02:00
parent 96c479b40b
commit dba39774f7
16 changed files with 599 additions and 224 deletions

View file

@ -324,7 +324,7 @@ class App.ControllerForm extends App.Controller
item = $( App.view('generic/textarea')( attribute: attribute ) )
if attribute.upload
fileUploaderId = 'file-uploader-' + new Date().getTime() + '-' + Math.floor( Math.random() * 99999 )
item = $( item.html() + '<div class="file-uploader ' + attribute.class + '" id="' + fileUploaderId + '"></div>' )
item = $( App.view('generic/textarea')( attribute: attribute ) + '<div class="file-uploader ' + attribute.class + '" id="' + fileUploaderId + '"></div>' )
# add file uploader
u = =>

View file

@ -1,10 +1,3 @@
Note = App.Note
$.fn.item = ->
elementID = $(@).data('id')
elementID or= $(@).parents('[data-id]').data('id')
Note.find(elementID)
class Index extends App.ControllerContent
events:
'click [data-type=network-new]': 'network_new'

View file

@ -1,10 +1,10 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var $, Ajax, Base, Collection, Extend, Include, Model, Queue, Singleton, Spine,
__slice = [].slice,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Spine = this.Spine || require('spine');
@ -16,15 +16,47 @@
Ajax = {
getURL: function(object) {
return object && (typeof object.url === "function" ? object.url() : void 0) || object.url;
return (typeof object.url === "function" ? object.url() : void 0) || object.url;
},
getScope: function(object) {
return (typeof object.scope === "function" ? object.scope() : void 0) || object.scope;
},
generateURL: function() {
var args, collection, object, path, scope;
object = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (object.className) {
collection = object.className.toLowerCase() + 's';
scope = Ajax.getScope(object);
} else {
if (typeof object.constructor.url === 'string') {
collection = object.constructor.url;
} else {
collection = object.constructor.className.toLowerCase() + 's';
}
scope = Ajax.getScope(object) || Ajax.getScope(object.constructor);
}
args.unshift(collection);
args.unshift(scope);
path = args.join('/');
path = path.replace(/(\/\/)/g, "/");
path = path.replace(/^\/|\/$/g, "");
if (path.indexOf("../") !== 0) {
return Model.host + "/" + path;
} else {
return path;
}
},
enabled: true,
disable: function(callback) {
var e;
if (this.enabled) {
this.enabled = false;
try {
return callback();
} catch (e) {
} catch (_error) {
e = _error;
throw e;
} finally {
this.enabled = true;
@ -46,11 +78,9 @@
};
Base = (function() {
function Base() {}
Base.prototype.defaults = {
contentType: 'application/json',
dataType: 'json',
processData: false,
headers: {
@ -66,6 +96,7 @@
Base.prototype.ajaxQueue = function(params, defaults) {
var deferred, jqXHR, promise, request, settings;
jqXHR = null;
deferred = $.Deferred();
promise = deferred.promise();
@ -78,6 +109,7 @@
};
promise.abort = function(statusText) {
var index;
if (jqXHR) {
return jqXHR.abort(statusText);
}
@ -101,19 +133,17 @@
})();
Collection = (function(_super) {
__extends(Collection, _super);
function Collection(model) {
this.model = model;
this.failResponse = __bind(this.failResponse, this);
this.recordsResponse = __bind(this.recordsResponse, this);
}
Collection.prototype.find = function(id, params) {
var record;
record = new this.model({
id: id
});
@ -133,6 +163,7 @@
Collection.prototype.fetch = function(params, options) {
var id,
_this = this;
if (params == null) {
params = {};
}
@ -164,15 +195,12 @@
})(Base);
Singleton = (function(_super) {
__extends(Singleton, _super);
function Singleton(record) {
this.record = record;
this.failResponse = __bind(this.failResponse, this);
this.recordResponse = __bind(this.recordResponse, this);
this.model = this.record.constructor;
}
@ -186,6 +214,7 @@
Singleton.prototype.create = function(params, options) {
return this.ajaxQueue(params, {
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(this.record),
url: Ajax.getURL(this.model)
}).done(this.recordResponse(options)).fail(this.failResponse(options));
@ -194,6 +223,7 @@
Singleton.prototype.update = function(params, options) {
return this.ajaxQueue(params, {
type: 'PUT',
contentType: 'application/json',
data: JSON.stringify(this.record),
url: Ajax.getURL(this.record)
}).done(this.recordResponse(options)).fail(this.failResponse(options));
@ -208,11 +238,13 @@
Singleton.prototype.recordResponse = function(options) {
var _this = this;
if (options == null) {
options = {};
}
return function(data, status, xhr) {
var _ref, _ref1;
if (Spine.isBlank(data) || _this.record.destroyed) {
data = false;
} else {
@ -236,11 +268,13 @@
Singleton.prototype.failResponse = function(options) {
var _this = this;
if (options == null) {
options = {};
}
return function(xhr, statusText, error) {
var _ref, _ref1;
_this.record.trigger('ajaxError', xhr, statusText, error);
if ((_ref = options.error) != null) {
_ref.apply(_this.record);
@ -260,15 +294,11 @@
return new Singleton(this);
},
url: function() {
var args, url;
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
url = Ajax.getURL(this.constructor);
if (url.charAt(url.length - 1) !== '/') {
url += '/';
}
url += encodeURIComponent(this.id);
args.unshift(url);
return args.join('/');
args.unshift(encodeURIComponent(this.id));
return Ajax.generateURL.apply(Ajax, [this].concat(__slice.call(args)));
}
};
@ -278,10 +308,9 @@
},
url: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
args.unshift(this.className.toLowerCase() + 's');
args.unshift(Model.host);
return args.join('/');
return Ajax.generateURL.apply(Ajax, [this].concat(__slice.call(args)));
}
};
@ -294,6 +323,7 @@
},
ajaxFetch: function() {
var _ref;
return (_ref = this.ajax()).fetch.apply(_ref, arguments);
},
ajaxChange: function(record, type, options) {
@ -323,3 +353,7 @@
}
}).call(this);
/*
//@ sourceMappingURL=ajax.map
*/

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var $, Spine,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
@ -10,7 +10,6 @@
$ = Spine.$;
Spine.List = (function(_super) {
__extends(List, _super);
List.prototype.events = {
@ -20,8 +19,7 @@
List.prototype.selectFirst = false;
function List() {
this.change = __bind(this.change, this);
List.__super__.constructor.apply(this, arguments);
this.change = __bind(this.change, this); List.__super__.constructor.apply(this, arguments);
this.bind('change', this.change);
}
@ -58,6 +56,7 @@
List.prototype.click = function(e) {
var item;
item = this.items[$(e.currentTarget).index()];
this.trigger('change', item);
return true;
@ -72,3 +71,7 @@
}
}).call(this);
/*
//@ sourceMappingURL=list.map
*/

View file

@ -0,0 +1,10 @@
{
"version": 3,
"file": "list.js",
"sourceRoot": "..",
"sources": [
"src/list.coffee"
],
"names": [],
"mappings": ";AAAA;CAAA,KAAA,EAAA;KAAA;;oSAAA;;CAAA,CAAA,CAAS,CAAC,CAAV,EAAmB;;CAAnB,CACA,CAAS,EAAK;;CADd,CAGM,GAAK;CACT;;CAAA,EACE,GADF;CACE,CAAe,IAAf,CAAA,MAAA;CADF,KAAA;;CAAA,EAGa,EAHb,MAGA;;CAEa,EAAA,CAAA,UAAA;CACX,KAAA,GAAA,8BAAA;CAAA,CACgB,EAAf,EAAD,EAAA;CAPF,IAKa;;CALb,EASU,KAAV,CAAU;CACR,WAAM,OAAN;CAVF,IASU;;CATV,EAYQ,CAAA,EAAR,GAAS;CACP,EAAW,CAAV,EAAD,CAAA;AAEO,CAAP,GAAA,EAAA,CAAA;CACE,GAAC,IAAD,GAAA;CACA,aAAA;QAJF;CAAA,GAMC,EAAD,EAAA,GAAA;CACA,EAAE,CAAC,CAAqB,EAAN,CAAhB,KAAF;CApBF,IAYQ;;CAZR,EAsBQ,EAAA,CAAR,GAAS;CACP,GAAkB,CAAlB,CAAA;CAAA,EAAS,CAAR,CAAD,GAAA;QAAA;CAAA,GACC,CAAK,CAAN,EAAM;CADN,GAEC,EAAD,CAAA;CACA,GAAG,EAAH,KAAA;AACS,CAAP,GAAA,EAAA,EAAA,CAAO;CACJ,GAAA,CAAD,GAAA,SAAA;UAFJ;QAJM;CAtBR,IAsBQ;;CAtBR,EA8BU,KAAV,CAAW;CACR,CAAE,CAAH,CAAC,IAAD,KAAA;CA/BF,IA8BU;;CA9BV,EAiCO,EAAP,IAAQ;CACN,GAAA,MAAA;;CAAA,EAAO,CAAP,CAAc,CAAd,OAAc;CAAd,CACmB,EAAlB,EAAD,CAAA,CAAA;CAFK,YAGL;CApCF,IAiCO;;CAjCP;;CADuB,IAAK;;;CAuCtB,EAAU,CAAlB,CAAuB,CAAjB,CAAN;IA1CA;CAAA"
}

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var Spine;
@ -11,11 +11,13 @@
},
saveLocal: function() {
var result;
result = JSON.stringify(this);
return localStorage[this.className] = result;
},
loadLocal: function() {
var result;
result = localStorage[this.className];
return this.refresh(result || [], {
clear: true
@ -28,3 +30,7 @@
}
}).call(this);
/*
//@ sourceMappingURL=local.map
*/

View file

@ -0,0 +1,10 @@
{
"version": 3,
"file": "local.js",
"sourceRoot": "..",
"sources": [
"src/local.coffee"
],
"names": [],
"mappings": ";AAAA;CAAA,IAAA,CAAA;;CAAA,CAAA,CAAQ,CAAC,CAAT,EAAkB;;CAAlB,CAEA,CACE,EADG;CACH,CAAU,CAAA,CAAV,IAAA,CAAU;CACR,GAAC,EAAD,GAAA;CACC,GAAA,CAAD,IAAA,IAAA;CAFF,IAAU;CAAV,CAIW,CAAA,CAAX,KAAA;CACE,KAAA,IAAA;;CAAA,EAAS,CAAI,EAAb,GAAS;CACI,EAAc,CAAb,KAAD,GAAA,CAAb;CANF,IAIW;CAJX,CAQW,CAAA,CAAX,KAAA;CACE,KAAA,IAAA;;CAAA,EAAS,CAAc,EAAvB,GAAsB,GAAA;CACrB,CAAD,EAAC,EAAQ,CAAT,MAAA;CAAuB,CAAO,EAAP,CAAA,GAAA;CAFd,OAET;CAVF,IAQW;CAXb,GAAA;;;CAeQ,EAAU,CAAlB,CAAuB,CAAjB,CAAN;IAfA;CAAA"
}

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var $, Spine,
__hasProp = {}.hasOwnProperty,
@ -10,7 +10,6 @@
$ = Spine.$;
Spine.Manager = (function(_super) {
__extends(Manager, _super);
Manager.include(Spine.Events);
@ -23,6 +22,7 @@
Manager.prototype.add = function() {
var cont, controllers, _i, _len, _results;
controllers = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_results = [];
for (_i = 0, _len = controllers.length; _i < _len; _i++) {
@ -34,8 +34,10 @@
Manager.prototype.addOne = function(controller) {
var _this = this;
controller.bind('active', function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return _this.trigger.apply(_this, ['change', controller].concat(__slice.call(args)));
});
@ -51,6 +53,7 @@
Manager.prototype.change = function() {
var args, cont, current, _i, _len, _ref, _results;
current = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_ref = this.controllers;
_results = [];
@ -72,6 +75,7 @@
Spine.Controller.include({
active: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (typeof args[0] === 'function') {
this.bind('active', args[0]);
@ -95,7 +99,6 @@
});
Spine.Stack = (function(_super) {
__extends(Stack, _super);
Stack.prototype.controllers = {};
@ -107,6 +110,7 @@
function Stack() {
var key, value, _fn, _ref, _ref1,
_this = this;
Stack.__super__.constructor.apply(this, arguments);
this.manager = new Spine.Manager;
_ref = this.controllers;
@ -123,11 +127,13 @@
_ref1 = this.routes;
_fn = function(key, value) {
var callback;
if (typeof value === 'function') {
callback = value;
}
callback || (callback = function() {
var _ref2;
return (_ref2 = _this[value]).active.apply(_ref2, arguments);
});
return _this.route(key, callback);
@ -159,3 +165,7 @@
}
}).call(this);
/*
//@ sourceMappingURL=manager.map
*/

View file

@ -0,0 +1,10 @@
{
"version": 3,
"file": "manager.js",
"sourceRoot": "..",
"sources": [
"src/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;CAeA,GAAwB,EAAxB,GAAyB;CAAzB,GAAE,EAAF,EAAA,CAAG;QAhBQ;CALb,IAKa;;CALb,EAuBA,MAAM,CAAD;CACH,EAAA,CAAC,EAAD,CAAQ,GAAR;CACC,GAAA,EAAD,IAAA,GAAA;CAzBF,IAuBK;;CAvBL;;CADwB,IAAK;;;CA4BvB,EAAU,CAAlB,CAAuB,CAAjB,CAAN;IAlFA;;;CAmFQ,EAAgB,CAAxB,CAAA,CAAM,CAAS;IAnFf;CAAA"
}

View file

@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var Collection, Instance, Singleton, Spine, isArray, require, singularize, underscore,
var Collection, Instance, Singleton, Spine, association, isArray, require, singularize, underscore,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -13,11 +13,11 @@
});
Collection = (function(_super) {
__extends(Collection, _super);
function Collection(options) {
var key, value;
if (options == null) {
options = {};
}
@ -29,6 +29,7 @@
Collection.prototype.all = function() {
var _this = this;
return this.model.select(function(rec) {
return _this.associated(rec);
});
@ -40,13 +41,19 @@
Collection.prototype.last = function() {
var values;
values = this.all();
return values[values.length - 1];
};
Collection.prototype.count = function() {
return this.all().length;
};
Collection.prototype.find = function(id) {
var records,
_this = this;
records = this.select(function(rec) {
return ("" + rec.id) === ("" + id);
});
@ -58,6 +65,7 @@
Collection.prototype.findAllByAttribute = function(name, value) {
var _this = this;
return this.model.select(function(rec) {
return _this.associated(rec) && rec[name] === value;
});
@ -69,34 +77,55 @@
Collection.prototype.select = function(cb) {
var _this = this;
return this.model.select(function(rec) {
return _this.associated(rec) && cb(rec);
});
};
Collection.prototype.refresh = function(values) {
var record, records, _i, _j, _len, _len1, _ref;
var i, match, record, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
if (values == null) {
return this;
}
_ref = this.all();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
record = _ref[_i];
delete this.model.records[record.id];
delete this.model.irecords[record.id];
_ref1 = this.model.records;
for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) {
match = _ref1[i];
if (!(match.id === record.id)) {
continue;
}
this.model.records.splice(i, 1);
break;
}
}
records = this.model.fromJSON(values);
if (!isArray(records)) {
records = [records];
if (!isArray(values)) {
values = [values];
}
for (_j = 0, _len1 = records.length; _j < _len1; _j++) {
record = records[_j];
for (_k = 0, _len2 = values.length; _k < _len2; _k++) {
record = values[_k];
record.newRecord = false;
record[this.fkey] = this.record.id;
this.model.records[record.id] = record;
}
return this.model.trigger('refresh', this.model.cloneArray(records));
this.model.refresh(values);
return this;
};
Collection.prototype.create = function(record) {
Collection.prototype.create = function(record, options) {
record[this.fkey] = this.record.id;
return this.model.create(record);
return this.model.create(record, options);
};
Collection.prototype.add = function(record, options) {
return record.updateAttribute(this.fkey, this.record.id, options);
};
Collection.prototype.remove = function(record, options) {
return record.updateAttribute(this.fkey, null, options);
};
Collection.prototype.associated = function(record) {
@ -108,11 +137,11 @@
})(Spine.Module);
Instance = (function(_super) {
__extends(Instance, _super);
function Instance(options) {
var key, value;
if (options == null) {
options = {};
}
@ -123,17 +152,25 @@
}
Instance.prototype.exists = function() {
return this.record[this.fkey] && this.model.exists(this.record[this.fkey]);
if (this.record[this.fkey]) {
return this.model.exists(this.record[this.fkey]);
} else {
return false;
}
};
Instance.prototype.update = function(value) {
if (value == null) {
return this;
}
if (!(value instanceof this.model)) {
value = new this.model(value);
}
if (value.isNew()) {
value.save();
}
return this.record[this.fkey] = value && value.id;
this.record[this.fkey] = value && value.id;
return this;
};
return Instance;
@ -141,11 +178,11 @@
})(Spine.Module);
Singleton = (function(_super) {
__extends(Singleton, _super);
function Singleton(options) {
var key, value;
if (options == null) {
options = {};
}
@ -160,11 +197,15 @@
};
Singleton.prototype.update = function(value) {
if (value == null) {
return this;
}
if (!(value instanceof this.model)) {
value = this.model.fromJSON(value);
}
value[this.fkey] = this.record.id;
return value.save();
value.save();
return this;
};
return Singleton;
@ -179,75 +220,42 @@
return str.replace(/::/g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase();
};
association = function(name, model, record, fkey, Ctor) {
if (typeof model === 'string') {
model = require(model);
}
return new Ctor({
name: name,
model: model,
record: record,
fkey: fkey
});
};
Spine.Model.extend({
hasMany: function(name, model, fkey) {
var association;
if (fkey == null) {
fkey = "" + (underscore(this.className)) + "_id";
}
association = function(record) {
if (typeof model === 'string') {
model = require(model);
}
return new Collection({
name: name,
model: model,
record: record,
fkey: fkey
});
};
return this.prototype[name] = function(value) {
if (value != null) {
association(this).refresh(value);
}
return association(this);
return association(name, model, this, fkey, Collection).refresh(value);
};
},
belongsTo: function(name, model, fkey) {
var association;
if (fkey == null) {
fkey = "" + (singularize(name)) + "_id";
fkey = "" + (underscore(singularize(name))) + "_id";
}
association = function(record) {
if (typeof model === 'string') {
model = require(model);
}
return new Instance({
name: name,
model: model,
record: record,
fkey: fkey
});
};
this.prototype[name] = function(value) {
if (value != null) {
association(this).update(value);
}
return association(this).exists();
return association(name, model, this, fkey, Instance).update(value).exists();
};
return this.attributes.push(fkey);
},
hasOne: function(name, model, fkey) {
var association;
if (fkey == null) {
fkey = "" + (underscore(this.className)) + "_id";
}
association = function(record) {
if (typeof model === 'string') {
model = require(model);
}
return new Singleton({
name: name,
model: model,
record: record,
fkey: fkey
});
};
return this.prototype[name] = function(value) {
if (value != null) {
association(this).update(value);
}
return association(this).find();
return association(name, model, this, fkey, Singleton).update(value).find();
};
}
});
@ -259,3 +267,7 @@
Spine.Instance = Instance;
}).call(this);
/*
//@ sourceMappingURL=relation.map
*/

View file

@ -0,0 +1,10 @@
{
"version": 3,
"file": "relation.js",
"sourceRoot": "..",
"sources": [
"src/relation.coffee"
],
"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Ga;;CAxGb,CA+GA,CAAc,CAAA,CAAA,CAAA,GAAC,EAAf;AAC4B,CAA1B,GAAA,CAA0B,CAAA,EAA1B;CAAA,EAAQ,EAAR,CAAA,CAAQ;MAAR;CACS,GAAL,OAAA;CAAK,CAAM,EAAN,EAAA;CAAA,CAAmB,GAAP,CAAA;CAAZ,CAAkC,IAAR;CAA1B,CAAgD,EAAN,EAAA;CAFvC,KAER;CAjHN,EA+Gc;;CA/Gd,CAmHA,GAAK,CAAL;CACE,CAAS,CAAA,CAAT,CAAS,EAAT,EAAU;;CACE,CAAF,CAAA,CAAiB,IAAzB,CAAU,CAAA;QAAV;CACC,EAAW,CAAX,CAAW,IAAR,IAAJ;CACc,CAAM,EAAlB,CAAA,EAAA,GAAA,CAAA,IAAA;CAHK,MAEK;CAFd,IAAS;CAAT,CAKW,CAAA,CAAX,CAAW,IAAX;;CACY,CAAF,CAAA,CAAa,IAArB,EAAU,CAAW;QAArB;CAAA,EACY,CAAX,CAAW,CAAZ,GAAI;CACU,CAAM,EAAlB,CAAA,CAAA,EAAA,GAAA,IAAA;CAFF,MACY;CAGX,GAAA,MAAU,GAAX;CAVF,IAKW;CALX,CAYQ,CAAA,CAAR,CAAQ,CAAR,GAAS;;CACG,CAAF,CAAA,CAAc,IAAtB,CAAU,CAAA;QAAV;CACC,EAAW,CAAX,CAAW,IAAR,IAAJ;CACc,CAAM,EAAlB,CAAA,CAAA,GAAA,EAAA,IAAA;CAHI,MAEM;CAdd,IAYQ;CAhIV,GAmHA;;CAnHA,CAqIA,CAAmB,EAAd,KAAL;;CArIA,CAsIA,CAAkB,EAAb,IAAL;;CAtIA,CAuIA,CAAiB,EAAZ,GAAL;CAvIA"
}

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var $, Spine, escapeRegExp, hashStrip, namedParam, splatParam,
__hasProp = {}.hasOwnProperty,
@ -37,6 +37,7 @@
Route.add = function(path, callback) {
var key, value, _results;
if (typeof path === 'object' && !(path instanceof RegExp)) {
_results = [];
for (key in path) {
@ -81,6 +82,7 @@
Route.navigate = function() {
var args, lastArg, options, path;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
options = {};
lastArg = args[args.length - 1];
@ -113,6 +115,7 @@
Route.getPath = function() {
var path;
if (this.history) {
path = window.location.pathname;
if (path.substr(0, 1) !== '/') {
@ -131,6 +134,7 @@
Route.change = function() {
var path;
path = this.getPath();
if (path === this.path) {
return;
@ -141,6 +145,7 @@
Route.matchRoute = function(path, options) {
var route, _i, _len, _ref1;
_ref1 = this.routes;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
route = _ref1[_i];
@ -154,6 +159,7 @@
function Route(path, callback) {
var match;
this.path = path;
this.callback = callback;
this.names = [];
@ -175,6 +181,7 @@
Route.prototype.match = function(path, options) {
var i, match, param, params, _i, _len;
if (options == null) {
options = {};
}
@ -205,6 +212,7 @@
},
routes: function(routes) {
var key, value, _results;
_results = [];
for (key in routes) {
value = routes[key];
@ -222,3 +230,7 @@
}
}).call(this);
/*
//@ sourceMappingURL=route.map
*/

View file

@ -0,0 +1,10 @@
{
"version": 3,
"file": "route.js",
"sourceRoot": "..",
"sources": [
"src/route.coffee"
],
"names": [],
"mappings": ";AAAA;CAAA,KAAA,mDAAA;KAAA;;uBAAA;;CAAA,CAAA,CAAQ,CAAC,CAAT,EAAkB;;CAAlB,CACA,CAAQ,EAAK;;CADb,CAGA,CAAe,EAHf,IAGA;;CAHA,CAIA,CAAe,OAAf,GAJA;;CAAA,CAKA,CAAe,OAAf,IALA;;CAAA,CAMA,CAAe,SAAf,aANA;;CAAA,CAQM,GAAK;CACT,GAAA,IAAA;;CAAA;;CAAA,GAAA,CAAC,CAAD;;CAAA,EAEiB,CAAjB,CAAC,SAAD,qDAFA;;CAAA,CAAA,CAIS,CAAT,CAAC,CAAD;;CAJA,EAOE,CADF,CAAC,EAAD;CACE,CAAS,EAAT,EAAA,CAAA;CAAA,CACS,GADT,CAC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AS;CACP,SAAA,UAAA;;AAAA,CAAA;YAAA,CAAA;6BAAA;CAAA,CAAY,CAAZ,CAAC,CAAD;CAAA;uBADM;CAHR,IAGQ;CAHR,CAMU,CAAA,CAAV,IAAA,CAAU;CACF,CAAkC,GAAnC,GAAe,CAApB,IAAA;CAPF,IAMU;CAhJZ,GAyIA;;;CAUQ,EAAU,CAAlB,CAAuB,CAAjB,CAAN;IAnJA;CAAA"
}

View file

@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.2
(function() {
var $, Controller, Events, Log, Model, Module, Spine, createObject, isArray, isBlank, makeArray, moduleKeywords,
__slice = [].slice,
@ -10,6 +10,7 @@
Events = {
bind: function(ev, callback) {
var calls, evs, name, _i, _len;
evs = ev.split(' ');
calls = this.hasOwnProperty('_callbacks') && this._callbacks || (this._callbacks = {});
for (_i = 0, _len = evs.length; _i < _len; _i++) {
@ -20,13 +21,16 @@
return this;
},
one: function(ev, callback) {
return this.bind(ev, function() {
this.unbind(ev, arguments.callee);
var handler;
return this.bind(ev, handler = function() {
this.unbind(ev, handler);
return callback.apply(this, arguments);
});
},
trigger: function() {
var args, callback, ev, list, _i, _len, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
ev = args.shift();
list = this.hasOwnProperty('_callbacks') && ((_ref = this._callbacks) != null ? _ref[ev] : void 0);
@ -41,12 +45,84 @@
}
return true;
},
listenTo: function(obj, ev, callback) {
obj.bind(ev, callback);
this.listeningTo || (this.listeningTo = []);
this.listeningTo.push(obj);
return this;
},
listenToOnce: function(obj, ev, callback) {
var listeningToOnce;
listeningToOnce = this.listeningToOnce || (this.listeningToOnce = []);
listeningToOnce.push(obj);
obj.one(ev, function() {
var idx;
idx = listeningToOnce.indexOf(obj);
if (idx !== -1) {
listeningToOnce.splice(idx, 1);
}
return callback.apply(this, arguments);
});
return this;
},
stopListening: function(obj, ev, callback) {
var idx, listeningTo, retain, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _results;
if (arguments.length === 0) {
retain = [];
_ref = [this.listeningTo, this.listeningToOnce];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
listeningTo = _ref[_i];
if (!listeningTo) {
continue;
}
for (_j = 0, _len1 = listeningTo.length; _j < _len1; _j++) {
obj = listeningTo[_j];
if (!(!(__indexOf.call(retain, obj) >= 0))) {
continue;
}
obj.unbind();
retain.push(obj);
}
}
this.listeningTo = void 0;
return this.listeningToOnce = void 0;
} else if (obj) {
if (ev) {
obj.unbind(ev, callback);
}
if (!ev) {
obj.unbind();
}
_ref1 = [this.listeningTo, this.listeningToOnce];
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
listeningTo = _ref1[_k];
if (!listeningTo) {
continue;
}
idx = listeningTo.indexOf(obj);
if (idx !== -1) {
_results.push(listeningTo.splice(idx, 1));
} else {
_results.push(void 0);
}
}
return _results;
}
},
unbind: function(ev, callback) {
var cb, evs, i, list, name, _i, _j, _len, _len1, _ref;
if (!ev) {
if (arguments.length === 0) {
this._callbacks = {};
return this;
}
if (!ev) {
return this;
}
evs = ev.split(' ');
for (_i = 0, _len = evs.length; _i < _len; _i++) {
name = evs[_i];
@ -82,6 +158,7 @@
logPrefix: '(App)',
log: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (!this.trace) {
return;
@ -101,9 +178,9 @@
moduleKeywords = ['included', 'extended'];
Module = (function() {
Module.include = function(obj) {
var key, value, _ref;
if (!obj) {
throw new Error('include(obj) requires obj');
}
@ -121,6 +198,7 @@
Module.extend = function(obj) {
var key, value, _ref;
if (!obj) {
throw new Error('extend(obj) requires obj');
}
@ -138,6 +216,7 @@
Module.proxy = function(func) {
var _this = this;
return function() {
return func.apply(_this, arguments);
};
@ -145,6 +224,7 @@
Module.prototype.proxy = function(func) {
var _this = this;
return function() {
return func.apply(_this, arguments);
};
@ -161,12 +241,13 @@
})();
Model = (function(_super) {
__extends(Model, _super);
Model.extend(Events);
Model.records = {};
Model.records = [];
Model.irecords = {};
Model.crecords = {};
@ -174,10 +255,10 @@
Model.configure = function() {
var attributes, name;
name = arguments[0], attributes = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
this.className = name;
this.records = {};
this.crecords = {};
this.deleteAll();
if (attributes.length) {
this.attributes = attributes;
}
@ -193,41 +274,28 @@
Model.find = function(id) {
var record;
record = this.records[id];
if (!record && ("" + id).match(/c-\d+/)) {
return this.findCID(id);
}
if (!record) {
throw new Error("\"" + this.className + "\" model could not find a record for the ID \"" + id + "\"");
}
return record.clone();
};
Model.findCID = function(cid) {
var record;
record = this.crecords[cid];
record = this.exists(id);
if (!record) {
throw new Error("\"" + this.className + "\" model could not find a record for the ID \"" + id + "\"");
}
return record.clone();
return record;
};
Model.exists = function(id) {
try {
return this.find(id);
} catch (e) {
return false;
}
var _ref, _ref1;
return (_ref = (_ref1 = this.irecords[id]) != null ? _ref1 : this.crecords[id]) != null ? _ref.clone() : void 0;
};
Model.refresh = function(values, options) {
var record, records, _i, _len;
var record, records, result, _i, _len;
if (options == null) {
options = {};
}
if (options.clear) {
this.records = {};
this.crecords = {};
this.deleteAll();
}
records = this.fromJSON(values);
if (!isArray(records)) {
@ -235,36 +303,41 @@
}
for (_i = 0, _len = records.length; _i < _len; _i++) {
record = records[_i];
record.id || (record.id = record.cid);
this.records[record.id] = record;
if (record.id && this.irecords[record.id]) {
this.records[this.records.indexOf(this.irecords[record.id])] = record;
} else {
record.id || (record.id = record.cid);
this.records.push(record);
}
this.irecords[record.id] = record;
this.crecords[record.cid] = record;
}
this.sort();
result = this.cloneArray(records);
this.trigger('refresh', this.cloneArray(records));
return this;
return result;
};
Model.select = function(callback) {
var id, record, result;
result = (function() {
var _ref, _results;
_ref = this.records;
_results = [];
for (id in _ref) {
record = _ref[id];
if (callback(record)) {
_results.push(record);
}
var record, _i, _len, _ref, _results;
_ref = this.records;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
record = _ref[_i];
if (callback(record)) {
_results.push(record.clone());
}
return _results;
}).call(this);
return this.cloneArray(result);
}
return _results;
};
Model.findByAttribute = function(name, value) {
var id, record, _ref;
var record, _i, _len, _ref;
_ref = this.records;
for (id in _ref) {
record = _ref[id];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
record = _ref[_i];
if (record[name] === value) {
return record.clone();
}
@ -279,55 +352,51 @@
};
Model.each = function(callback) {
var key, value, _ref, _results;
var record, _i, _len, _ref, _results;
_ref = this.records;
_results = [];
for (key in _ref) {
value = _ref[key];
_results.push(callback(value.clone()));
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
record = _ref[_i];
_results.push(callback(record.clone()));
}
return _results;
};
Model.all = function() {
return this.cloneArray(this.recordsValues());
return this.cloneArray(this.records);
};
Model.first = function() {
var record;
record = this.recordsValues()[0];
return record != null ? record.clone() : void 0;
var _ref;
return (_ref = this.records[0]) != null ? _ref.clone() : void 0;
};
Model.last = function() {
var record, values;
values = this.recordsValues();
record = values[values.length - 1];
return record != null ? record.clone() : void 0;
var _ref;
return (_ref = this.records[this.records.length - 1]) != null ? _ref.clone() : void 0;
};
Model.count = function() {
return this.recordsValues().length;
return this.records.length;
};
Model.deleteAll = function() {
var key, value, _ref, _results;
_ref = this.records;
_results = [];
for (key in _ref) {
value = _ref[key];
_results.push(delete this.records[key]);
}
return _results;
this.records = [];
this.irecords = {};
return this.crecords = {};
};
Model.destroyAll = function(options) {
var key, value, _ref, _results;
var record, _i, _len, _ref, _results;
_ref = this.records;
_results = [];
for (key in _ref) {
value = _ref[key];
_results.push(this.records[key].destroy(options));
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
record = _ref[_i];
_results.push(record.destroy(options));
}
return _results;
};
@ -338,6 +407,7 @@
Model.create = function(atts, options) {
var record;
record = new this(atts);
return record.save(options);
};
@ -350,7 +420,7 @@
if (typeof callbackOrParams === 'function') {
return this.bind('change', callbackOrParams);
} else {
return this.trigger('change', callbackOrParams);
return this.trigger.apply(this, ['change'].concat(__slice.call(arguments)));
}
};
@ -358,16 +428,17 @@
if (typeof callbackOrParams === 'function') {
return this.bind('fetch', callbackOrParams);
} else {
return this.trigger('fetch', callbackOrParams);
return this.trigger.apply(this, ['fetch'].concat(__slice.call(arguments)));
}
};
Model.toJSON = function() {
return this.recordsValues();
return this.records;
};
Model.fromJSON = function(objects) {
var value, _i, _len, _results;
if (!objects) {
return;
}
@ -388,22 +459,20 @@
Model.fromForm = function() {
var _ref;
return (_ref = new this).fromForm.apply(_ref, arguments);
};
Model.recordsValues = function() {
var key, result, value, _ref;
result = [];
_ref = this.records;
for (key in _ref) {
value = _ref[key];
result.push(value);
Model.sort = function() {
if (this.comparator) {
this.records.sort(this.comparator);
}
return result;
return this.records;
};
Model.cloneArray = function(array) {
var value, _i, _len, _results;
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
value = array[_i];
@ -416,6 +485,7 @@
Model.uid = function(prefix) {
var uid;
if (prefix == null) {
prefix = '';
}
@ -446,9 +516,13 @@
Model.prototype.load = function(atts) {
var key, value;
if (atts.id) {
this.id = atts.id;
}
for (key in atts) {
value = atts[key];
if (typeof this[key] === 'function') {
if (atts.hasOwnProperty(key) && typeof this[key] === 'function') {
this[key](value);
} else {
this[key] = value;
@ -459,6 +533,7 @@
Model.prototype.attributes = function() {
var key, result, _i, _len, _ref;
result = {};
_ref = this.constructor.attributes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -483,6 +558,7 @@
Model.prototype.save = function(options) {
var error, record;
if (options == null) {
options = {};
}
@ -502,6 +578,7 @@
Model.prototype.stripCloneAttrs = function() {
var key, value;
if (this.hasOwnProperty('cid')) {
return;
}
@ -517,6 +594,7 @@
Model.prototype.updateAttribute = function(name, value, options) {
var atts;
atts = {};
atts[name] = value;
return this.updateAttributes(atts, options);
@ -529,7 +607,8 @@
Model.prototype.changeID = function(id) {
var records;
records = this.constructor.records;
records = this.constructor.irecords;
records[id] = records[this.id];
delete records[this.id];
this.id = id;
@ -537,21 +616,37 @@
};
Model.prototype.destroy = function(options) {
var i, record, records, _i, _len;
if (options == null) {
options = {};
}
this.trigger('beforeDestroy', options);
delete this.constructor.records[this.id];
records = this.constructor.records.slice(0);
for (i = _i = 0, _len = records.length; _i < _len; i = ++_i) {
record = records[i];
if (!(this.eql(record))) {
continue;
}
records.splice(i, 1);
break;
}
this.constructor.records = records;
delete this.constructor.irecords[this.id];
delete this.constructor.crecords[this.cid];
this.destroyed = true;
this.trigger('destroy', options);
this.trigger('change', 'destroy', options);
if (this.listeningTo) {
this.stopListening();
}
this.unbind();
return this;
};
Model.prototype.dup = function(newRecord) {
var result;
result = new this.constructor(this.attributes());
if (newRecord === false) {
result.cid = this.cid;
@ -567,6 +662,7 @@
Model.prototype.reload = function() {
var original;
if (this.isNew()) {
return this;
}
@ -585,6 +681,7 @@
Model.prototype.fromForm = function(form) {
var key, result, _i, _len, _ref;
result = {};
_ref = $(form).serializeArray();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -595,14 +692,16 @@
};
Model.prototype.exists = function() {
return this.id && this.id in this.constructor.records;
return this.constructor.exists(this.id);
};
Model.prototype.update = function(options) {
var clone, records;
this.trigger('beforeUpdate', options);
records = this.constructor.records;
records = this.constructor.irecords;
records[this.id].load(this.attributes());
this.constructor.sort();
clone = records[this.id].clone();
clone.trigger('update', options);
clone.trigger('change', 'update', options);
@ -611,13 +710,16 @@
Model.prototype.create = function(options) {
var clone, record;
this.trigger('beforeCreate', options);
if (!this.id) {
this.id = this.cid;
}
record = this.dup(false);
this.constructor.records[this.id] = record;
this.constructor.records.push(record);
this.constructor.irecords[this.id] = record;
this.constructor.crecords[this.cid] = record;
this.constructor.sort();
clone = record.clone();
clone.trigger('create', options);
clone.trigger('change', 'create', options);
@ -625,48 +727,155 @@
};
Model.prototype.bind = function(events, callback) {
var binder, unbinder,
var binder, singleEvent, _fn, _i, _len, _ref,
_this = this;
this.constructor.bind(events, binder = function(record) {
if (record && _this.eql(record)) {
return callback.apply(_this, arguments);
}
});
this.constructor.bind('unbind', unbinder = function(record) {
if (record && _this.eql(record)) {
_this.constructor.unbind(events, binder);
return _this.constructor.unbind('unbind', unbinder);
}
});
return binder;
_ref = events.split(' ');
_fn = function(singleEvent) {
var unbinder;
return _this.constructor.bind("unbind", unbinder = function(record, event, cb) {
if (record && _this.eql(record)) {
if (event && event !== singleEvent) {
return;
}
if (cb && cb !== callback) {
return;
}
_this.constructor.unbind(singleEvent, binder);
return _this.constructor.unbind("unbind", unbinder);
}
});
};
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
singleEvent = _ref[_i];
_fn(singleEvent);
}
return this;
};
Model.prototype.one = function(events, callback) {
var binder,
var handler,
_this = this;
return binder = this.bind(events, function() {
_this.constructor.unbind(events, binder);
return this.bind(events, handler = function() {
_this.unbind(events, handler);
return callback.apply(_this, arguments);
});
};
Model.prototype.trigger = function() {
var args, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
args.splice(1, 0, this);
return (_ref = this.constructor).trigger.apply(_ref, args);
};
Model.prototype.unbind = function() {
return this.trigger('unbind');
Model.prototype.listenTo = function(obj, events, callback) {
obj.bind(events, callback);
this.listeningTo || (this.listeningTo = []);
return this.listeningTo.push(obj);
};
Model.prototype.listenToOnce = function(obj, events, callback) {
var handler, listeningToOnce,
_this = this;
listeningToOnce = this.listeningToOnce || (this.listeningToOnce = []);
listeningToOnce.push(obj);
return obj.bind(events, handler = function() {
var idx;
idx = listeningToOnce.indexOf(obj);
if (idx !== -1) {
listeningToOnce.splice(idx, 1);
}
obj.unbind(events, handler);
return callback.apply(obj, arguments);
});
};
Model.prototype.stopListening = function(obj, events, callback) {
var idx, listeningTo, retain, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
if (arguments.length === 0) {
retain = [];
_ref = [this.listeningTo, this.listeningToOnce];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
listeningTo = _ref[_i];
if (!listeningTo) {
continue;
}
_ref1 = this.listeningTo;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
obj = _ref1[_j];
if (!(!(__indexOf.call(retain, obj) >= 0))) {
continue;
}
obj.unbind();
retain.push(obj);
}
}
this.listeningTo = void 0;
this.listeningToOnce = void 0;
return;
}
if (obj) {
if (!events) {
obj.unbind();
}
if (events) {
obj.unbind(events, callback);
}
_ref2 = [this.listeningTo, this.listeningToOnce];
_results = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
listeningTo = _ref2[_k];
if (!listeningTo) {
continue;
}
idx = listeningTo.indexOf(obj);
if (idx !== -1) {
_results.push(listeningTo.splice(idx, 1));
} else {
_results.push(void 0);
}
}
return _results;
}
};
Model.prototype.unbind = function(events, callback) {
var event, _i, _len, _ref, _results;
if (arguments.length === 0) {
return this.trigger('unbind');
} else if (events) {
_ref = events.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push(this.trigger('unbind', event, callback));
}
return _results;
}
};
return Model;
})(Module);
Controller = (function(_super) {
Model.prototype.on = Model.prototype.bind;
Model.prototype.off = Model.prototype.unbind;
Controller = (function(_super) {
__extends(Controller, _super);
Controller.include(Events);
@ -679,8 +888,8 @@
function Controller(options) {
this.release = __bind(this.release, this);
var context, key, parent_prototype, value, _ref;
var key, value, _ref;
this.options = options;
_ref = this.options;
for (key in _ref) {
@ -704,6 +913,16 @@
if (!this.elements) {
this.elements = this.constructor.elements;
}
context = this;
while (parent_prototype = context.constructor.__super__) {
if (parent_prototype.events) {
this.events = $.extend({}, parent_prototype.events, this.events);
}
if (parent_prototype.elements) {
this.elements = $.extend({}, parent_prototype.elements, this.elements);
}
context = parent_prototype;
}
if (this.events) {
this.delegateEvents(this.events);
}
@ -714,9 +933,10 @@
}
Controller.prototype.release = function() {
this.trigger('release');
this.trigger('release', this);
this.el.remove();
return this.unbind();
this.unbind();
return this.stopListening();
};
Controller.prototype.$ = function(selector) {
@ -726,6 +946,7 @@
Controller.prototype.delegateEvents = function(events) {
var eventName, key, match, method, selector, _results,
_this = this;
_results = [];
for (key in events) {
method = events[key];
@ -761,6 +982,7 @@
Controller.prototype.refreshElements = function() {
var key, value, _ref, _results;
_ref = this.elements;
_results = [];
for (key in _ref) {
@ -782,9 +1004,11 @@
Controller.prototype.append = function() {
var e, elements, _ref;
elements = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
elements = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
e = elements[_i];
@ -805,9 +1029,11 @@
Controller.prototype.prepend = function() {
var e, elements, _ref;
elements = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
elements = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
e = elements[_i];
@ -822,6 +1048,7 @@
Controller.prototype.replace = function(element) {
var previous, _ref;
_ref = [this.el, $(element.el || element)], previous = _ref[0], this.el = _ref[1];
previous.replaceWith(this.el);
this.delegateEvents(this.events);
@ -839,6 +1066,7 @@
createObject = Object.create || function(o) {
var Func;
Func = function() {};
Func.prototype = o;
return new Func();
@ -850,6 +1078,7 @@
isBlank = function(value) {
var key;
if (!value) {
return true;
}
@ -869,7 +1098,7 @@
module.exports = Spine;
}
Spine.version = '1.0.9';
Spine.version = '1.1.0';
Spine.isArray = isArray;
@ -890,13 +1119,14 @@
Module.extend.call(Spine, Events);
Module.create = Module.sub = Controller.create = Controller.sub = Model.sub = function(instances, statics) {
var Result;
Result = (function(_super) {
var Result, _ref;
Result = (function(_super) {
__extends(Result, _super);
function Result() {
return Result.__super__.constructor.apply(this, arguments);
_ref = Result.__super__.constructor.apply(this, arguments);
return _ref;
}
return Result;
@ -915,16 +1145,17 @@
};
Model.setup = function(name, attributes) {
var Instance;
var Instance, _ref;
if (attributes == null) {
attributes = [];
}
Instance = (function(_super) {
__extends(Instance, _super);
function Instance() {
return Instance.__super__.constructor.apply(this, arguments);
_ref = Instance.__super__.constructor.apply(this, arguments);
return _ref;
}
return Instance;
@ -937,3 +1168,7 @@
Spine.Class = Module;
}).call(this);
/*
//@ sourceMappingURL=spine.map
*/

File diff suppressed because one or more lines are too long