Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#51 improve index of for new browsers

  • Loading branch information...
commit 275feb204a01f2148e910a04e791082587c0571d 1 parent 6dbd502
@le0pard le0pard authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/routes.js
View
15 lib/routes.js
@@ -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);
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.