mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-24 20:26:13 +10:00
Added v1.2.0 of spinejs - http://spinejs.com/
This commit is contained in:
Executable
+384
@@ -0,0 +1,384 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(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; };
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
$ = Spine.$;
|
||||
|
||||
Model = Spine.Model;
|
||||
|
||||
Queue = $({});
|
||||
|
||||
Ajax = {
|
||||
getURL: function(object) {
|
||||
return (typeof object.url === "function" ? object.url() : void 0) || object.url;
|
||||
},
|
||||
getCollectionURL: function(object) {
|
||||
if (object) {
|
||||
if (typeof object.url === "function") {
|
||||
return this.generateURL(object);
|
||||
} else {
|
||||
return 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 (_error) {
|
||||
e = _error;
|
||||
throw e;
|
||||
} finally {
|
||||
this.enabled = true;
|
||||
}
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
},
|
||||
queue: function(request) {
|
||||
if (request) {
|
||||
return Queue.queue(request);
|
||||
} else {
|
||||
return Queue.queue();
|
||||
}
|
||||
},
|
||||
clearQueue: function() {
|
||||
return this.queue([]);
|
||||
}
|
||||
};
|
||||
|
||||
Base = (function() {
|
||||
function Base() {}
|
||||
|
||||
Base.prototype.defaults = {
|
||||
dataType: 'json',
|
||||
processData: false,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
};
|
||||
|
||||
Base.prototype.queue = Ajax.queue;
|
||||
|
||||
Base.prototype.ajax = function(params, defaults) {
|
||||
return $.ajax(this.ajaxSettings(params, defaults));
|
||||
};
|
||||
|
||||
Base.prototype.ajaxQueue = function(params, defaults, record) {
|
||||
var deferred, jqXHR, promise, request, settings;
|
||||
jqXHR = null;
|
||||
deferred = $.Deferred();
|
||||
promise = deferred.promise();
|
||||
if (!Ajax.enabled) {
|
||||
return promise;
|
||||
}
|
||||
settings = this.ajaxSettings(params, defaults);
|
||||
request = function(next) {
|
||||
var _ref;
|
||||
if ((record != null ? record.id : void 0) != null) {
|
||||
if (settings.url == null) {
|
||||
settings.url = Ajax.getURL(record);
|
||||
}
|
||||
if ((_ref = settings.data) != null) {
|
||||
_ref.id = record.id;
|
||||
}
|
||||
}
|
||||
settings.data = JSON.stringify(settings.data);
|
||||
return jqXHR = $.ajax(settings).done(deferred.resolve).fail(deferred.reject).then(next, next);
|
||||
};
|
||||
promise.abort = function(statusText) {
|
||||
var index;
|
||||
if (jqXHR) {
|
||||
return jqXHR.abort(statusText);
|
||||
}
|
||||
index = $.inArray(request, this.queue());
|
||||
if (index > -1) {
|
||||
this.queue().splice(index, 1);
|
||||
}
|
||||
deferred.rejectWith(settings.context || settings, [promise, statusText, '']);
|
||||
return promise;
|
||||
};
|
||||
this.queue(request);
|
||||
return promise;
|
||||
};
|
||||
|
||||
Base.prototype.ajaxSettings = function(params, defaults) {
|
||||
return $.extend({}, this.defaults, defaults, params);
|
||||
};
|
||||
|
||||
return Base;
|
||||
|
||||
})();
|
||||
|
||||
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, options) {
|
||||
var record;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
record = new this.model({
|
||||
id: id
|
||||
});
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'GET',
|
||||
url: options.url || Ajax.getURL(record)
|
||||
}).done(this.recordsResponse).fail(this.failResponse);
|
||||
};
|
||||
|
||||
Collection.prototype.all = function(params, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'GET',
|
||||
url: options.url || Ajax.getURL(this.model)
|
||||
}).done(this.recordsResponse).fail(this.failResponse);
|
||||
};
|
||||
|
||||
Collection.prototype.fetch = function(params, options) {
|
||||
var id,
|
||||
_this = this;
|
||||
if (params == null) {
|
||||
params = {};
|
||||
}
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (id = params.id) {
|
||||
delete params.id;
|
||||
return this.find(id, params, options).done(function(record) {
|
||||
return _this.model.refresh(record, options);
|
||||
});
|
||||
} else {
|
||||
return this.all(params, options).done(function(records) {
|
||||
return _this.model.refresh(records, options);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Collection.prototype.recordsResponse = function(data, status, xhr) {
|
||||
return this.model.trigger('ajaxSuccess', null, status, xhr);
|
||||
};
|
||||
|
||||
Collection.prototype.failResponse = function(xhr, statusText, error) {
|
||||
return this.model.trigger('ajaxError', null, xhr, statusText, error);
|
||||
};
|
||||
|
||||
return Collection;
|
||||
|
||||
})(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;
|
||||
}
|
||||
|
||||
Singleton.prototype.reload = function(params, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'GET',
|
||||
url: options.url
|
||||
}, this.record).done(this.recordResponse(options)).fail(this.failResponse(options));
|
||||
};
|
||||
|
||||
Singleton.prototype.create = function(params, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: this.record.toJSON(),
|
||||
url: options.url || Ajax.getCollectionURL(this.record)
|
||||
}).done(this.recordResponse(options)).fail(this.failResponse(options));
|
||||
};
|
||||
|
||||
Singleton.prototype.update = function(params, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: this.record.toJSON(),
|
||||
url: options.url
|
||||
}, this.record).done(this.recordResponse(options)).fail(this.failResponse(options));
|
||||
};
|
||||
|
||||
Singleton.prototype.destroy = function(params, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return this.ajaxQueue(params, {
|
||||
type: 'DELETE',
|
||||
url: options.url
|
||||
}, this.record).done(this.recordResponse(options)).fail(this.failResponse(options));
|
||||
};
|
||||
|
||||
Singleton.prototype.recordResponse = function(options) {
|
||||
var _this = this;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return function(data, status, xhr) {
|
||||
var _ref, _ref1;
|
||||
Ajax.disable(function() {
|
||||
if (!(Spine.isBlank(data) || _this.record.destroyed)) {
|
||||
if (data.id && _this.record.id !== data.id) {
|
||||
_this.record.changeID(data.id);
|
||||
}
|
||||
return _this.record.refresh(data);
|
||||
}
|
||||
});
|
||||
_this.record.trigger('ajaxSuccess', data, status, xhr);
|
||||
if ((_ref = options.success) != null) {
|
||||
_ref.apply(_this.record);
|
||||
}
|
||||
return (_ref1 = options.done) != null ? _ref1.apply(_this.record) : void 0;
|
||||
};
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
return (_ref1 = options.fail) != null ? _ref1.apply(_this.record) : void 0;
|
||||
};
|
||||
};
|
||||
|
||||
return Singleton;
|
||||
|
||||
})(Base);
|
||||
|
||||
Model.host = '';
|
||||
|
||||
Include = {
|
||||
ajax: function() {
|
||||
return new Singleton(this);
|
||||
},
|
||||
url: function() {
|
||||
var args;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
args.unshift(encodeURIComponent(this.id));
|
||||
return Ajax.generateURL.apply(Ajax, [this].concat(__slice.call(args)));
|
||||
}
|
||||
};
|
||||
|
||||
Extend = {
|
||||
ajax: function() {
|
||||
return new Collection(this);
|
||||
},
|
||||
url: function() {
|
||||
var args;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
return Ajax.generateURL.apply(Ajax, [this].concat(__slice.call(args)));
|
||||
}
|
||||
};
|
||||
|
||||
Model.Ajax = {
|
||||
extended: function() {
|
||||
this.fetch(this.ajaxFetch);
|
||||
this.change(this.ajaxChange);
|
||||
this.extend(Extend);
|
||||
return this.include(Include);
|
||||
},
|
||||
ajaxFetch: function() {
|
||||
var _ref;
|
||||
return (_ref = this.ajax()).fetch.apply(_ref, arguments);
|
||||
},
|
||||
ajaxChange: function(record, type, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (options.ajax === false) {
|
||||
return;
|
||||
}
|
||||
return record.ajax()[type](options.ajax, options);
|
||||
}
|
||||
};
|
||||
|
||||
Model.Ajax.Methods = {
|
||||
extended: function() {
|
||||
this.extend(Extend);
|
||||
return this.include(Include);
|
||||
}
|
||||
};
|
||||
|
||||
Ajax.defaults = Base.prototype.defaults;
|
||||
|
||||
Ajax.Base = Base;
|
||||
|
||||
Ajax.Singleton = Singleton;
|
||||
|
||||
Ajax.Collection = Collection;
|
||||
|
||||
Spine.Ajax = Ajax;
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = Ajax;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=ajax.map
|
||||
*/
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+3
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Executable
+77
@@ -0,0 +1,77 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var $, Spine,
|
||||
__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; };
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
$ = Spine.$;
|
||||
|
||||
Spine.List = (function(_super) {
|
||||
__extends(List, _super);
|
||||
|
||||
List.prototype.events = {
|
||||
'click .item': 'click'
|
||||
};
|
||||
|
||||
List.prototype.selectFirst = false;
|
||||
|
||||
function List() {
|
||||
this.change = __bind(this.change, this);
|
||||
List.__super__.constructor.apply(this, arguments);
|
||||
this.bind('change', this.change);
|
||||
}
|
||||
|
||||
List.prototype.template = function() {
|
||||
throw 'Override template';
|
||||
};
|
||||
|
||||
List.prototype.change = function(item) {
|
||||
this.current = item;
|
||||
if (!this.current) {
|
||||
this.children().removeClass('active');
|
||||
return;
|
||||
}
|
||||
this.children().removeClass('active');
|
||||
return $(this.children().get(this.items.indexOf(this.current))).addClass('active');
|
||||
};
|
||||
|
||||
List.prototype.render = function(items) {
|
||||
if (items) {
|
||||
this.items = items;
|
||||
}
|
||||
this.html(this.template(this.items));
|
||||
this.change(this.current);
|
||||
if (this.selectFirst) {
|
||||
if (!this.children('.active').length) {
|
||||
return this.children(':first').click();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List.prototype.children = function(sel) {
|
||||
return this.el.children(sel);
|
||||
};
|
||||
|
||||
List.prototype.click = function(e) {
|
||||
var item;
|
||||
item = this.items[$(e.currentTarget).index()];
|
||||
this.trigger('change', item);
|
||||
return true;
|
||||
};
|
||||
|
||||
return List;
|
||||
|
||||
})(Spine.Controller);
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = Spine.List;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=list.map
|
||||
*/
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
(function(){var $,Spine,__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};Spine=this.Spine||require("spine");$=Spine.$;Spine.List=function(_super){__extends(List,_super);List.prototype.events={"click .item":"click"};List.prototype.selectFirst=false;function List(){this.change=__bind(this.change,this);List.__super__.constructor.apply(this,arguments);this.bind("change",this.change)}List.prototype.template=function(){throw"Override template"};List.prototype.change=function(item){this.current=item;if(!this.current){this.children().removeClass("active");return}this.children().removeClass("active");return $(this.children().get(this.items.indexOf(this.current))).addClass("active")};List.prototype.render=function(items){if(items){this.items=items}this.html(this.template(this.items));this.change(this.current);if(this.selectFirst){if(!this.children(".active").length){return this.children(":first").click()}}};List.prototype.children=function(sel){return this.el.children(sel)};List.prototype.click=function(e){var item;item=this.items[$(e.currentTarget).index()];this.trigger("change",item);return true};return List}(Spine.Controller);if(typeof module!=="undefined"&&module!==null){module.exports=Spine.List}}).call(this);
|
||||
//# sourceMappingURL=list.min.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"list.min.js","sources":["list.js"],"names":["$","Spine","__bind","fn","me","apply","arguments","__hasProp","hasOwnProperty","__extends","child","parent","key","call","ctor","this","constructor","prototype","__super__","require","List","_super","events","click .item","selectFirst","change","bind","template","item","current","children","removeClass","get","items","indexOf","addClass","render","html","length","click","sel","el","e","currentTarget","index","trigger","Controller","module","exports"],"mappings":"CACA,WACE,GAAIA,GAAGC,MACLC,OAAS,SAASC,GAAIC,IAAK,MAAO,YAAY,MAAOD,IAAGE,MAAMD,GAAIE,aAClEC,aAAeC,eACfC,UAAY,SAASC,MAAOC,QAAU,IAAK,GAAIC,OAAOD,QAAQ,CAAE,GAAIJ,UAAUM,KAAKF,OAAQC,KAAMF,MAAME,KAAOD,OAAOC,KAAQ,QAASE,QAASC,KAAKC,YAAcN,MAASI,KAAKG,UAAYN,OAAOM,SAAWP,OAAMO,UAAY,GAAIH,KAAQJ,OAAMQ,UAAYP,OAAOM,SAAW,OAAOP,OAEzRT,OAAQc,KAAKd,OAASkB,QAAQ,QAE9BnB,GAAIC,MAAMD,CAEVC,OAAMmB,KAAO,SAAUC,QACrBZ,UAAUW,KAAMC,OAEhBD,MAAKH,UAAUK,QACbC,cAAe,QAGjBH,MAAKH,UAAUO,YAAc,KAE7B,SAASJ,QACPL,KAAKU,OAASvB,OAAOa,KAAKU,OAAQV,KAClCK,MAAKF,UAAUF,YAAYX,MAAMU,KAAMT,UACvCS,MAAKW,KAAK,SAAUX,KAAKU,QAG3BL,KAAKH,UAAUU,SAAW,WACxB,KAAM,oBAGRP,MAAKH,UAAUQ,OAAS,SAASG,MAC/Bb,KAAKc,QAAUD,IACf,KAAKb,KAAKc,QAAS,CACjBd,KAAKe,WAAWC,YAAY,SAC5B,QAEFhB,KAAKe,WAAWC,YAAY,SAC5B,OAAO/B,GAAEe,KAAKe,WAAWE,IAAIjB,KAAKkB,MAAMC,QAAQnB,KAAKc,WAAWM,SAAS,UAG3Ef,MAAKH,UAAUmB,OAAS,SAASH,OAC/B,GAAIA,MAAO,CACTlB,KAAKkB,MAAQA,MAEflB,KAAKsB,KAAKtB,KAAKY,SAASZ,KAAKkB,OAC7BlB,MAAKU,OAAOV,KAAKc,QACjB,IAAId,KAAKS,YAAa,CACpB,IAAKT,KAAKe,SAAS,WAAWQ,OAAQ,CACpC,MAAOvB,MAAKe,SAAS,UAAUS,UAKrCnB,MAAKH,UAAUa,SAAW,SAASU,KACjC,MAAOzB,MAAK0B,GAAGX,SAASU,KAG1BpB,MAAKH,UAAUsB,MAAQ,SAASG,GAC9B,GAAId,KACJA,MAAOb,KAAKkB,MAAMjC,EAAE0C,EAAEC,eAAeC,QACrC7B,MAAK8B,QAAQ,SAAUjB,KACvB,OAAO,MAGT,OAAOR,OAENnB,MAAM6C,WAET,UAAWC,UAAW,aAAeA,SAAW,KAAM,CACpDA,OAAOC,QAAU/C,MAAMmB,QAGxBP,KAAKE"}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var Spine;
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
Spine.Model.Local = {
|
||||
extended: function() {
|
||||
this.change(this.saveLocal);
|
||||
return this.fetch(this.loadLocal);
|
||||
},
|
||||
saveLocal: function() {
|
||||
var result;
|
||||
result = JSON.stringify(this);
|
||||
return localStorage[this.className] = result;
|
||||
},
|
||||
loadLocal: function(options) {
|
||||
var result;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (!options.hasOwnProperty('clear')) {
|
||||
options.clear = true;
|
||||
}
|
||||
result = localStorage[this.className];
|
||||
return this.refresh(result || [], options);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = Spine.Model.Local;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=local.map
|
||||
*/
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
(function(){var Spine;Spine=this.Spine||require("spine");Spine.Model.Local={extended:function(){this.change(this.saveLocal);return this.fetch(this.loadLocal)},saveLocal:function(){var result;result=JSON.stringify(this);return localStorage[this.className]=result},loadLocal:function(options){var result;if(options==null){options={}}if(!options.hasOwnProperty("clear")){options.clear=true}result=localStorage[this.className];return this.refresh(result||[],options)}};if(typeof module!=="undefined"&&module!==null){module.exports=Spine.Model.Local}}).call(this);
|
||||
//# sourceMappingURL=local.min.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"local.min.js","sources":["local.js"],"names":["Spine","this","require","Model","Local","extended","change","saveLocal","fetch","loadLocal","result","JSON","stringify","localStorage","className","options","hasOwnProperty","clear","refresh","module","exports","call"],"mappings":"CACA,WACE,GAAIA,MAEJA,OAAQC,KAAKD,OAASE,QAAQ,QAE9BF,OAAMG,MAAMC,OACVC,SAAU,WACRJ,KAAKK,OAAOL,KAAKM,UACjB,OAAON,MAAKO,MAAMP,KAAKQ,YAEzBF,UAAW,WACT,GAAIG,OACJA,QAASC,KAAKC,UAAUX,KACxB,OAAOY,cAAaZ,KAAKa,WAAaJ,QAExCD,UAAW,SAASM,SAClB,GAAIL,OACJ,IAAIK,SAAW,KAAM,CACnBA,WAEF,IAAKA,QAAQC,eAAe,SAAU,CACpCD,QAAQE,MAAQ,KAElBP,OAASG,aAAaZ,KAAKa,UAC3B,OAAOb,MAAKiB,QAAQR,WAAcK,UAItC,UAAWI,UAAW,aAAeA,SAAW,KAAM,CACpDA,OAAOC,QAAUpB,MAAMG,MAAMC,SAG9BiB,KAAKpB"}
|
||||
Executable
+162
@@ -0,0 +1,162 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var $, Spine,
|
||||
__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;
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
$ = Spine.$;
|
||||
|
||||
Spine.Manager = (function(_super) {
|
||||
__extends(Manager, _super);
|
||||
|
||||
Manager.include(Spine.Events);
|
||||
|
||||
function Manager() {
|
||||
this.controllers = [];
|
||||
this.bind('change', this.change);
|
||||
this.add.apply(this, arguments);
|
||||
}
|
||||
|
||||
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++) {
|
||||
cont = controllers[_i];
|
||||
_results.push(this.addOne(cont));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
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)));
|
||||
});
|
||||
controller.bind('release', function() {
|
||||
return _this.controllers.splice(_this.controllers.indexOf(controller), 1);
|
||||
});
|
||||
return this.controllers.push(controller);
|
||||
};
|
||||
|
||||
Manager.prototype.deactivate = function() {
|
||||
return this.trigger.apply(this, ['change', false].concat(__slice.call(arguments)));
|
||||
};
|
||||
|
||||
Manager.prototype.change = function() {
|
||||
var args, cont, current, _i, _len, _ref;
|
||||
current = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
_ref = this.controllers;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
cont = _ref[_i];
|
||||
if (cont !== current) {
|
||||
cont.deactivate.apply(cont, args);
|
||||
}
|
||||
}
|
||||
if (current) {
|
||||
return current.activate.apply(current, args);
|
||||
}
|
||||
};
|
||||
|
||||
return Manager;
|
||||
|
||||
})(Spine.Module);
|
||||
|
||||
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]);
|
||||
} else {
|
||||
args.unshift('active');
|
||||
this.trigger.apply(this, args);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
isActive: function() {
|
||||
return this.el.hasClass('active');
|
||||
},
|
||||
activate: function() {
|
||||
this.el.addClass('active');
|
||||
return this;
|
||||
},
|
||||
deactivate: function() {
|
||||
this.el.removeClass('active');
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
Spine.Stack = (function(_super) {
|
||||
__extends(Stack, _super);
|
||||
|
||||
Stack.prototype.controllers = {};
|
||||
|
||||
Stack.prototype.routes = {};
|
||||
|
||||
Stack.prototype.className = 'spine stack';
|
||||
|
||||
function Stack() {
|
||||
var key, value, _fn, _ref, _ref1,
|
||||
_this = this;
|
||||
Stack.__super__.constructor.apply(this, arguments);
|
||||
this.manager = new Spine.Manager;
|
||||
_ref = this.controllers;
|
||||
for (key in _ref) {
|
||||
value = _ref[key];
|
||||
if (this[key] != null) {
|
||||
throw Error("'@" + key + "' already assigned - choose a different name");
|
||||
}
|
||||
this[key] = new value({
|
||||
stack: this
|
||||
});
|
||||
this.add(this[key]);
|
||||
}
|
||||
_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);
|
||||
};
|
||||
for (key in _ref1) {
|
||||
value = _ref1[key];
|
||||
_fn(key, value);
|
||||
}
|
||||
if (this["default"]) {
|
||||
this[this["default"]].active();
|
||||
}
|
||||
}
|
||||
|
||||
Stack.prototype.add = function(controller) {
|
||||
this.manager.add(controller);
|
||||
return this.append(controller);
|
||||
};
|
||||
|
||||
return Stack;
|
||||
|
||||
})(Spine.Controller);
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = Spine.Manager;
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports.Stack = Spine.Stack;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=manager.map
|
||||
*/
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
(function(){var $,Spine,__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;Spine=this.Spine||require("spine");$=Spine.$;Spine.Manager=function(_super){__extends(Manager,_super);Manager.include(Spine.Events);function Manager(){this.controllers=[];this.bind("change",this.change);this.add.apply(this,arguments)}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++){cont=controllers[_i];_results.push(this.addOne(cont))}return _results};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)))});controller.bind("release",function(){return _this.controllers.splice(_this.controllers.indexOf(controller),1)});return this.controllers.push(controller)};Manager.prototype.deactivate=function(){return this.trigger.apply(this,["change",false].concat(__slice.call(arguments)))};Manager.prototype.change=function(){var args,cont,current,_i,_len,_ref;current=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[];_ref=this.controllers;for(_i=0,_len=_ref.length;_i<_len;_i++){cont=_ref[_i];if(cont!==current){cont.deactivate.apply(cont,args)}}if(current){return current.activate.apply(current,args)}};return Manager}(Spine.Module);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])}else{args.unshift("active");this.trigger.apply(this,args)}return this},isActive:function(){return this.el.hasClass("active")},activate:function(){this.el.addClass("active");return this},deactivate:function(){this.el.removeClass("active");return this}});Spine.Stack=function(_super){__extends(Stack,_super);Stack.prototype.controllers={};Stack.prototype.routes={};Stack.prototype.className="spine stack";function Stack(){var key,value,_fn,_ref,_ref1,_this=this;Stack.__super__.constructor.apply(this,arguments);this.manager=new Spine.Manager;_ref=this.controllers;for(key in _ref){value=_ref[key];if(this[key]!=null){throw Error("'@"+key+"' already assigned - choose a different name")}this[key]=new value({stack:this});this.add(this[key])}_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)};for(key in _ref1){value=_ref1[key];_fn(key,value)}if(this["default"]){this[this["default"]].active()}}Stack.prototype.add=function(controller){this.manager.add(controller);return this.append(controller)};return Stack}(Spine.Controller);if(typeof module!=="undefined"&&module!==null){module.exports=Spine.Manager}if(typeof module!=="undefined"&&module!==null){module.exports.Stack=Spine.Stack}}).call(this);
|
||||
//# sourceMappingURL=manager.min.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"manager.min.js","sources":["manager.js"],"names":["$","Spine","__hasProp","hasOwnProperty","__extends","child","parent","key","call","ctor","this","constructor","prototype","__super__","__slice","slice","require","Manager","_super","include","Events","controllers","bind","change","add","apply","arguments","cont","_i","_len","_results","length","push","addOne","controller","_this","args","trigger","concat","splice","indexOf","deactivate","current","_ref","activate","Module","Controller","active","unshift","isActive","el","hasClass","addClass","removeClass","Stack","routes","className","value","_fn","_ref1","manager","Error","stack","callback","_ref2","route","append","module","exports"],"mappings":"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"}
|
||||
Executable
+264
@@ -0,0 +1,264 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
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; };
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
isArray = Spine.isArray;
|
||||
|
||||
require = this.require || (function(value) {
|
||||
return eval(value);
|
||||
});
|
||||
|
||||
Collection = (function(_super) {
|
||||
__extends(Collection, _super);
|
||||
|
||||
function Collection(options) {
|
||||
var key, value;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
for (key in options) {
|
||||
value = options[key];
|
||||
this[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
Collection.prototype.all = function() {
|
||||
var _this = this;
|
||||
return this.model.select(function(rec) {
|
||||
return _this.associated(rec);
|
||||
});
|
||||
};
|
||||
|
||||
Collection.prototype.first = function() {
|
||||
return this.all()[0];
|
||||
};
|
||||
|
||||
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);
|
||||
});
|
||||
if (!records[0]) {
|
||||
throw new Error("\"" + this.model.className + "\" model could not find a record for the ID \"" + id + "\"");
|
||||
}
|
||||
return records[0];
|
||||
};
|
||||
|
||||
Collection.prototype.findAllByAttribute = function(name, value) {
|
||||
var _this = this;
|
||||
return this.model.select(function(rec) {
|
||||
return _this.associated(rec) && rec[name] === value;
|
||||
});
|
||||
};
|
||||
|
||||
Collection.prototype.findByAttribute = function(name, value) {
|
||||
return this.findAllByAttribute(name, value)[0];
|
||||
};
|
||||
|
||||
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 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.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;
|
||||
}
|
||||
}
|
||||
if (!isArray(values)) {
|
||||
values = [values];
|
||||
}
|
||||
for (_k = 0, _len2 = values.length; _k < _len2; _k++) {
|
||||
record = values[_k];
|
||||
record.newRecord = false;
|
||||
record[this.fkey] = this.record.id;
|
||||
}
|
||||
this.model.refresh(values);
|
||||
return this;
|
||||
};
|
||||
|
||||
Collection.prototype.create = function(record, options) {
|
||||
record[this.fkey] = this.record.id;
|
||||
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) {
|
||||
return record[this.fkey] === this.record.id;
|
||||
};
|
||||
|
||||
return Collection;
|
||||
|
||||
})(Spine.Module);
|
||||
|
||||
Instance = (function(_super) {
|
||||
__extends(Instance, _super);
|
||||
|
||||
function Instance(options) {
|
||||
var key, value;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
for (key in options) {
|
||||
value = options[key];
|
||||
this[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
Instance.prototype.exists = function() {
|
||||
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();
|
||||
}
|
||||
this.record[this.fkey] = value && value.id;
|
||||
return this;
|
||||
};
|
||||
|
||||
return Instance;
|
||||
|
||||
})(Spine.Module);
|
||||
|
||||
Singleton = (function(_super) {
|
||||
__extends(Singleton, _super);
|
||||
|
||||
function Singleton(options) {
|
||||
var key, value;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
for (key in options) {
|
||||
value = options[key];
|
||||
this[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
Singleton.prototype.find = function() {
|
||||
return this.record.id && this.model.findByAttribute(this.fkey, this.record.id);
|
||||
};
|
||||
|
||||
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;
|
||||
value.save();
|
||||
return this;
|
||||
};
|
||||
|
||||
return Singleton;
|
||||
|
||||
})(Spine.Module);
|
||||
|
||||
singularize = function(str) {
|
||||
return str.replace(/s$/, '');
|
||||
};
|
||||
|
||||
underscore = function(str) {
|
||||
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) {
|
||||
if (fkey == null) {
|
||||
fkey = "" + (underscore(this.className)) + "_id";
|
||||
}
|
||||
return this.prototype[name] = function(value) {
|
||||
return association(name, model, this, fkey, Collection).refresh(value);
|
||||
};
|
||||
},
|
||||
belongsTo: function(name, model, fkey) {
|
||||
if (fkey == null) {
|
||||
fkey = "" + (underscore(singularize(name))) + "_id";
|
||||
}
|
||||
this.prototype[name] = function(value) {
|
||||
return association(name, model, this, fkey, Instance).update(value).exists();
|
||||
};
|
||||
return this.attributes.push(fkey);
|
||||
},
|
||||
hasOne: function(name, model, fkey) {
|
||||
if (fkey == null) {
|
||||
fkey = "" + (underscore(this.className)) + "_id";
|
||||
}
|
||||
return this.prototype[name] = function(value) {
|
||||
return association(name, model, this, fkey, Singleton).update(value).find();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Spine.Collection = Collection;
|
||||
|
||||
Spine.Singleton = Singleton;
|
||||
|
||||
Spine.Instance = Instance;
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=relation.map
|
||||
*/
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
(function(){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};Spine=this.Spine||require("spine");isArray=Spine.isArray;require=this.require||function(value){return eval(value)};Collection=function(_super){__extends(Collection,_super);function Collection(options){var key,value;if(options==null){options={}}for(key in options){value=options[key];this[key]=value}}Collection.prototype.all=function(){var _this=this;return this.model.select(function(rec){return _this.associated(rec)})};Collection.prototype.first=function(){return this.all()[0]};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});if(!records[0]){throw new Error('"'+this.model.className+'" model could not find a record for the ID "'+id+'"')}return records[0]};Collection.prototype.findAllByAttribute=function(name,value){var _this=this;return this.model.select(function(rec){return _this.associated(rec)&&rec[name]===value})};Collection.prototype.findByAttribute=function(name,value){return this.findAllByAttribute(name,value)[0]};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 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.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}}if(!isArray(values)){values=[values]}for(_k=0,_len2=values.length;_k<_len2;_k++){record=values[_k];record.newRecord=false;record[this.fkey]=this.record.id}this.model.refresh(values);return this};Collection.prototype.create=function(record,options){record[this.fkey]=this.record.id;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){return record[this.fkey]===this.record.id};return Collection}(Spine.Module);Instance=function(_super){__extends(Instance,_super);function Instance(options){var key,value;if(options==null){options={}}for(key in options){value=options[key];this[key]=value}}Instance.prototype.exists=function(){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()}this.record[this.fkey]=value&&value.id;return this};return Instance}(Spine.Module);Singleton=function(_super){__extends(Singleton,_super);function Singleton(options){var key,value;if(options==null){options={}}for(key in options){value=options[key];this[key]=value}}Singleton.prototype.find=function(){return this.record.id&&this.model.findByAttribute(this.fkey,this.record.id)};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;value.save();return this};return Singleton}(Spine.Module);singularize=function(str){return str.replace(/s$/,"")};underscore=function(str){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){if(fkey==null){fkey=""+underscore(this.className)+"_id"}return this.prototype[name]=function(value){return association(name,model,this,fkey,Collection).refresh(value)}},belongsTo:function(name,model,fkey){if(fkey==null){fkey=""+underscore(singularize(name))+"_id"}this.prototype[name]=function(value){return association(name,model,this,fkey,Instance).update(value).exists()};return this.attributes.push(fkey)},hasOne:function(name,model,fkey){if(fkey==null){fkey=""+underscore(this.className)+"_id"}return this.prototype[name]=function(value){return association(name,model,this,fkey,Singleton).update(value).find()}}});Spine.Collection=Collection;Spine.Singleton=Singleton;Spine.Instance=Instance}).call(this);
|
||||
//# sourceMappingURL=relation.min.map
|
||||
File diff suppressed because one or more lines are too long
Executable
+242
@@ -0,0 +1,242 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var $, Spine, escapeRegExp, hashStrip, namedParam, splatParam,
|
||||
__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;
|
||||
|
||||
Spine = this.Spine || require('spine');
|
||||
|
||||
$ = Spine.$;
|
||||
|
||||
hashStrip = /^#*/;
|
||||
|
||||
namedParam = /:([\w\d]+)/g;
|
||||
|
||||
splatParam = /\*([\w\d]+)/g;
|
||||
|
||||
escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g;
|
||||
|
||||
Spine.Route = (function(_super) {
|
||||
var _ref;
|
||||
|
||||
__extends(Route, _super);
|
||||
|
||||
Route.extend(Spine.Events);
|
||||
|
||||
Route.historySupport = ((_ref = window.history) != null ? _ref.pushState : void 0) != null;
|
||||
|
||||
Route.routes = [];
|
||||
|
||||
Route.options = {
|
||||
trigger: true,
|
||||
history: false,
|
||||
shim: false,
|
||||
replace: false,
|
||||
redirect: false
|
||||
};
|
||||
|
||||
Route.add = function(path, callback) {
|
||||
var key, value, _results;
|
||||
if (typeof path === 'object' && !(path instanceof RegExp)) {
|
||||
_results = [];
|
||||
for (key in path) {
|
||||
value = path[key];
|
||||
_results.push(this.add(key, value));
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
return this.routes.push(new this(path, callback));
|
||||
}
|
||||
};
|
||||
|
||||
Route.setup = function(options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
this.options = $.extend({}, this.options, options);
|
||||
if (this.options.history) {
|
||||
this.history = this.historySupport && this.options.history;
|
||||
}
|
||||
if (this.options.shim) {
|
||||
return;
|
||||
}
|
||||
if (this.history) {
|
||||
$(window).bind('popstate', this.change);
|
||||
} else {
|
||||
$(window).bind('hashchange', this.change);
|
||||
}
|
||||
return this.change();
|
||||
};
|
||||
|
||||
Route.unbind = function() {
|
||||
if (this.options.shim) {
|
||||
return;
|
||||
}
|
||||
if (this.history) {
|
||||
return $(window).unbind('popstate', this.change);
|
||||
} else {
|
||||
return $(window).unbind('hashchange', this.change);
|
||||
}
|
||||
};
|
||||
|
||||
Route.navigate = function() {
|
||||
var args, lastArg, options, path, route;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
options = {};
|
||||
lastArg = args[args.length - 1];
|
||||
if (typeof lastArg === 'object') {
|
||||
options = args.pop();
|
||||
} else if (typeof lastArg === 'boolean') {
|
||||
options.trigger = args.pop();
|
||||
}
|
||||
options = $.extend({}, this.options, options);
|
||||
path = args.join('/');
|
||||
if (this.path === path) {
|
||||
return;
|
||||
}
|
||||
this.path = path;
|
||||
this.trigger('navigate', this.path);
|
||||
if (options.trigger) {
|
||||
route = this.matchRoute(this.path, options);
|
||||
}
|
||||
if (options.shim) {
|
||||
return;
|
||||
}
|
||||
if (!route) {
|
||||
if (typeof options.redirect === 'function') {
|
||||
return options.redirect.apply(this, [this.path, options]);
|
||||
} else {
|
||||
if (options.redirect === true) {
|
||||
this.redirect(this.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.history && options.replace) {
|
||||
return history.replaceState({}, document.title, this.path);
|
||||
} else if (this.history) {
|
||||
return history.pushState({}, document.title, this.path);
|
||||
} else {
|
||||
return window.location.hash = this.path;
|
||||
}
|
||||
};
|
||||
|
||||
Route.getPath = function() {
|
||||
var path;
|
||||
if (this.history) {
|
||||
path = window.location.pathname;
|
||||
if (path.substr(0, 1) !== '/') {
|
||||
path = '/' + path;
|
||||
}
|
||||
} else {
|
||||
path = window.location.hash;
|
||||
path = path.replace(hashStrip, '');
|
||||
}
|
||||
return path;
|
||||
};
|
||||
|
||||
Route.getHost = function() {
|
||||
return "" + window.location.protocol + "//" + window.location.host;
|
||||
};
|
||||
|
||||
Route.change = function() {
|
||||
var path;
|
||||
path = this.getPath();
|
||||
if (path === this.path) {
|
||||
return;
|
||||
}
|
||||
this.path = path;
|
||||
return this.matchRoute(this.path);
|
||||
};
|
||||
|
||||
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];
|
||||
if (!(route.match(path, options))) {
|
||||
continue;
|
||||
}
|
||||
this.trigger('change', route, path);
|
||||
return route;
|
||||
}
|
||||
};
|
||||
|
||||
Route.redirect = function(path) {
|
||||
return window.location = path;
|
||||
};
|
||||
|
||||
function Route(path, callback) {
|
||||
var match;
|
||||
this.path = path;
|
||||
this.callback = callback;
|
||||
this.names = [];
|
||||
if (typeof path === 'string') {
|
||||
namedParam.lastIndex = 0;
|
||||
while ((match = namedParam.exec(path)) !== null) {
|
||||
this.names.push(match[1]);
|
||||
}
|
||||
splatParam.lastIndex = 0;
|
||||
while ((match = splatParam.exec(path)) !== null) {
|
||||
this.names.push(match[1]);
|
||||
}
|
||||
path = path.replace(escapeRegExp, '\\$&').replace(namedParam, '([^\/]*)').replace(splatParam, '(.*?)');
|
||||
this.route = new RegExp("^" + path + "$");
|
||||
} else {
|
||||
this.route = path;
|
||||
}
|
||||
}
|
||||
|
||||
Route.prototype.match = function(path, options) {
|
||||
var i, match, param, params, _i, _len;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
match = this.route.exec(path);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
options.match = match;
|
||||
params = match.slice(1);
|
||||
if (this.names.length) {
|
||||
for (i = _i = 0, _len = params.length; _i < _len; i = ++_i) {
|
||||
param = params[i];
|
||||
options[this.names[i]] = param;
|
||||
}
|
||||
}
|
||||
return this.callback.call(null, options) !== false;
|
||||
};
|
||||
|
||||
return Route;
|
||||
|
||||
})(Spine.Module);
|
||||
|
||||
Spine.Route.change = Spine.Route.proxy(Spine.Route.change);
|
||||
|
||||
Spine.Controller.include({
|
||||
route: function(path, callback) {
|
||||
return Spine.Route.add(path, this.proxy(callback));
|
||||
},
|
||||
routes: function(routes) {
|
||||
var key, value, _results;
|
||||
_results = [];
|
||||
for (key in routes) {
|
||||
value = routes[key];
|
||||
_results.push(this.route(key, value));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
navigate: function() {
|
||||
return Spine.Route.navigate.apply(Spine.Route, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = Spine.Route;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=route.map
|
||||
*/
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
(function(){var $,Spine,escapeRegExp,hashStrip,namedParam,splatParam,__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;Spine=this.Spine||require("spine");$=Spine.$;hashStrip=/^#*/;namedParam=/:([\w\d]+)/g;splatParam=/\*([\w\d]+)/g;escapeRegExp=/[-[\]{}()+?.,\\^$|#\s]/g;Spine.Route=function(_super){var _ref;__extends(Route,_super);Route.extend(Spine.Events);Route.historySupport=((_ref=window.history)!=null?_ref.pushState:void 0)!=null;Route.routes=[];Route.options={trigger:true,history:false,shim:false,replace:false,redirect:false};Route.add=function(path,callback){var key,value,_results;if(typeof path==="object"&&!(path instanceof RegExp)){_results=[];for(key in path){value=path[key];_results.push(this.add(key,value))}return _results}else{return this.routes.push(new this(path,callback))}};Route.setup=function(options){if(options==null){options={}}this.options=$.extend({},this.options,options);if(this.options.history){this.history=this.historySupport&&this.options.history}if(this.options.shim){return}if(this.history){$(window).bind("popstate",this.change)}else{$(window).bind("hashchange",this.change)}return this.change()};Route.unbind=function(){if(this.options.shim){return}if(this.history){return $(window).unbind("popstate",this.change)}else{return $(window).unbind("hashchange",this.change)}};Route.navigate=function(){var args,lastArg,options,path,route;args=1<=arguments.length?__slice.call(arguments,0):[];options={};lastArg=args[args.length-1];if(typeof lastArg==="object"){options=args.pop()}else if(typeof lastArg==="boolean"){options.trigger=args.pop()}options=$.extend({},this.options,options);path=args.join("/");if(this.path===path){return}this.path=path;this.trigger("navigate",this.path);if(options.trigger){route=this.matchRoute(this.path,options)}if(options.shim){return}if(!route){if(typeof options.redirect==="function"){return options.redirect.apply(this,[this.path,options])}else{if(options.redirect===true){this.redirect(this.path)}}}if(this.history&&options.replace){return history.replaceState({},document.title,this.path)}else if(this.history){return history.pushState({},document.title,this.path)}else{return window.location.hash=this.path}};Route.getPath=function(){var path;if(this.history){path=window.location.pathname;if(path.substr(0,1)!=="/"){path="/"+path}}else{path=window.location.hash;path=path.replace(hashStrip,"")}return path};Route.getHost=function(){return""+window.location.protocol+"//"+window.location.host};Route.change=function(){var path;path=this.getPath();if(path===this.path){return}this.path=path;return this.matchRoute(this.path)};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];if(!route.match(path,options)){continue}this.trigger("change",route,path);return route}};Route.redirect=function(path){return window.location=path};function Route(path,callback){var match;this.path=path;this.callback=callback;this.names=[];if(typeof path==="string"){namedParam.lastIndex=0;while((match=namedParam.exec(path))!==null){this.names.push(match[1])}splatParam.lastIndex=0;while((match=splatParam.exec(path))!==null){this.names.push(match[1])}path=path.replace(escapeRegExp,"\\$&").replace(namedParam,"([^/]*)").replace(splatParam,"(.*?)");this.route=new RegExp("^"+path+"$")}else{this.route=path}}Route.prototype.match=function(path,options){var i,match,param,params,_i,_len;if(options==null){options={}}match=this.route.exec(path);if(!match){return false}options.match=match;params=match.slice(1);if(this.names.length){for(i=_i=0,_len=params.length;_i<_len;i=++_i){param=params[i];options[this.names[i]]=param}}return this.callback.call(null,options)!==false};return Route}(Spine.Module);Spine.Route.change=Spine.Route.proxy(Spine.Route.change);Spine.Controller.include({route:function(path,callback){return Spine.Route.add(path,this.proxy(callback))},routes:function(routes){var key,value,_results;_results=[];for(key in routes){value=routes[key];_results.push(this.route(key,value))}return _results},navigate:function(){return Spine.Route.navigate.apply(Spine.Route,arguments)}});if(typeof module!=="undefined"&&module!==null){module.exports=Spine.Route}}).call(this);
|
||||
//# sourceMappingURL=route.min.map
|
||||
File diff suppressed because one or more lines are too long
Executable
+1125
File diff suppressed because it is too large
Load Diff
Vendored
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "spinejs",
|
||||
"filename": "spine.min.js",
|
||||
"version": "0.0.4",
|
||||
"filename": "all.min.js",
|
||||
"version": "1.2.0",
|
||||
"description": "Spine is a lightweight framework for building JavaScript web applications",
|
||||
"homepage": "http://maccman.github.com/spine/",
|
||||
"homepage": "http://spinejs.com/",
|
||||
"keywords": [
|
||||
"mvc",
|
||||
"models",
|
||||
@@ -23,7 +23,7 @@
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/maccman/spine"
|
||||
"url": "https://github.com/spine/spine"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user