Skip to content

Commit

Permalink
#51 improve index of for new browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Jul 1, 2012
1 parent 6dbd502 commit 275feb2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/routes.js
Expand Up @@ -96,6 +96,12 @@
return result;
},

smartIndexOf: function(array, item){
if (Array.prototype.indexOf && array.indexOf === Array.prototype.indexOf) return array.indexOf(item);
for (var i = 0; i < array.length; i++) if (i in array && array[i] === item) return i;
return -1;
},

build_path: function(required_parameters, optional_parts, route, args) {
args = Array.prototype.slice.call(args);
var opts = this.extract_options(required_parameters.length, args);
Expand All @@ -104,12 +110,9 @@
}

parameters = this.prepare_parameters(required_parameters, args, opts);
// Array#indexOf is not supported by IE <= 8
for(var i = 0; i < optional_parts.length; i++) {
if (optional_parts[i] == "format") {
this.set_default_format(parameters);
break;
}
// Array#indexOf is not supported by IE <= 8, so we use custom method
if (Utils.smartIndexOf(optional_parts, 'format') !== -1) {
this.set_default_format(parameters);
}
var result = Utils.get_prefix();
var anchor = Utils.extract_anchor(parameters);
Expand Down

0 comments on commit 275feb2

Please sign in to comment.