vendor/assets/javascripts/djr.js in djr-0.1.0 vs vendor/assets/javascripts/djr.js in djr-0.2.0
- old
+ new
@@ -20,13 +20,13 @@
this.data = data;
};
this.errorDefault = function(error) {
this.error = error;
};
- this.ajax = function(object, callback, error, method, url, params) {
+ this.ajax = function(object, callback, error, method, url, scope) {
var self = this;
- var params = params || [];
+ var params = [];
params["\(.:format\)"] = this.format;
if(method === "")
method = "GET";
@@ -39,11 +39,11 @@
object = null;
}
if(method === "DELETE") object = null;
jQuery.ajax({
- context : self,
+ context : scope || self,
data : object,
cache : false,
dataType : 'json',
error : error,
success : callback,
@@ -53,11 +53,11 @@
url : this.formatURL(url, params) + "?authenticity_token=" + $("meta[name='csrf-token']").attr("content")
});
};
for (var action in this.routes) {
this[action] = function(act) {
- return function(object, callback, error) {
+ return function(object, callback, error, scope) {
if(typeof object === "function") {
callback = object;
error = callback;
object = {};
}
@@ -65,10 +65,11 @@
var localErrorHandler = error || this.errorDefault;
this.ajax(object,
localCallback,
localErrorHandler,
this.routes[act].method,
- this.routes[act].url);
+ this.routes[act].url,
+ scope);
return this;
}
}(action);
}
\ No newline at end of file