From f3ac8e2f5d93ce51a83714961ae97b218aad8420 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 13 Nov 2015 11:42:43 -0800 Subject: [PATCH] jquery.dashboard.js - Fix bad variable scoping (Possible behavioral change) These snippets were declaring new variables (eg `if (...) var ids = foo`) in one scope then accessing them in a later scope - which properly triggers a warning from jshint. In my mind, this would be a nullop (always leaving `ids` undefined), although JS does allow values to leak through. I *suspect* this leaking was *partially* intentional. The variable (`ids` or `id`) is clearly intended to be used a few lines later. However, in the case where the conditional is *false*, the content of `ids` or `id` is unclear. You might expect it to be `undefined` (and it probably would be in the first few loop-iterations), but eventually you'd would start leaking values across iterations, and that doesn't seem normal/intentional. --- js/jquery/jquery.dashboard.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/jquery/jquery.dashboard.js b/js/jquery/jquery.dashboard.js index e2c2c71014..489345b89c 100644 --- a/js/jquery/jquery.dashboard.js +++ b/js/jquery/jquery.dashboard.js @@ -81,12 +81,12 @@ for (var c2 in dashboard.columns) { // IDs of the sortable elements in this column. - if( typeof dashboard.columns[c2] == 'object' ) var ids = dashboard.columns[c2].element.sortable('toArray'); + var ids = (typeof dashboard.columns[c2] == 'object') ? dashboard.columns[c2].element.sortable('toArray') : undefined; // For each id... for (var w in ids) { // Chop 'widget-' off of the front so that we have the real widget id. - if( typeof ids[w] == 'string' ) var id = ids[w].substring('widget-'.length); + var id = (typeof ids[w] == 'string') ? ids[w].substring('widget-'.length) : undefined; // Add one flat property to the params object that will look like an array element to the PHP server. // Unfortunately jQuery doesn't do this for us. -- 2.25.1