-
Notifications
You must be signed in to change notification settings - Fork 4
/
backbone.jfeed.js
33 lines (30 loc) · 1.02 KB
/
backbone.jfeed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Created by Kendall Buchanan, (https://github.com/kendagriff)
// MIT licence
// Version 0.0.1
(function() {
// Wrap an optional error callback with a fallback error event.
var wrapError = function(onError, model, options) {
return function(resp) {
if (onError) {
onError(model, resp, options);
} else {
model.trigger('error', model, resp, options);
}
};
};
Backbone.JFeed = {};
Backbone.JFeed.Collection = Backbone.Collection.extend({
fetch: function(options) {
if (!this.feedUrl) throw new Error('A "feedUrl" property must be specified');
options || (options = {});
var collection = this;
var success = options.success;
options.success = function(resp, status, xhr) {
collection.reset(collection.parse(resp.items, xhr), options)
if (success) success(collection, resp);
};
options.error = wrapError(options.error, collection, options);
return $.getFeed(_.extend({ url: this.feedUrl }, options))
}
});
}).call(this);