]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Fixed broken regex from previous commit 5307/head
authorJoe Workman <joe@workmanmail.com>
Tue, 10 Jun 2014 19:54:39 +0000 (12:54 -0700)
committerJoe Workman <joe@workmanmail.com>
Tue, 10 Jun 2014 19:54:39 +0000 (12:54 -0700)
There was a previous commit that broke many existing interchange instances because it was trying to add the ability to support commas inside the url path. In order to support backwards compatibility and this new edge case, more logic needed to be added. This should work in all cases now.

I also made sure that I left support in for defining new directives outside of the default 'replace'

js/foundation/foundation.interchange.js

index 08aa3d6fcdc1da12bf579899a890d9d2c812fc5a..673c590214d211f11e047b7eca8c6da17276fec5 100644 (file)
       return $(window).trigger('resize');
     },
 
-    parse_params : function (path, directive, mq) {
-      return [this.trim(path), this.convert_directive(directive), this.trim(mq)];
-    },
-
     convert_directive : function (directive) {
 
       var trimmed = this.trim(directive);
       return 'replace';
     },
 
+    parse_scenario : function (scenario) {
+      // This logic had to be made more complex since some users were using commas in the url path
+      // So we cannot simply just split on a comma
+      var directive_match = scenario[0].match(/(.+),\s*(\w+)\s*$/),
+      media_query         = scenario[1];
+
+      if (directive_match) {
+        var path  = directive_match[1],
+        directive = directive_match[2];
+      }
+      else {
+        var cached_split = scenario[0].split(/,\s*$/),
+        path             = cached_split[0],
+        directive        = '';               
+      }
+
+      return [this.trim(path), this.convert_directive(directive), this.trim(media_query)];
+    },
+
     object : function(el) {
       var raw_arr = this.parse_data_attr(el),
           scenarios = [], 
           var split = raw_arr[i].split(/\((.*?)(\))$/);
 
           if (split.length > 1) {
-            var cached_split = split[0].split(/\, /),
-                params = this.parse_params(cached_split[0],
-                  cached_split[1], split[1]);
-
+            var params = this.parse_scenario(split);
             scenarios.push(params);
           }
         }