Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Last active November 5, 2017 00:07
Show Gist options
  • Save nhunzaker/9676031 to your computer and use it in GitHub Desktop.
Save nhunzaker/9676031 to your computer and use it in GitHub Desktop.
var _ = require('underscore');
var Backbone = require('backbone');
var cheerio = require('cheerio');
var request = require('request');
Backbone.ajax = function(options) {
options.json = true;
return request(options, function(error, result) {
if (error) {
if (_.has(options, 'failure')) options.failure(error);
} else {
(if (_.has(options, 'success')) options.success(result.body);
}
});
};
Backbone.View.prototype.setElement = function($cheerio) {
this.$el = $cheerio("*");
return this;
},
Backbone.View.prototype._createElement = function(tagName) {
return cheerio.load('<' + tagName + '>');
}
@nhunzaker
Copy link
Author

I wish gists sent out notifications about comments! I should have updated this, given I was the one that sent out the PR...

@akre54
Copy link

akre54 commented Apr 27, 2014

Good stuff :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment