Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

#51 improve index of for new browsers

  • Loading branch information...
commit 275feb204a01f2148e910a04e791082587c0571d 1 parent 6dbd502
Alexey Vasiliev authored July 01, 2012

Showing 1 changed file with 9 additions and 6 deletions. Show diff stats Hide diff stats

  1. 15  lib/routes.js
15  lib/routes.js
@@ -96,6 +96,12 @@
96 96
       return result;
97 97
     },
98 98
 
  99
+    smartIndexOf: function(array, item){
  100
+      if (Array.prototype.indexOf && array.indexOf === Array.prototype.indexOf) return array.indexOf(item);
  101
+      for (var i = 0; i < array.length; i++) if (i in array && array[i] === item) return i;
  102
+      return -1;
  103
+    },
  104
+
99 105
     build_path: function(required_parameters, optional_parts, route, args) {
100 106
       args = Array.prototype.slice.call(args);
101 107
       var opts = this.extract_options(required_parameters.length, args);
@@ -104,12 +110,9 @@
104 110
       }
105 111
 
106 112
       parameters = this.prepare_parameters(required_parameters, args, opts);
107  
-      // Array#indexOf is not supported by IE <= 8
108  
-      for(var i = 0; i < optional_parts.length; i++) {
109  
-        if (optional_parts[i] == "format") {
110  
-          this.set_default_format(parameters);
111  
-          break;
112  
-        }
  113
+      // Array#indexOf is not supported by IE <= 8, so we use custom method
  114
+      if (Utils.smartIndexOf(optional_parts, 'format') !== -1) {
  115
+        this.set_default_format(parameters);
113 116
       }
114 117
       var result = Utils.get_prefix();
115 118
       var anchor = Utils.extract_anchor(parameters);

0 notes on commit 275feb2

Please sign in to comment.
Something went wrong with that request. Please try again.