Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(function() {
var Mixins = {
sync: function(method, model, options) {
console.debug('Backbone.sync("%s", %o, %o);',method, model, options);
console.debug('this:%o',this);
$.ajax({
type: 'POST',
headers: {
"Accept": "*/*",
"X-Ajax-Synchronization-Token": this.area.ajax_synchronization_token,
"X-Authorization": "Basic " + this.area.jsproxy
},
url: '/proxy?apikey=' + this.user.key + '&sig=' + this.user.signature,
data: JSON.stringify({
method: model.method,
id: 1,
params: model.params
}),
dataType: "json",
success: options.success,
error: options.error
});
}
};
var MyLibrary = Backbone.Model.extend({
url: '/data/config.js',
initialize: function(config) {
this.session = new Session();
this.trigger("loaded");
}
});
var Session = Backbone.Model.extend({
frequency: 60, // in seconds
method: "area.fetch",
params: [],
initialize: function() {
this.start();
},
start: function() {
this.monitor = setInterval(this.fetch({
success: function(session, response) {
console.debug("response: %o",response);
},
error: function(session, response) {
console.debug("response: %o",response);
}
}),this.frequency*1000);
},
sync: function(method, model, options) {
Mixins.sync(method, model, options);
}
});
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
// Save the previous value of the `MyLibrary` variable.
var previousMyLibrary = root.MyLibrary;
// Export the MyLibrary object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `MyLibrary` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = MyLibrary;
}
exports.MyLibrary = MyLibrary;
} else {
root['MyLibrary'] = MyLibrary;
}
// Run MyLibrary.js in *noConflict* mode, returning the `MyLibrary` variable to its
// previous owner. Returns a reference to the Underscore object.
MyLibrary.noConflict = function() {
root.MyLibrary = previousMyLibrary;
return this;
};
}).call(this);
window.mylibrary = new MyLibrary({
"area": {
"ajax_synchronization_token": "sometoken",
"jsproxy": "proxytoken"
},
"user": {
"key": "somekey",
"signature": "somesignature"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.