From 9291ff76d0708bdeb38703119e34f806332aa0e2 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Tue, 10 Jun 2014 12:54:39 -0700 Subject: [PATCH] Fixed broken regex from previous commit 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 | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/js/foundation/foundation.interchange.js b/js/foundation/foundation.interchange.js index 08aa3d6fc..673c59021 100644 --- a/js/foundation/foundation.interchange.js +++ b/js/foundation/foundation.interchange.js @@ -235,10 +235,6 @@ 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); @@ -250,6 +246,25 @@ 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 = [], @@ -260,10 +275,7 @@ 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); } } -- 2.47.2