Permalink
Browse files

Fixes for Safari and IE6. Thanks to Changshin Lee and Nat Budin for t…

…heir patches. This is a combination of their work.

git-svn-id: https://svn.thoughtbot.com/jester/trunk@120 d7758119-aa2c-0410-afcd-b700fbd0d0b3
  • Loading branch information...
1 parent 6a5fa8d commit 1c68b28d7894e806a18695e0434ea60baf38343e emill committed Jan 10, 2008
Showing with 23 additions and 23 deletions.
  1. +18 −18 jester.js
  2. +5 −5 test/jester_test.html
View
36 jester.js
@@ -13,10 +13,10 @@ Jester.Resource = function(){};
// Doing it this way forces the validation of the syntax but gives flexibility enough to rename the new class.
Jester.Constructor = function(model){
return (function CONSTRUCTOR() {
- this.class = CONSTRUCTOR;
+ this.klass = CONSTRUCTOR;
this.initialize.apply(this, arguments);
this.after_initialization.apply(this, arguments);
- }).toSource().replace(/CONSTRUCTOR/g, model);
+ }).toString().replace(/CONSTRUCTOR/g, model);
}
// universal Jester callback holder for remote JSON loading
@@ -40,7 +40,7 @@ Object.extend(Jester.Resource, {
var default_options = {
format: "xml",
singular: model.underscore(),
- name: model,
+ name: model
}
options = Object.extend(default_options, options);
options.format = options.format.toLowerCase();
@@ -282,9 +282,9 @@ Object.extend(Jester.Resource, {
_default_urls : function(options) {
urls = {
- show : "/" + options.plural + "/:id." + options.format,
- list : "/" + options.plural + "." + options.format,
- new : "/" + options.plural + "/new." + options.format
+ 'show' : "/" + options.plural + "/:id." + options.format,
+ 'list' : "/" + options.plural + "." + options.format,
+ 'new' : "/" + options.plural + "/new." + options.format
}
urls.create = urls.list;
urls.destroy = urls.update = urls.show;
@@ -441,14 +441,14 @@ Object.extend(Jester.Resource.prototype, {
this._properties = [];
this._associations = [];
- this.setAttributes(this.class._attributes || {});
+ this.setAttributes(this.klass._attributes || {});
this.setAttributes(attributes);
// Initialize with no errors
this.errors = [];
// Establish custom URL helpers
- for (var url in this.class._urls)
+ for (var url in this.klass._urls)
eval('this._' + url + '_url = function(params) {return this._url_for("' + url + '", params);}');
},
after_initialization: function(){},
@@ -468,9 +468,9 @@ Object.extend(Jester.Resource.prototype, {
if (this.id) {
if (callback)
- return this.class.find(this.id, {}, reloadWork);
+ return this.klass.find(this.id, {}, reloadWork);
else
- return reloadWork(this.class.find(this.id));
+ return reloadWork(this.klass.find(this.id));
}
else
return this;
@@ -496,7 +496,7 @@ Object.extend(Jester.Resource.prototype, {
return false;
});
- return this.class.request(destroyWork, this._destroy_url(), {method: "delete"}, callback);
+ return this.klass.request(destroyWork, this._destroy_url(), {method: "delete"}, callback);
},
save : function(callback) {
@@ -514,8 +514,8 @@ Object.extend(Jester.Resource.prototype, {
}
else {
var doc = Jester.Tree.parseXML(transport.responseText);
- if (doc[this.class._singular_xml])
- attributes = this._attributesFromTree(doc[this.class._singular_xml]);
+ if (doc[this.klass._singular_xml])
+ attributes = this._attributesFromTree(doc[this.klass._singular_xml]);
}
if (attributes)
this._resetAttributes(attributes);
@@ -554,11 +554,11 @@ Object.extend(Jester.Resource.prototype, {
// collect params
var params = {};
(this._properties).each( bind(this, function(value, i) {
- params[this.class._singular + "[" + value + "]"] = this[value];
+ params[this.klass._singular + "[" + value + "]"] = this[value];
}));
// send the request
- return this.class.request(saveWork, url, {parameters: params, method: method}, callback);
+ return this.klass.request(saveWork, url, {parameters: params, method: method}, callback);
},
setAttributes : function(attributes)
@@ -591,12 +591,12 @@ Object.extend(Jester.Resource.prototype, {
_attributesFromJSON: function()
{
- return this.class._attributesFromJSON.apply(this.class, arguments);
+ return this.klass._attributesFromJSON.apply(this.klass, arguments);
},
_attributesFromTree: function()
{
- return this.class._attributesFromTree.apply(this.class, arguments);
+ return this.klass._attributesFromTree.apply(this.klass, arguments);
},
_errorsFrom : function(raw) {
@@ -709,7 +709,7 @@ Object.extend(Jester.Resource.prototype, {
if (typeof(params) == "object" && !params.id)
params.id = this.id;
- return this.class._url_for(action, params);
+ return this.klass._url_for(action, params);
}
});
View
10 test/jester_test.html
@@ -353,7 +353,7 @@
var eric = User.find(1);
assertEquals(1, eric._associations.length);
assertEquals("posts", eric._associations[0]);
- assertEquals(Post, eric.posts[0].class);
+ assertEquals(Post, eric.posts[0].klass);
assertEquals(2, eric.posts.length);
var john = User.find(2);
@@ -364,7 +364,7 @@
Post = undefined;
var eric = User.find(1);
assertEquals("posts", eric._associations[0]);
- assertEquals(Post, eric.posts[0].class);
+ assertEquals(Post, eric.posts[0].klass);
assertEquals("Auto-generated Post class should have same values as the original one.", original_url, Post._show_url());
assertEquals("post", Post._singular);
assertEquals(User._format, Post._format);
@@ -376,14 +376,14 @@
var post = Post.find(1);
assertEquals(1, post._associations.length);
assertEquals("user", post._associations[0]);
- assertEquals(User, post.user.class)
+ assertEquals(User, post.user.klass)
// auto-model belongs_to/has_one
var original_url = User._show_url();
User = undefined;
var post = Post.find(1);
assertEquals("user", post._associations[0]);
- assertEquals(User, post.user.class);
+ assertEquals(User, post.user.klass);
assertEquals(original_url, User._show_url());
assertEquals("user", User._singular);
assertEquals(Post._format, User._format);
@@ -543,7 +543,7 @@
function testBuild() {
// test without checking new.xml
var eric = User.build();
- assertEquals(User, eric.class);
+ assertEquals(User, eric.klass);
assertEquals(0, eric._properties.length);
// test with checking new.xml

0 comments on commit 1c68b28

Please sign in to comment.