Skip to content

Commit

Permalink
Fixed a buildParams bug for multiple parameters; storing the params i…
Browse files Browse the repository at this point in the history
…n the object so extra params like a search query can be saved; added class methods finally.
  • Loading branch information
agibralter committed Nov 11, 2008
1 parent ca9cb69 commit 4e9f80c
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pester.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
case 'integer':
val = $(tag).text() ? parseInt($(tag).text(), 10) : null;
break;
case 'float':
val = $(tag).text() ? parseFloat($(tag).text(), 10) : null;
break;
case 'boolean':
val = $(tag).text() ? true : false;
val = $(tag).text() == 'true' ? true : false;
break;
default:
val = $(tag).text();
Expand All @@ -40,7 +43,7 @@
var buildParams = function (params_obj) {
var params = '';
$.each(params_obj, function (key, val) {
params += encodeURI(key) + '=' + encodeURI(val);
params += '&' + encodeURI(key) + '=' + encodeURI(val);
});
return params;
};
Expand Down Expand Up @@ -112,6 +115,9 @@
var name = instance.class_obj.resource_name_xml;
if ($(name, data).size() == 1) {
instance.parse_xml($(name, data));
if (params_obj) {
instance.params_obj = params_obj;
}
}
// cache object
// TODO limit size of cache?
Expand All @@ -128,6 +134,24 @@
}
},
instance: {
merge_params: function (new_params_obj) {
var res_params = {};
if (this.params_obj) {
$.each(this.params_obj, function (key, val) {
if (new_params_obj[key]) {
res_params[key] = new_params_obj[key];
} else {
res_params[key] = val;
}
});
}
$.each(new_params_obj, function (key, val) {
if (!res_params[key]) {
res_params[key] = val;
}
});
return res_params;
},
parse_xml: function (xml) {
var $this = this;

Expand Down Expand Up @@ -216,6 +240,13 @@
return method.apply(Class, arguments);
};
});
if (obj && obj['class_methods']) {
$.each(obj['class_methods'], function (name, method) {
Class[name] = function () {
return method.apply(Class, arguments);
};
});
}

jQueryExtObj[name] = Class;

Expand Down

0 comments on commit 4e9f80c

Please sign in to comment.