From 4b4dc3c0db4109d50b7bca94d0a15b43d4d44fb5 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 2 Nov 2014 00:30:49 -0400 Subject: [PATCH] code review --- src/js/dashboard.js | 3 +-- src/js/info.js | 6 ++---- src/js/settings.js | 8 ++++---- src/js/udom.js | 18 ++++++++---------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/js/dashboard.js b/src/js/dashboard.js index 89c8c6c..b8a4580 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -27,8 +27,7 @@ var loadDashboardPanel = function(hash) { var button = uDom(hash); var url = button.attr('data-dashboard-panel-url'); uDom('iframe').nodeAt(0).src = url; - uDom('.tabButton').toArray().forEach(function(tab){ - var button = uDom(tab); + uDom('.tabButton').forEach(function(button){ button.toggleClass('selected', button.attr('data-dashboard-panel-url') === url); }); } diff --git a/src/js/info.js b/src/js/info.js index 1128bc5..74cb100 100644 --- a/src/js/info.js +++ b/src/js/info.js @@ -314,8 +314,7 @@ function changeFilterHandler() { // Initialize request filters as per user settings: // https://github.com/gorhill/httpswitchboard/issues/49 var statsFilters = cachedUserSettings.statsFilters; - uDom('input[id^="show-"][type="checkbox"]').toArray().forEach(function(elem) { - var input = uDom(elem); + uDom('input[id^="show-"][type="checkbox"]').forEach(function(input) { statsFilters[input.attr('id')] = !!input.prop('checked'); }); changeUserSettings('statsFilters', statsFilters); @@ -396,8 +395,7 @@ uDom.onLoad(function(){ // init ui as per user settings uDom('#max-logged-requests').val(userSettings.maxLoggedRequests); var statsFilters = userSettings.statsFilters; - uDom('input[id^="show-"][type="checkbox"]').toArray().forEach(function(elem) { - var input = uDom(elem); + uDom('input[id^="show-"][type="checkbox"]').forEach(function(input) { var filter = statsFilters[input.attr('id')]; input.prop('checked', filter === undefined || filter === true); }); diff --git a/src/js/settings.js b/src/js/settings.js index 5cc9735..530dc99 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -109,12 +109,12 @@ uDom.onLoad(function() { // `data-range` allows to add/remove bool properties without // changing code. - uDom('input[data-range="bool"]').toArray().forEach(function(elem) { - elem.checked = userSettings[elem.id] === true; + uDom('input[data-range="bool"]').forEach(function(elem) { + elem.prop('checked', userSettings[elem.attr('id')] === true); }); - uDom('input[name="displayTextSize"]').toArray().forEach(function(elem) { - elem.checked = elem.value === userSettings.displayTextSize; + uDom('input[name="displayTextSize"]').forEach(function(elem) { + elem.prop('checked', elem.val() === userSettings.displayTextSize); }); uDom('#smart-auto-reload').val(userSettings.smartAutoReload); uDom('#subframe-color').val(userSettings.subframeColor); diff --git a/src/js/udom.js b/src/js/udom.js index d7bda72..2391260 100644 --- a/src/js/udom.js +++ b/src/js/udom.js @@ -228,6 +228,14 @@ DOMList.prototype.toArray = function() { /******************************************************************************/ +DOMList.prototype.forEach = function(fn) { + for ( var i = 0; i < this.nodes.length; i++ ) { + fn(this.at(i), i); + } +}; + +/******************************************************************************/ + DOMList.prototype.subset = function(i, l) { var r = new DOMList(); var n = l !== undefined ? l : this.nodes.length; @@ -355,16 +363,6 @@ DOMList.prototype.contents = function() { /******************************************************************************/ -DOMList.prototype.forEach = function(callback) { - var n = this.nodes.length; - for ( var i = 0; i < n; i++ ) { - callback.bind(this.nodes[i]).call(); - } - return this; -}; - -/******************************************************************************/ - DOMList.prototype.remove = function() { var cn, p; var i = this.nodes.length;