public
Created

An example of how to get Backbone Models and Collections working in a firefox extension.

  • Download Gist
ffextension.js
JavaScript
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 34 35 36
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($);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.