Last active
August 29, 2015 13:57
-
-
Save nhunzaker/9676446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = require('./config'); | |
var _ = require('underscore'); | |
var url = require('url'); | |
require('backbone').ajax = function(options) { | |
var deferred = require('q').defer(); | |
_.extend(options, { | |
json : true, | |
url : url.resolve(config.API_URL, options.url) | |
}); | |
require('request')(options, function(error, result) { | |
if (error) { | |
if (_.has(options, 'failure')) options.failure(error); | |
deferred.reject(new Error(error)); | |
} else { | |
if (_.has(options, 'success'))options.success(result.body); | |
deferred.resolve(result.body, result); | |
} | |
}); | |
return deferred.promise; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var backbone = require('backbone'); | |
var cheerio = require('cheerio'); | |
Backbone.View.prototype.setElement = function($cheerio) { | |
this._$ = $cheerio; | |
this.$el = $cheerio("*"); | |
return this; | |
}, | |
Backbone.View.prototype._createElement = function(tagName) { | |
return cheerio.load('<' + tagName + '>'); | |
}; | |
Backbone.View.prototype.toHTML = function() { | |
return this._$.html(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment