From f0608f6fedff4139d17e0121b133e144573d49f8 Mon Sep 17 00:00:00 2001 From: htulipe Date: Tue, 27 Jan 2015 21:52:38 +0100 Subject: [PATCH] Allow other params than 'mode' in example query string. Currently, if other params are present at the beginning of the query string, the mode switcher will not work. This situation can occur when a search criteria was entered in the examples index page. That criteria will be passed along to the example page via a query param. --- resources/example-behaviour.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/example-behaviour.js b/resources/example-behaviour.js index 2d54501427..161f51d790 100644 --- a/resources/example-behaviour.js +++ b/resources/example-behaviour.js @@ -29,11 +29,13 @@ pairs = [], i, pair, - adjusted; + adjusted, + modeFound = false; for (i = chunks.length - 1; i >= 0; --i) { pair = chunks[i].split('='); if (pair[0].toLowerCase() === 'mode') { pair[1] = newMode; + modeFound = true; } adjusted = encodeURIComponent(pair[0]); if (typeof pair[1] !== undefined) { @@ -41,8 +43,8 @@ } pairs.push(adjusted); } - if (pairs.length === 0) { - pairs[0] = 'mode=' + encodeURIComponent(newMode); + if (!modeFound) { + pairs.push('mode=' + encodeURIComponent(newMode)); } location.href = baseUrl + '?' + pairs.join('&'); };