From 442d9fbea9e0eb18904cdac1f269ef6859a18632 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 5 Sep 2011 07:46:55 +0000 Subject: [PATCH] (trunk web) use "===" instead of "==" when appropriate. --- web/javascript/common.js | 22 +++++++++++----------- web/javascript/dialog.js | 2 +- web/javascript/formatter.js | 25 ++++++++++++------------- web/javascript/inspector.js | 6 +++--- web/javascript/remote.js | 2 +- web/javascript/torrent-row.js | 10 +++++----- web/javascript/transmission.js | 22 +++++++++++----------- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/web/javascript/common.js b/web/javascript/common.js index 3883150d3..8ba38d5c2 100644 --- a/web/javascript/common.js +++ b/web/javascript/common.js @@ -74,7 +74,7 @@ Array.prototype.clone = function () { */ function setInnerHTML(e, html) { - if (e == undefined) + if (!e) return; /* innerHTML is listed as a string, but the browser seems to change it. @@ -177,7 +177,7 @@ Prefs._Defaults = */ Prefs.setValue = function(key, val) { - if (Prefs._Defaults[key] == undefined) + if (!(key in Prefs._Defaults)) console.warn("unrecognized preference key '%s'", key); var days = 30; @@ -196,21 +196,21 @@ Prefs.getValue = function(key, fallback) { var val; - if (Prefs._Defaults[key] == undefined) + if (!(key in Prefs._Defaults)) console.warn("unrecognized preference key '%s'", key); var lines = document.cookie.split(';'); for (var i=0, len=lines.length; !val && i= 96 && key <= 105 || // comma, period and minus, . on keypad - key == 190 || key == 188 || key == 109 || key == 110 || + key === 190 || key === 188 || key === 109 || key === 110 || // Backspace and Tab and Enter - key == 8 || key == 9 || key == 13 || + key === 8 || key === 9 || key === 13 || // Home and End - key == 35 || key == 36 || + key === 35 || key === 36 || // left and right arrows - key == 37 || key == 39 || + key === 37 || key === 39 || // Del and Ins - key == 46 || key == 45; + key === 46 || key === 45; }); }); } diff --git a/web/javascript/dialog.js b/web/javascript/dialog.js index 4ed0249ec..05774d46e 100644 --- a/web/javascript/dialog.js +++ b/web/javascript/dialog.js @@ -79,7 +79,7 @@ Dialog.prototype = { $('.dialog_container').hide(); setInnerHTML(this._heading[0], dialog_heading); setInnerHTML(this._message[0], dialog_message); - setInnerHTML(this._cancel_button[0], (cancel_button_label == null) ? 'Cancel' : cancel_button_label); + setInnerHTML(this._cancel_button[0], cancel_button_label || 'Cancel'); setInnerHTML(this._confirm_button[0], confirm_button_label); this._confirm_button.show(); this._callback_function = callback_function; diff --git a/web/javascript/formatter.js b/web/javascript/formatter.js index 30bd221a6..10d2bf071 100644 --- a/web/javascript/formatter.js +++ b/web/javascript/formatter.js @@ -69,12 +69,11 @@ Transmission.fmt = (function() * Format a ratio to a string */ ratioString: function(x) { - if (x == -1) + if (x === -1) return "None"; - else if (x == -2) + if (x === -2) return '∞'; - else - return this.percentString(x); + return this.percentString(x); }, /** @@ -192,15 +191,15 @@ Transmission.fmt = (function() var minutes = Math.floor((seconds % 3600) / 60); var seconds = Math.floor((seconds % 3600) % 60); - if (days > 0 && hours == 0) + if (days > 0 && hours === 0) result = [ days, 'days' ]; else if (days > 0 && hours > 0) result = [ days, 'days', hours, 'hr' ]; - else if (hours > 0 && minutes == 0) + else if (hours > 0 && minutes === 0) result = [ hours, 'hr' ]; else if (hours > 0 && minutes > 0) result = [ hours,'hr', minutes, 'min' ]; - else if (minutes > 0 && seconds == 0) + else if (minutes > 0 && seconds === 0) result = [ minutes, 'min' ]; else if (minutes > 0 && seconds > 0) result = [ minutes, 'min', seconds, 'seconds' ]; @@ -221,15 +220,15 @@ Transmission.fmt = (function() var date = ""; var time = ""; - var sameYear = now.getFullYear() == myDate.getFullYear(); - var sameMonth = now.getMonth() == myDate.getMonth(); + var sameYear = now.getFullYear() === myDate.getFullYear(); + var sameMonth = now.getMonth() === myDate.getMonth(); var dateDiff = now.getDate() - myDate.getDate(); if (sameYear && sameMonth && Math.abs(dateDiff) <= 1){ - if (dateDiff == 0){ + if (dateDiff === 0){ date = "Today"; } - else if (dateDiff == 1){ + else if (dateDiff === 1){ date = "Yesterday"; } else{ @@ -246,7 +245,7 @@ Transmission.fmt = (function() hours = hours - 12; period = "PM"; } - if (hours == 0){ + if (hours === 0){ hours = 12; } if (hours < 10){ @@ -293,7 +292,7 @@ Transmission.fmt = (function() case "T": explanation = "Peer is connected via uTP"; break; } - if( explanation == null ) { + if (!explanation) { formattedFlags.push(flag); } else { formattedFlags.push("" + flag + ""); diff --git a/web/javascript/inspector.js b/web/javascript/inspector.js index f6f1fa9a1..06d991e00 100644 --- a/web/javascript/inspector.js +++ b/web/javascript/inspector.js @@ -86,7 +86,7 @@ function Inspector(controller) { accumulateString = function (oldVal, newVal) { if (!oldVal || !oldVal.length) return newVal; - if (oldVal == newVal) + if (oldVal === newVal) return newVal; return 'Mixed'; }, @@ -301,7 +301,7 @@ function Inspector(controller) { 'Client', ''); for (i=0; peer=peers[i]; ++i) { - parity = ((i+1) % 2 == 0 ? 'even' : 'odd'); + parity = (i%2) ? 'odd' : 'even'; html.push('', '', (peer.isEncrypted ? 'Encrypted' : ''), '', '', (peer.rateToPeer ? fmt.speedBps(peer.rateToPeer) : ''), '', @@ -423,7 +423,7 @@ function Inspector(controller) { lastAnnounceStatusHash = lastAnnounceStatus(tracker); announceState = getAnnounceState(tracker); lastScrapeStatusHash = lastScrapeStatus(tracker); - parity = ((j+1) % 2 == 0 ? 'even' : 'odd'); + parity = (j%2) ? 'odd' : 'even'; html.push('
  • ', tracker.host, '
    ', '
    ', diff --git a/web/javascript/remote.js b/web/javascript/remote.js index e6fbddbf1..829ddc793 100644 --- a/web/javascript/remote.js +++ b/web/javascript/remote.js @@ -69,7 +69,7 @@ TransmissionRemote.prototype = remote = this; // set the Transmission-Session-Id on a 409 - if (request.status == 409 && (token = request.getResponseHeader('X-Transmission-Session-Id'))){ + if (request.status === 409 && (token = request.getResponseHeader('X-Transmission-Session-Id'))){ remote._token = token; $.ajax(ajaxObject); return; diff --git a/web/javascript/torrent-row.js b/web/javascript/torrent-row.js index 0065b43f3..34b6e21a0 100644 --- a/web/javascript/torrent-row.js +++ b/web/javascript/torrent-row.js @@ -28,17 +28,17 @@ TorrentRendererHelper.getProgressInfo = function(controller, t) else pct = 100; - if (s == Torrent._StatusStopped) + if (s === Torrent._StatusStopped) extra = 'paused'; - else if (s == Torrent._StatusDownloadWait) + else if (s === Torrent._StatusDownloadWait) extra = 'leeching queued'; else if (t.needsMetaData()) extra = 'magnet'; else if (s === Torrent._StatusDownload) extra = 'leeching'; - else if (s == Torrent._StatusSeedWait) + else if (s === Torrent._StatusSeedWait) extra = 'seeding queued'; - else if (s == Torrent._StatusSeed) + else if (s === Torrent._StatusSeed) extra = 'seeding'; else extra = ''; @@ -198,7 +198,7 @@ TorrentRendererFull.prototype = is_done = t.isDone() || t.isSeeding(); if (is_done) { - if (totalSize == sizeWhenDone) // seed: '698.05 MiB' + if (totalSize === sizeWhenDone) // seed: '698.05 MiB' c = [ Transmission.fmt.size(totalSize) ]; else // partial seed: '127.21 MiB of 698.05 MiB (18.2%)' c = [ Transmission.fmt.size(sizeWhenDone), diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index b567f6d9b..865c18f49 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -205,7 +205,7 @@ Transmission.prototype = search_box.addClass('blur'); search_box[0].value = 'Filter'; search_box.bind('blur', function() { - if (this.value == '') { + if (this.value === '') { $(this).addClass('blur'); this.value = 'Filter'; tr.setFilterText(null); @@ -287,7 +287,7 @@ Transmission.prototype = mins = ((i % 4) * 15); value = (i * 15); - content = hour + ":" + (mins == 0 ? "00" : mins); + content = hour + ":" + (mins || '00'); start.options[i] = new Option(content, value); end.options[i] = new Option(content, value); } @@ -769,7 +769,7 @@ Transmission.prototype = $('input#limit_upload').prop('checked', up_limited); $('input#upload_rate').val( up_limit_k); $('input#refresh_rate').val( p[Prefs._RefreshRate]); - $('div.encryption input').val( p[RPC._Encryption] == RPC._EncryptionRequired); + $('div.encryption input').val( p[RPC._Encryption] === RPC._EncryptionRequired); $('input#turtle_download_rate').val( turtle_dn_limit_k); $('input#turtle_upload_rate').val( turtle_up_limit_k); $('input#turtle_schedule').prop('checked', p[RPC._TurtleTimeEnabled]); @@ -880,20 +880,20 @@ Transmission.prototype = // Display the preferences dialog case 'footer_super_menu': - if ($element[0].id == 'preferences') { + if ($element[0].id === 'preferences') { $('div#prefs_container div#pref_error').hide(); $('div#prefs_container h2.dialog_heading').show(); tr.showPrefsDialog(); } - else if ($element[0].id == 'statistics') { + else if ($element[0].id === 'statistics') { $('div#stats_container div#stats_error').hide(); $('div#stats_container h2.dialog_heading').show(); tr.showStatsDialog(); } - else if ($element[0].id == 'homepage') { + else if ($element[0].id === 'homepage') { window.open('http://www.transmissionbt.com/'); } - else if ($element[0].id == 'tipjar') { + else if ($element[0].id === 'tipjar') { window.open('http://www.transmissionbt.com/donate.php'); } break; @@ -1060,7 +1060,7 @@ Transmission.prototype = // 'Apple' button emulation on PC : // Need settable meta-key and ctrl-key variables for mac emulation var meta_key = ev.metaKey; - if (ev.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1) + if (ev.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") === -1) meta_key = true; // Shift-Click - selects a range from the last-clicked row to this one @@ -1171,7 +1171,7 @@ Transmission.prototype = promptToRemoveTorrents:function(torrents) { - if (torrents.length == 1) + if (torrents.length === 1) { var torrent = torrents[0]; var header = 'Remove ' + torrent.getName() + '?'; @@ -1188,7 +1188,7 @@ Transmission.prototype = promptToRemoveTorrentsAndData:function(torrents) { - if (torrents.length == 1) + if (torrents.length === 1) { var torrent = torrents[0], header = 'Remove ' + torrent.getName() + ' and delete data?', @@ -1416,7 +1416,7 @@ Transmission.prototype = { var o, tmp, text, torrent_count, state = this[Prefs._FilterMode], - state_all = state == Prefs._FilterAll, + state_all = state === Prefs._FilterAll, state_string = this.getStateString(state), tracker = this.filterTracker, tracker_all = !tracker,