From a93fc61f32650db0897bf19dc28e661571aaeab4 Mon Sep 17 00:00:00 2001 From: techninja Date: Fri, 24 Jun 2016 14:29:35 -0700 Subject: [PATCH 01/16] Linting.... :shirt: --- resources/scripts/main.settings.js | 65 +++++++++++++++++------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/resources/scripts/main.settings.js b/resources/scripts/main.settings.js index 7f73aa6..36a870a 100644 --- a/resources/scripts/main.settings.js +++ b/resources/scripts/main.settings.js @@ -1,8 +1,13 @@ /* * @file Holds all RoboPaint GLOBAL settings specific configuration, binding and * handler code. If a new setting wants to show up in the application, in needs - * to have its markup added in main.settings.inc.html. This may all eventually move - * to a more centralized singluar configuration file ... but not yet. ;) + * to have its markup added in main.settings.inc.html. This may all eventually + * move to a more centralized singluar configuration file ... but not yet. ;) + */ + +// TODO: Limit the number of random globals going on here. :P +/* globals window, cncserver, robopaint, localStorage, $, initializing, +setModal, rpRequire, paper, homeVis, mainWindow, appMode, $subwindow, isModal, */ /** @@ -82,11 +87,11 @@ function loadSettings() { // Allow machine specific overrides of initial default settings settingsDefaultAlter(robopaint.settings); - // Are there existing settings from a previous run? Mesh them into the defaults + // Are there existing settings from a previous run? Mesh into the defaults. if (localStorage[robopaint.utils.settingsStorageKey()]) { var s = robopaint.utils.getSettings(); for (var key in robopaint.settings) { - if (typeof s[key] != 'undefined' && s[key] !== null) { + if (typeof s[key] !== 'undefined' && s[key] !== null) { robopaint.settings[key] = s[key]; } } @@ -104,7 +109,7 @@ function loadSettings() { } break; default: - if ($input.attr('type') == 'checkbox') { + if ($input.attr('type') === 'checkbox') { $input.prop('checked', robopaint.settings[key]); } else { $input.val(robopaint.settings[key]); @@ -163,7 +168,7 @@ $(robopaint).on('settingsComplete', function(){ addSettingsRangeValues(); // Add in the range value displays // Clear last used image - if (robopaint.settings.openlast == 0) delete localStorage["svgedit-default"]; + if (robopaint.settings.openlast === 0) delete localStorage["svgedit-default"]; }); /** @@ -242,11 +247,12 @@ function bindSettingsControls() { var $input = $(this); var pushKey = []; var pushVal = ''; + var name = ''; // Do this first as switch case can't use indexOf // Update available modes if (this.id.indexOf('modeenable') !== -1) { - var name = this.id.replace('modeenable', ''); + name = this.id.replace('modeenable', ''); var enabled = $input.is(':checked'); robopaint.settings.enabledmodes[name] = enabled; $('#bar-' + name).toggleClass('hidden', !enabled); @@ -271,19 +277,22 @@ function bindSettingsControls() { case 'servoup': case 'servopaint': case 'servowash': - var name = this.id.substr(5); + name = this.id.substr(5); // Shim to translate robopaint name to cncserver name - if (name == "paint") name = 'draw'; + if (name === "paint") name = 'draw'; // Save settings - cncserver.conf.bot.set('servo:presets:' + name, parseFloat($input.val()/10)); + cncserver.conf.bot.set( + 'servo:presets:' + name, parseFloat($input.val()/10) + ); // On input with nothing in the buffer allow active change of the bot. // On "change" of sliders, the user has finished sliding, we can reset // the height back to UP. Allows changing while paused. var state = robopaint.cncserver.state; - if (!initializing && (state.bufferList.length === 0 || state.process.paused)) { + if (!initializing && + (state.bufferList.length === 0 || state.process.paused)) { if (e.type === 'change') { cncserver.setHeight('up', null, state.process.paused); } else { @@ -340,27 +349,27 @@ function bindSettingsControls() { // No paint? toggleDisableSetting( '#showcolortext, #colorset', - ($input.val() == 2 || $input.val() == 0), + ($input.val() === 2 || $input.val() === 0), robopaint.t('settings.output.penmode.warningPaint') ); // No nothing! toggleDisableSetting( '#maxpaintdistance, #refillmode, #refillaction, #maxpaint', - $input.val() != 3, + $input.val() !== 3, robopaint.t('settings.output.penmode.warningAll') ); robopaint.settings[this.id] = $input.val(); break; case 'bottype': // Bot type change! Not a real setting - localStorage["currentBot"] = JSON.stringify({ + localStorage.currentBot = JSON.stringify({ type: $input.val(), name: $('#bottype option:selected').text() }); return; default: // Nothing special to set, just change the settings object value - if ($input.attr('type') == 'checkbox') { + if ($input.attr('type') === 'checkbox') { robopaint.settings[this.id] = $input.is(':checked'); } else { robopaint.settings[this.id] = $input.val(); @@ -368,26 +377,26 @@ function bindSettingsControls() { } // Enable only for debug windows (users can close them by hand). - if (this.id == 'rpdebug' && $input.is(':checked')) { + if (this.id === 'rpdebug' && $input.is(':checked')) { mainWindow.openDevTools(); if (appMode !== 'home') $subwindow[0].openDevTools(); } // Update paint sets when changes made that would effect them - if (this.id == 'colorset' || this.id == 'showcolortext') { + if (this.id === 'colorset' || this.id === 'showcolortext') { updateColorSetSettings(); cncserver.pushToMode('updateMediaSet'); } // Update visibility of paintsets on penmode change - if (this.id == 'penmode') { + if (this.id === 'penmode') { cncserver.pushToMode('updatePenMode'); } // If there's a key to override for CNC server, set it if (pushKey.length) { robopaint.settings[this.id] = pushVal; - if (pushKey[0] == 'b') { // Bot! + if (pushKey[0] === 'b') { // Bot! cncserver.conf.bot.set(pushKey[1], pushVal); } else { // Global conf cncserver.conf.global.set(pushKey[1], pushVal); @@ -401,21 +410,21 @@ function bindSettingsControls() { }); // Done Button - $('#settings-done').click(function(e) { + $('#settings-done').click(function() { setSettingsWindow(false); }); // Keyboard shortcut for exiting settings $(window).keydown(function (e){ if (isModal && $('#settings').is(':visible')) { - if (e.keyCode == 27) { + if (e.keyCode === 27) { $('#settings-done').click(); } } }); // Reset button - $('#settings-reset').click(function(e) { + $('#settings-reset').click(function() { if (confirm(robopaint.t('settings.buttons.reset.confirm'))) { // Disable any non-core modes $('.advanced-modes input').prop('checked', false).change(); @@ -519,7 +528,9 @@ function addSettingsRangeValues() { // Display as Centimeters (2.24076923 mm per step!) num = Math.round((num / 224.076923) * 10) / 10; num = robopaint.t('common.metric.cm', {count: num}) + ' / ' + - robopaint.t('common.imperial.in', {count: (Math.round((num / 2.54) * 10) / 10)}); + robopaint.t('common.imperial.in', { + count: (Math.round((num / 2.54) * 10) / 10) + }); dosep = false; break; case 'servoup': @@ -552,7 +563,7 @@ function addSettingsRangeValues() { } // Format translated text with - if (['servotime', 'latencyoffset'].indexOf(this.id) != -1) { + if (['servotime', 'latencyoffset'].indexOf(this.id) !== -1) { post = ''; num = robopaint.t('common.time.ms', {count: num}); } @@ -563,7 +574,7 @@ function addSettingsRangeValues() { }).change(); $r.addClass('processed').after($l); - }) + }); } /** @@ -580,12 +591,12 @@ function updateColorSetSettings() { // Add Sortable color names/colors $colors.empty(); for (var i in set.colors) { - if (i == set.colors.length-1) break; // Ignore the last value + if (i === set.colors.length-1) break; // Ignore the last value $('
  • ') .append( $('') .addClass('color') - .css('background-color', set.colors[i].color['HEX']) + .css('background-color', set.colors[i].color.HEX) .text(' '), $('
  • ') .append( $('') .addClass('color') - .css('background-color', set.colors[i].color.HEX) + .css('background-color', color.color.HEX) .text(' '), - $('