Skip to content
This repository has been archived by the owner on May 22, 2018. It is now read-only.

Commit

Permalink
Removed complicated regexp determining whether the resource should be…
Browse files Browse the repository at this point in the history
… treated as remote.

git-svn-id: https://svn.thoughtbot.com/jester/trunk@105 d7758119-aa2c-0410-afcd-b700fbd0d0b3
  • Loading branch information
emill committed Jul 24, 2007
1 parent 5c2610a commit b1d0e0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
26 changes: 11 additions & 15 deletions jester.js
Expand Up @@ -12,7 +12,6 @@
*/
Jester = {}
Jester.Resource = function(){};
Jester.Resources = [];

// Doing it this way forces the validation of the syntax but gives flexibility enough to rename the new class.
Jester.Constructor = function(model){
Expand Down Expand Up @@ -41,34 +40,32 @@ Object.extend(Jester.Resource, {
}
if (!options) options = {};

var default_prefix = "http://" + window.location.hostname + (window.location.port ? ":" + window.location.port : "")
var default_options = {
format: "xml",
singular: model.underscore(),
name: model,
prefix: default_prefix
}
options = Object.extend(default_options, options);
options.format = options.format.toLowerCase();
options.plural = options.singular.pluralize(options.plural);
options.singular_xml = options.singular.replace(/_/g, "-");
options.plural_xml = options.plural.replace(/_/g, "-");
options.remote = false;
options.remote = false;

// Establish prefix
if (!options.prefix.match(/^https?:/)) {
var default_prefix = "http://" + window.location.hostname + (window.location.port ? ":" + window.location.port : "")
if (options.prefix && options.prefix.match(/^https?:/))
options.remote = true;

if (!options.prefix)
options.prefix = default_prefix;

if (!options.prefix.match(/^https?:/))
options.prefix = default_prefix + (options.prefix.match(/^\//) ? "" : "/") + options.prefix;
}
options.prefix = options.prefix.replace(/\b\/+$/,"");

var m = null;
if(m = options.prefix.match(/(https?:)\/\/([\w\.]+)(?::(\d+))?/))
{
options.remote = !(m[1] == window.location.protocol && m[2] == window.location.hostname &&
((typeof(m[3]) == "undefined" && window.location.port == "")
|| m[3] == window.location.port));
}

// Assign options to model
new_model.name = model;
new_model.options = options;
for(var opt in options)
Expand All @@ -77,7 +74,6 @@ Object.extend(Jester.Resource, {
if(options.checkNew)
this.buildAttributes(new_model, options.asynchronous);

Jester.Resources.push(new_model)
return new_model;
},

Expand Down
3 changes: 2 additions & 1 deletion test/jester_test.html
Expand Up @@ -150,7 +150,8 @@
user_callback(result);
}
}
return eval(Internet[url]);
eval('var result = ' + Internet[url]);
return result;
}

var result = Internet[url];
Expand Down

0 comments on commit b1d0e0b

Please sign in to comment.