Created
January 30, 2013 02:57
-
-
Save balanceiskey/4670217 to your computer and use it in GitHub Desktop.
An example of how to get Backbone Models and Collections working in a firefox extension.
This file contains 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 Request = require('request').Request, | |
_ = require('./underscore'), | |
Backbone = require('./backbone'), | |
// Firefox Add-Ons cannot use jQuery in the background | |
// script, but there are instances where we need some | |
// jquery functionality, paricularly $.ajax, which | |
// is defined later. | |
$ = { | |
ajax: function (params) { | |
if (!params.url){ | |
console.error('ajax request made without url'); | |
return false; | |
} | |
var util = this; | |
params.onComplete = function (response) { | |
// WARNING: response is read-only. | |
if (response.status === 200){ | |
params.success && | |
params.success(response.text, response.status, response); | |
}else{ | |
console.error('ajax request failed'); | |
params.error && | |
params.error({ | |
responseText: response.text, | |
status: response.status | |
}); | |
} | |
}; | |
Request(params).get(); | |
} | |
}; | |
// use our pseudo-jQuery instead | |
Backbone.setDomLibrary($); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment