Fix javascript errors and follow best practices

This commit is contained in:
Thomas Piccirello 2017-07-01 00:42:20 -04:00 committed by sledgehammer999
parent 1ad66ba791
commit 317689bd5d
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
11 changed files with 145 additions and 145 deletions

View file

@ -70,7 +70,7 @@ window.addEvent('load', function () {
var properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y; var properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y;
localStorage.setItem('filters_width', filters_width); localStorage.setItem('filters_width', filters_width);
localStorage.setItem('properties_height_rel', properties_height_rel); localStorage.setItem('properties_height_rel', properties_height_rel);
} };
window.addEvent('resize', function() { window.addEvent('resize', function() {
// Resizing might takes some time. // Resizing might takes some time.
@ -128,7 +128,7 @@ window.addEvent('load', function () {
// Reload torrents // Reload torrents
if (typeof torrentsTable.tableBody != 'undefined') if (typeof torrentsTable.tableBody != 'undefined')
updateMainData(); updateMainData();
} };
new MochaUI.Panel({ new MochaUI.Panel({
id : 'Filters', id : 'Filters',
@ -151,10 +151,9 @@ window.addEvent('load', function () {
initializeWindows(); initializeWindows();
// Show Top Toolbar is enabled by default // Show Top Toolbar is enabled by default
if (localStorage.getItem('show_top_toolbar') == null)
var showTopToolbar = true; var showTopToolbar = true;
else if (localStorage.getItem('show_top_toolbar') !== null)
var showTopToolbar = localStorage.getItem('show_top_toolbar') == "true"; showTopToolbar = localStorage.getItem('show_top_toolbar') == "true";
if (!showTopToolbar) { if (!showTopToolbar) {
$('showTopToolbarLink').firstChild.style.opacity = '0'; $('showTopToolbarLink').firstChild.style.opacity = '0';
$('mochaToolbar').addClass('invisible'); $('mochaToolbar').addClass('invisible');
@ -171,7 +170,7 @@ window.addEvent('load', function () {
var serverState = {}; var serverState = {};
var removeTorrentFromCategoryList = function(hash) { var removeTorrentFromCategoryList = function(hash) {
if (hash == null || hash == "") if (hash === null || hash === "")
return false; return false;
var removed = false; var removed = false;
Object.each(category_list, function(category) { Object.each(category_list, function(category) {
@ -185,14 +184,14 @@ window.addEvent('load', function () {
var addTorrentToCategoryList = function(torrent) { var addTorrentToCategoryList = function(torrent) {
var category = torrent['category']; var category = torrent['category'];
if (category == null) if (category === null)
return false; return false;
if (category.length === 0) { // Empty category if (category.length === 0) { // Empty category
removeTorrentFromCategoryList(torrent['hash']); removeTorrentFromCategoryList(torrent['hash']);
return true; return true;
} }
var categoryHash = genHash(category); var categoryHash = genHash(category);
if (category_list[categoryHash] == null) // This should not happen if (category_list[categoryHash] === null) // This should not happen
category_list[categoryHash] = {name: category, torrents: []}; category_list[categoryHash] = {name: category, torrents: []};
if (!Object.contains(category_list[categoryHash].torrents, torrent['hash'])) { if (!Object.contains(category_list[categoryHash].torrents, torrent['hash'])) {
removeTorrentFromCategoryList(torrent['hash']); removeTorrentFromCategoryList(torrent['hash']);
@ -242,7 +241,7 @@ window.addEvent('load', function () {
categoryList.appendChild(create_link(CATEGORIES_ALL, 'QBT_TR(All)QBT_TR[CONTEXT=CategoryFilterModel]', all)); categoryList.appendChild(create_link(CATEGORIES_ALL, 'QBT_TR(All)QBT_TR[CONTEXT=CategoryFilterModel]', all));
categoryList.appendChild(create_link(CATEGORIES_UNCATEGORIZED, 'QBT_TR(Uncategorized)QBT_TR[CONTEXT=CategoryFilterModel]', uncategorized)); categoryList.appendChild(create_link(CATEGORIES_UNCATEGORIZED, 'QBT_TR(Uncategorized)QBT_TR[CONTEXT=CategoryFilterModel]', uncategorized));
var sortedCategories = [] var sortedCategories = [];
Object.each(category_list, function(category) { Object.each(category_list, function(category) {
sortedCategories.push(category.name); sortedCategories.push(category.name);
}); });
@ -268,7 +267,7 @@ window.addEvent('load', function () {
else else
childrens[i].className = ""; childrens[i].className = "";
} }
} };
var syncMainDataTimer; var syncMainDataTimer;
var syncMainData = function () { var syncMainData = function () {
@ -287,7 +286,7 @@ window.addEvent('load', function () {
$('error_div').set('html', ''); $('error_div').set('html', '');
if (response) { if (response) {
var update_categories = false; var update_categories = false;
var full_update = (response['full_update'] == true); var full_update = (response['full_update'] === true);
if (full_update) { if (full_update) {
torrentsTable.clear(); torrentsTable.clear();
category_list = {}; category_list = {};
@ -328,8 +327,8 @@ window.addEvent('load', function () {
torrentsTable.altRow(); torrentsTable.altRow();
if (response['server_state']) { if (response['server_state']) {
var tmp = response['server_state']; var tmp = response['server_state'];
for(var key in tmp) for(var k in tmp)
serverState[key] = tmp[key]; serverState[k] = tmp[k];
processServerState(); processServerState();
} }
updateFiltersList(); updateFiltersList();
@ -348,7 +347,7 @@ window.addEvent('load', function () {
torrentsTable.updateTable(); torrentsTable.updateTable();
clearTimeout(syncMainDataTimer); clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(100); syncMainDataTimer = syncMainData.delay(100);
} };
var processServerState = function () { var processServerState = function () {
var transfer_info = friendlyUnit(serverState.dl_info_speed, true); var transfer_info = friendlyUnit(serverState.dl_info_speed, true);
@ -368,7 +367,7 @@ window.addEvent('load', function () {
document.title = "qBittorrent ${VERSION} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]"; document.title = "qBittorrent ${VERSION} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]";
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes)); $('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes));
<!-- Statistics dialog --> // Statistics dialog
if (document.getElementById("statisticspage")) { if (document.getElementById("statisticspage")) {
$('AlltimeDL').set('html', 'QBT_TR(Alltime download:)QBT_TR[CONTEXT=StatsDialog]' + " " + friendlyUnit(serverState.alltime_dl, false)); $('AlltimeDL').set('html', 'QBT_TR(Alltime download:)QBT_TR[CONTEXT=StatsDialog]' + " " + friendlyUnit(serverState.alltime_dl, false));
$('AlltimeUL').set('html', 'QBT_TR(Alltime upload:)QBT_TR[CONTEXT=StatsDialog]' + " " + friendlyUnit(serverState.alltime_ul, false)); $('AlltimeUL').set('html', 'QBT_TR(Alltime upload:)QBT_TR[CONTEXT=StatsDialog]' + " " + friendlyUnit(serverState.alltime_ul, false));
@ -421,8 +420,8 @@ window.addEvent('load', function () {
if (enabled) if (enabled)
$('alternativeSpeedLimits').src = "images/slow.png"; $('alternativeSpeedLimits').src = "images/slow.png";
else else
$('alternativeSpeedLimits').src = "images/slow_off.png" $('alternativeSpeedLimits').src = "images/slow_off.png";
} };
$('alternativeSpeedLimits').addEvent('click', function() { $('alternativeSpeedLimits').addEvent('click', function() {
// Change icon immediately to give some feedback // Change icon immediately to give some feedback
@ -436,7 +435,7 @@ window.addEvent('load', function () {
}, },
onFailure: function() { onFailure: function() {
// Restore icon in case of failure // Restore icon in case of failure
updateAltSpeedIcon(alternativeSpeedLimits) updateAltSpeedIcon(alternativeSpeedLimits);
} }
}).send(); }).send();
}); });
@ -493,7 +492,7 @@ window.addEvent('load', function () {
if ($defined(prop_h)) if ($defined(prop_h))
prop_h = prop_h.toFloat() * Window.getSize().y; prop_h = prop_h.toFloat() * Window.getSize().y;
else else
prop_h = Window.getSize().y / 2.; prop_h = Window.getSize().y / 2.0;
new MochaUI.Panel({ new MochaUI.Panel({
id : 'propertiesPanel', id : 'propertiesPanel',
title : 'Panel', title : 'Panel',
@ -524,7 +523,7 @@ window.addEvent('load', function () {
updateWebSeedsData(); updateWebSeedsData();
else if (!$('prop_files').hasClass('invisible')) else if (!$('prop_files').hasClass('invisible'))
updateTorrentFilesData(); updateTorrentFilesData();
} };
$('PropGeneralLink').addEvent('click', function(e){ $('PropGeneralLink').addEvent('click', function(e){
$('prop_general').removeClass("invisible"); $('prop_general').removeClass("invisible");
@ -587,7 +586,7 @@ window.addEvent('load', function () {
function closeWindows() { function closeWindows() {
MochaUI.closeAll(); MochaUI.closeAll();
}; }
var keyboardEvents = new Keyboard({ var keyboardEvents = new Keyboard({
defaultEventType: 'keydown', defaultEventType: 'keydown',
@ -616,7 +615,7 @@ var loadTorrentPeersData = function(){
return; return;
} }
var current_hash = torrentsTable.getCurrentTorrentHash(); var current_hash = torrentsTable.getCurrentTorrentHash();
if (current_hash == "") { if (current_hash === "") {
syncTorrentPeersLastResponseId = 0; syncTorrentPeersLastResponseId = 0;
torrentPeersTable.clear(); torrentPeersTable.clear();
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
@ -638,7 +637,7 @@ var loadTorrentPeersData = function(){
onSuccess: function(response) { onSuccess: function(response) {
$('error_div').set('html', ''); $('error_div').set('html', '');
if (response) { if (response) {
var full_update = (response['full_update'] == true); var full_update = (response['full_update'] === true);
if (full_update) { if (full_update) {
torrentPeersTable.clear(); torrentPeersTable.clear();
} }

View file

@ -23,7 +23,7 @@ var ContextMenu = new Class({
//initialization //initialization
initialize: function(options) { initialize: function(options) {
//set options //set options
this.setOptions(options) this.setOptions(options);
//option diffs menu //option diffs menu
this.menu = $(this.options.menu); this.menu = $(this.options.menu);
@ -69,19 +69,19 @@ var ContextMenu = new Class({
}); });
// position the menu // position the menu
var xPos = e.page.x + this.options.offsets.x; var xPosMenu = e.page.x + this.options.offsets.x;
var yPos = e.page.y + this.options.offsets.y; var yPosMenu = e.page.y + this.options.offsets.y;
if (xPos + this.menu.offsetWidth > document.documentElement.clientWidth) if (xPosMenu + this.menu.offsetWidth > document.documentElement.clientWidth)
xPos -= this.menu.offsetWidth; xPosMenu -= this.menu.offsetWidth;
if (yPos + this.menu.offsetHeight > document.documentElement.clientHeight) if (yPosMenu + this.menu.offsetHeight > document.documentElement.clientHeight)
yPos = document.documentElement.clientHeight - this.menu.offsetHeight; yPosMenu = document.documentElement.clientHeight - this.menu.offsetHeight;
if (xPos < 0) if (xPosMenu < 0)
xPos = 0; xPosMenu = 0;
if (yPos < 0) if (yPosMenu < 0)
yPos = 0; yPosMenu = 0;
this.menu.setStyles({ this.menu.setStyles({
left: xPos, left: xPosMenu,
top: yPos, top: yPosMenu,
position: 'absolute', position: 'absolute',
'z-index': '2000' 'z-index': '2000'
}); });
@ -260,19 +260,19 @@ var TorrentsTableContextMenu = new Class({
h.each(function(item, index){ h.each(function(item, index){
var data = torrentsTable.rows.get(item).full_data; var data = torrentsTable.rows.get(item).full_data;
if (data['seq_dl'] != true) if (data['seq_dl'] !== true)
all_are_seq_dl = false; all_are_seq_dl = false;
else else
there_are_seq_dl = true; there_are_seq_dl = true;
if (data['f_l_piece_prio'] != true) if (data['f_l_piece_prio'] !== true)
all_are_f_l_piece_prio = false; all_are_f_l_piece_prio = false;
else else
there_are_f_l_piece_prio = true; there_are_f_l_piece_prio = true;
if (data['progress'] != 1.0) // not downloaded if (data['progress'] != 1.0) // not downloaded
all_are_downloaded = false; all_are_downloaded = false;
else if (data['super_seeding'] != true) else if (data['super_seeding'] !== true)
all_are_super_seeding = false; all_are_super_seeding = false;
if (data['state'] != 'pausedUP' && data['state'] != 'pausedDL') if (data['state'] != 'pausedUP' && data['state'] != 'pausedDL')
@ -280,7 +280,7 @@ var TorrentsTableContextMenu = new Class({
else else
there_are_paused = true; there_are_paused = true;
if (data['force_start'] != true) if (data['force_start'] !== true)
all_are_force_start = false; all_are_force_start = false;
else else
there_are_force_start = true; there_are_force_start = true;
@ -344,7 +344,7 @@ var TorrentsTableContextMenu = new Class({
categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentNewCategoryFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]</a>'})); categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentNewCategoryFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]</a>'}));
categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]</a>'})); categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]</a>'}));
var sortedCategories = [] var sortedCategories = [];
Object.each(category_list, function (category) { Object.each(category_list, function (category) {
sortedCategories.push(category.name); sortedCategories.push(category.name);
}); });

View file

@ -35,7 +35,7 @@ getSavePath = function() {
} }
} }
}).send(); }).send();
} };
$(window).addEventListener("load", function() { $(window).addEventListener("load", function() {
getSavePath(); getSavePath();

View file

@ -45,8 +45,8 @@ var DynamicTable = new Class({
this.hiddenTableHeader = $(dynamicTableDivId).getElements('tr')[0]; this.hiddenTableHeader = $(dynamicTableDivId).getElements('tr')[0];
this.tableBody = $(dynamicTableDivId).getElements('tbody')[0]; this.tableBody = $(dynamicTableDivId).getElements('tbody')[0];
this.rows = new Hash(); this.rows = new Hash();
this.selectedRows = new Array(); this.selectedRows = [];
this.columns = new Array(); this.columns = [];
this.contextMenu = contextMenu; this.contextMenu = contextMenu;
this.sortedColumn = getLocalStorageItem('sorted_column_' + this.dynamicTableDivId, 0); this.sortedColumn = getLocalStorageItem('sorted_column_' + this.dynamicTableDivId, 0);
this.reverseSort = getLocalStorageItem('reverse_sort_' + this.dynamicTableDivId, '0'); this.reverseSort = getLocalStorageItem('reverse_sort_' + this.dynamicTableDivId, '0');
@ -116,7 +116,7 @@ var DynamicTable = new Class({
el.setStyle('border-right-color', ''); el.setStyle('border-right-color', '');
el.setStyle('border-right-width', ''); el.setStyle('border-right-width', '');
} }
} };
var mouseMoveFn = function (e) { var mouseMoveFn = function (e) {
var brect = e.target.getBoundingClientRect(); var brect = e.target.getBoundingClientRect();
@ -250,7 +250,7 @@ var DynamicTable = new Class({
onDrag : onDrag, onDrag : onDrag,
onComplete : onComplete, onComplete : onComplete,
onCancel : onCancel onCancel : onCancel
}) });
} }
}, },
@ -331,7 +331,7 @@ var DynamicTable = new Class({
column['width'] = getLocalStorageItem('column_' + name + '_width_' + this.dynamicTableDivId, defaultWidth); column['width'] = getLocalStorageItem('column_' + name + '_width_' + this.dynamicTableDivId, defaultWidth);
column['dataProperties'] = [name]; column['dataProperties'] = [name];
column['getRowValue'] = function (row, pos) { column['getRowValue'] = function (row, pos) {
if (pos == undefined) if (pos === undefined)
pos = 0; pos = 0;
return row['full_data'][this.dataProperties[pos]]; return row['full_data'][this.dataProperties[pos]];
}; };
@ -429,8 +429,8 @@ var DynamicTable = new Class({
else { else {
ths[pos].addClass('invisible'); ths[pos].addClass('invisible');
fths[pos].addClass('invisible'); fths[pos].addClass('invisible');
for (var i = 0; i < trs.length; i++) for (var j = 0; j < trs.length; j++)
trs[i].getElements('td')[pos].addClass('invisible'); trs[j].getElements('td')[pos].addClass('invisible');
} }
if (this.columns[pos].onResize !== null) if (this.columns[pos].onResize !== null)
{ {
@ -527,7 +527,7 @@ var DynamicTable = new Class({
}, },
getFilteredAndSortedRows : function () { getFilteredAndSortedRows : function () {
var filteredRows = new Array(); var filteredRows = [];
var rows = this.rows.getValues(); var rows = this.rows.getValues();
@ -557,7 +557,7 @@ var DynamicTable = new Class({
}, },
updateTable : function (fullUpdate) { updateTable : function (fullUpdate) {
if (fullUpdate == undefined) if (fullUpdate === undefined)
fullUpdate = false; fullUpdate = false;
var rows = this.getFilteredAndSortedRows(); var rows = this.getFilteredAndSortedRows();
@ -573,7 +573,7 @@ var DynamicTable = new Class({
for (var rowPos = 0; rowPos < rows.length; rowPos++) { for (var rowPos = 0; rowPos < rows.length; rowPos++) {
var rowId = rows[rowPos]['rowId']; var rowId = rows[rowPos]['rowId'];
tr_found = false; tr_found = false;
for (j = rowPos; j < trs.length; j++) for (var j = rowPos; j < trs.length; j++)
if (trs[j]['rowId'] == rowId) { if (trs[j]['rowId'] == rowId) {
tr_found = true; tr_found = true;
if (rowPos == j) if (rowPos == j)
@ -635,7 +635,7 @@ var DynamicTable = new Class({
tr.addClass('selected'); tr.addClass('selected');
} }
else else
tr.removeClass('selected') tr.removeClass('selected');
} }
} }
} else { } else {
@ -648,9 +648,9 @@ var DynamicTable = new Class({
this.setupTr(tr); this.setupTr(tr);
for (var j = 0 ; j < this.columns.length; j++) { for (var k = 0 ; k < this.columns.length; k++) {
var td = new Element('td'); var td = new Element('td');
if ((this.columns[j].visible == '0') || this.columns[j].force_hide) if ((this.columns[k].visible == '0') || this.columns[k].force_hide)
td.addClass('invisible'); td.addClass('invisible');
td.injectInside(tr); td.injectInside(tr);
} }
@ -698,7 +698,7 @@ var DynamicTable = new Class({
removeRow : function (rowId) { removeRow : function (rowId) {
this.selectedRows.erase(rowId); this.selectedRows.erase(rowId);
var tr = this.getTrByRowId(rowId); var tr = this.getTrByRowId(rowId);
if (tr != null) { if (tr !== null) {
tr.dispose(); tr.dispose();
this.rows.erase(rowId); this.rows.erase(rowId);
return true; return true;
@ -973,7 +973,7 @@ var TorrentsTable = new Class({
this.columns['dl_limit'].updateTd = function (td, row) { this.columns['dl_limit'].updateTd = function (td, row) {
var speed = this.getRowValue(row); var speed = this.getRowValue(row);
if (speed === 0) if (speed === 0)
td.set('html', '∞') td.set('html', '∞');
else else
td.set('html', friendlyUnit(speed, true)); td.set('html', friendlyUnit(speed, true));
}; };
@ -1039,9 +1039,10 @@ var TorrentsTable = new Class({
break; break;
case 'inactive': case 'inactive':
inactive = true; inactive = true;
break;
case 'active': case 'active':
if (state == 'stalledDL') if (state == 'stalledDL')
r = (row['full_data'].upspeed > 0) r = (row['full_data'].upspeed > 0);
else else
r = state == 'metaDL' || state == 'downloading' || state == 'forcedDL' || state == 'uploading' || state == 'forcedUP'; r = state == 'metaDL' || state == 'downloading' || state == 'forcedDL' || state == 'uploading' || state == 'forcedUP';
if (r == inactive) if (r == inactive)
@ -1086,7 +1087,7 @@ var TorrentsTable = new Class({
}, },
getFilteredAndSortedRows : function () { getFilteredAndSortedRows : function () {
var filteredRows = new Array(); var filteredRows = [];
var rows = this.rows.getValues(); var rows = this.rows.getValues();
@ -1218,7 +1219,7 @@ var TorrentPeersTable = new Class({
this.columns['dl_speed'].updateTd = function (td, row) { this.columns['dl_speed'].updateTd = function (td, row) {
var speed = this.getRowValue(row); var speed = this.getRowValue(row);
if (speed == 0) if (speed === 0)
td.set('html', ''); td.set('html', '');
else else
td.set('html', friendlyUnit(speed, true)); td.set('html', friendlyUnit(speed, true));

View file

@ -16,8 +16,8 @@ function friendlyUnit(value, isSpeed) {
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]"; return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
var i = 0; var i = 0;
while (value >= 1024. && i < 6) { while (value >= 1024.0 && i < 6) {
value /= 1024.; value /= 1024.0;
++i; ++i;
} }
@ -28,7 +28,7 @@ function friendlyUnit(value, isSpeed) {
} }
var ret; var ret;
if (i == 0) if (i === 0)
ret = value + " " + units[i]; ret = value + " " + units[i];
else else
ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up
@ -46,7 +46,7 @@ function friendlyDuration(seconds) {
var MAX_ETA = 8640000; var MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA) if (seconds < 0 || seconds >= MAX_ETA)
return "∞"; return "∞";
if (seconds == 0) if (seconds === 0)
return "0"; return "0";
if (seconds < 60) if (seconds < 60)
return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]"; return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]";
@ -56,11 +56,11 @@ function friendlyDuration(seconds) {
var hours = minutes / 60; var hours = minutes / 60;
minutes = minutes % 60; minutes = minutes % 60;
if (hours < 24) if (hours < 24)
return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes)) return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes));
var days = hours / 24; var days = hours / 24;
hours = hours % 24; hours = hours % 24;
if (days < 100) if (days < 100)
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours)) return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours));
return "∞"; return "∞";
} }
@ -103,4 +103,4 @@ function escapeHtml(str) {
var div = document.createElement('div'); var div = document.createElement('div');
div.appendChild(document.createTextNode(str)); div.appendChild(document.createTextNode(str));
return div.innerHTML; return div.innerHTML;
}; }

View file

@ -19,7 +19,7 @@ if (typeof localStorage == 'undefined') {
duration: 365 * 10 duration: 365 * 10
}); });
} }
} };
} }
function getLocalStorageItem(name, defaultVal) { function getLocalStorageItem(name, defaultVal) {
@ -116,7 +116,7 @@ initializeWindows = function() {
width: 424, width: 424,
height: 80 height: 80
}); });
} };
uploadLimitFN = function() { uploadLimitFN = function() {
var h = torrentsTable.selectedRowsIds(); var h = torrentsTable.selectedRowsIds();
@ -210,7 +210,7 @@ initializeWindows = function() {
width: 424, width: 424,
height: 80 height: 80
}); });
} };
StatisticsLinkFN = function() { StatisticsLinkFN = function() {
new MochaUI.Window({ new MochaUI.Window({
@ -225,7 +225,7 @@ initializeWindows = function() {
height: 370, height: 370,
padding: 10 padding: 10
}); });
} };
downloadLimitFN = function() { downloadLimitFN = function() {
var h = torrentsTable.selectedRowsIds(); var h = torrentsTable.selectedRowsIds();
@ -340,8 +340,8 @@ initializeWindows = function() {
torrentSetCategoryFN = function (categoryHash) { torrentSetCategoryFN = function (categoryHash) {
var categoryName = ''; var categoryName = '';
if (categoryHash != 0) if (categoryHash !== 0)
var categoryName = category_list[categoryHash].name; categoryName = category_list[categoryHash].name;
var h = torrentsTable.selectedRowsIds(); var h = torrentsTable.selectedRowsIds();
if (h.length) { if (h.length) {
new Request({ new Request({
@ -387,7 +387,7 @@ initializeWindows = function() {
deleteUnusedCategoriesFN = function () { deleteUnusedCategoriesFN = function () {
var categories = []; var categories = [];
for (var hash in category_list) { for (var hash in category_list) {
if (torrentsTable.getFilteredTorrentsNumber('all', hash) == 0) if (torrentsTable.getFilteredTorrentsNumber('all', hash) === 0)
categories.push(category_list[hash].name); categories.push(category_list[hash].name);
} }
new Request({ new Request({
@ -499,7 +499,7 @@ initializeWindows = function() {
}).send(); }).send();
updateMainData(); updateMainData();
} }
} };
addClickEvent('about', function(e) { addClickEvent('about', function(e) {
new Event(e).stop(); new Event(e).stop();
@ -544,4 +544,4 @@ initializeWindows = function() {
new Event(e).stop(); new Event(e).stop();
}); });
}); });
} };

View file

@ -28,7 +28,7 @@ MochaUI.extend({
if (data) { if (data) {
var tmp = data.toInt(); var tmp = data.toInt();
if (tmp > 0) { if (tmp > 0) {
maximum = tmp / 1024. maximum = tmp / 1024.0;
} }
else { else {
if (hashes[0] == "global") if (hashes[0] == "global")
@ -59,7 +59,7 @@ MochaUI.extend({
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (up_limit == 0) { if (up_limit === 0) {
$('uplimitUpdatevalue').value = '∞'; $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden"; $('upLimitUnit').style.visibility = "hidden";
} }
@ -88,7 +88,7 @@ MochaUI.extend({
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum, steps: maximum,
offset: 0, offset: 0,
initialStep: (up_limit / 1024.).round(), initialStep: (up_limit / 1024.0).round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('uplimitUpdatevalue').value = pos; $('uplimitUpdatevalue').value = pos;
@ -101,12 +101,12 @@ MochaUI.extend({
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (up_limit == 0) { if (up_limit === 0) {
$('uplimitUpdatevalue').value = '∞'; $('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden"; $('upLimitUnit').style.visibility = "hidden";
} }
else { else {
$('uplimitUpdatevalue').value = (up_limit / 1024.).round(); $('uplimitUpdatevalue').value = (up_limit / 1024.0).round();
$('upLimitUnit').style.visibility = "visible"; $('upLimitUnit').style.visibility = "visible";
} }
} }
@ -132,7 +132,7 @@ MochaUI.extend({
if (data) { if (data) {
var tmp = data.toInt(); var tmp = data.toInt();
if (tmp > 0) { if (tmp > 0) {
maximum = tmp / 1024. maximum = tmp / 1024.0;
} }
else { else {
if (hashes[0] == "global") if (hashes[0] == "global")
@ -163,7 +163,7 @@ MochaUI.extend({
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (dl_limit == 0) { if (dl_limit === 0) {
$('dllimitUpdatevalue').value = '∞'; $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden"; $('dlLimitUnit').style.visibility = "hidden";
} }
@ -192,7 +192,7 @@ MochaUI.extend({
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum, steps: maximum,
offset: 0, offset: 0,
initialStep: (dl_limit / 1024.).round(), initialStep: (dl_limit / 1024.0).round(),
onChange: function(pos) { onChange: function(pos) {
if (pos > 0) { if (pos > 0) {
$('dllimitUpdatevalue').value = pos; $('dllimitUpdatevalue').value = pos;
@ -205,12 +205,12 @@ MochaUI.extend({
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if (dl_limit == 0) { if (dl_limit === 0) {
$('dllimitUpdatevalue').value = '∞'; $('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden"; $('dlLimitUnit').style.visibility = "hidden";
} }
else { else {
$('dllimitUpdatevalue').value = (dl_limit / 1024.).round(); $('dllimitUpdatevalue').value = (dl_limit / 1024.0).round();
$('dlLimitUnit').style.visibility = "visible"; $('dlLimitUnit').style.visibility = "visible";
} }
} }

View file

@ -40,7 +40,7 @@ var setCBState = function(state) {
$("tristate_cb").checked = false; $("tristate_cb").checked = false;
} }
} }
} };
var switchCBState = function() { var switchCBState = function() {
// Uncheck // Uncheck
@ -69,7 +69,7 @@ var switchCBState = function() {
item.set("checked", "checked"); item.set("checked", "checked");
setFilePriority(index, 1); setFilePriority(index, 1);
}); });
} };
var allCBChecked = function() { var allCBChecked = function() {
var CBs = $$('input.DownloadedCB'); var CBs = $$('input.DownloadedCB');
@ -79,7 +79,7 @@ var allCBChecked = function() {
return false; return false;
} }
return true; return true;
} };
var allCBUnchecked = function() { var allCBUnchecked = function() {
var CBs = $$('input.DownloadedCB'); var CBs = $$('input.DownloadedCB');
@ -89,10 +89,10 @@ var allCBUnchecked = function() {
return false; return false;
} }
return true; return true;
} };
var setFilePriority = function(id, priority) { var setFilePriority = function(id, priority) {
if (current_hash == "") return; if (current_hash === "") return;
new Request({ new Request({
url: 'command/setFilePrio', url: 'command/setFilePrio',
method: 'post', method: 'post',
@ -110,7 +110,7 @@ var setFilePriority = function(id, priority) {
else { else {
$('comboPrio' + id).addClass("invisible"); $('comboPrio' + id).addClass("invisible");
} }
} };
var createDownloadedCB = function(id, downloaded) { var createDownloadedCB = function(id, downloaded) {
var CB = new Element('input'); var CB = new Element('input');
@ -137,7 +137,7 @@ var createDownloadedCB = function(id, downloaded) {
} }
}); });
return CB; return CB;
} };
var createPriorityCombo = function(id, selected_prio) { var createPriorityCombo = function(id, selected_prio) {
var select = new Element('select'); var select = new Element('select');
@ -147,19 +147,19 @@ var createPriorityCombo = function(id, selected_prio) {
setFilePriority(id, new_prio); setFilePriority(id, new_prio);
}); });
var opt = new Element("option"); var opt = new Element("option");
opt.set('value', '1') opt.set('value', '1');
opt.set('html', "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]"); opt.set('html', "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]");
if (selected_prio <= 1) if (selected_prio <= 1)
opt.setAttribute('selected', ''); opt.setAttribute('selected', '');
opt.injectInside(select); opt.injectInside(select);
opt = new Element("option"); opt = new Element("option");
opt.set('value', '2') opt.set('value', '2');
opt.set('html', "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]"); opt.set('html', "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]");
if (selected_prio == 2) if (selected_prio == 2)
opt.setAttribute('selected', ''); opt.setAttribute('selected', '');
opt.injectInside(select); opt.injectInside(select);
opt = new Element("option"); opt = new Element("option");
opt.set('value', '7') opt.set('value', '7');
opt.set('html', "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]"); opt.set('html', "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]");
if (selected_prio == 7) if (selected_prio == 7)
opt.setAttribute('selected', ''); opt.setAttribute('selected', '');
@ -172,7 +172,7 @@ var createPriorityCombo = function(id, selected_prio) {
} }
select.addClass("combo_priority"); select.addClass("combo_priority");
return select; return select;
} };
var filesDynTable = new Class({ var filesDynTable = new Class({
@ -231,8 +231,8 @@ var filesDynTable = new Class({
insertRow: function(id, row) { insertRow: function(id, row) {
if (this.rows.has(id)) { if (this.rows.has(id)) {
var tr = this.rows.get(id); var tableRow = this.rows.get(id);
this.updateRow(tr, row, id); this.updateRow(tableRow, row, id);
return; return;
} }
//this.removeRow(id); //this.removeRow(id);
@ -279,7 +279,7 @@ var loadTorrentFilesData = function() {
return; return;
} }
var new_hash = torrentsTable.getCurrentTorrentHash(); var new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash == "") { if (new_hash === "") {
fTable.removeAllRows(); fTable.removeAllRows();
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000); loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
@ -305,17 +305,17 @@ var loadTorrentFilesData = function() {
// Update Trackers data // Update Trackers data
var i = 0; var i = 0;
files.each(function(file) { files.each(function(file) {
if (i == 0) { if (i === 0) {
is_seed = file.is_seed; is_seed = file.is_seed;
} }
var row = new Array(); var row = [];
row.length = 4; row.length = 4;
row[0] = file.priority; row[0] = file.priority;
row[1] = escapeHtml(file.name); row[1] = escapeHtml(file.name);
row[2] = friendlyUnit(file.size, false); row[2] = friendlyUnit(file.size, false);
row[3] = (file.progress * 100).round(1); row[3] = (file.progress * 100).round(1);
if (row[3] == 100.0 && file.progress < 1.0) if (row[3] == 100.0 && file.progress < 1.0)
row[3] = 99.9 row[3] = 99.9;
row[4] = file.priority; row[4] = file.priority;
fTable.insertRow(i, row); fTable.insertRow(i, row);
i++; i++;
@ -340,12 +340,12 @@ var loadTorrentFilesData = function() {
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000); loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
} }
}).send(); }).send();
} };
var updateTorrentFilesData = function() { var updateTorrentFilesData = function() {
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesData(); loadTorrentFilesData();
} };
fTable = new filesDynTable(); fTable = new filesDynTable();
fTable.setup($('filesTable')); fTable.setup($('filesTable'));

View file

@ -23,7 +23,7 @@ var clearData = function() {
$('torrent_hash').set('html', ''); $('torrent_hash').set('html', '');
$('save_path').set('html', ''); $('save_path').set('html', '');
$('comment').set('html', ''); $('comment').set('html', '');
} };
var loadTorrentDataTimer; var loadTorrentDataTimer;
var loadTorrentData = function() { var loadTorrentData = function() {
@ -33,7 +33,7 @@ var loadTorrentData = function() {
return; return;
} }
var current_hash = torrentsTable.getCurrentTorrentHash(); var current_hash = torrentsTable.getCurrentTorrentHash();
if (current_hash == "") { if (current_hash === "") {
clearData(); clearData();
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
@ -59,26 +59,26 @@ var loadTorrentData = function() {
if (data.seeding_time > 0) if (data.seeding_time > 0)
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyDuration(data.time_elapsed)) .replace("%1", friendlyDuration(data.time_elapsed))
.replace("%2", friendlyDuration(data.seeding_time)) .replace("%2", friendlyDuration(data.seeding_time));
else else
temp = friendlyDuration(data.time_elapsed) temp = friendlyDuration(data.time_elapsed);
$('time_elapsed').set('html', temp); $('time_elapsed').set('html', temp);
$('eta').set('html', friendlyDuration(data.eta)); $('eta').set('html', friendlyDuration(data.eta));
temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.nb_connections) .replace("%1", data.nb_connections)
.replace("%2", data.nb_connections_limit < 0 ? "∞" : data.nb_connections_limit) .replace("%2", data.nb_connections_limit < 0 ? "∞" : data.nb_connections_limit);
$('nb_connections').set('html', temp); $('nb_connections').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_downloaded)) .replace("%1", friendlyUnit(data.total_downloaded))
.replace("%2", friendlyUnit(data.total_downloaded_session)) .replace("%2", friendlyUnit(data.total_downloaded_session));
$('total_downloaded').set('html', temp); $('total_downloaded').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_uploaded)) .replace("%1", friendlyUnit(data.total_uploaded))
.replace("%2", friendlyUnit(data.total_uploaded_session)) .replace("%2", friendlyUnit(data.total_uploaded_session));
$('total_uploaded').set('html', temp); $('total_uploaded').set('html', temp);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
@ -161,9 +161,9 @@ var loadTorrentData = function() {
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
} }
}).send(); }).send();
} };
var updateTorrentData = function() { var updateTorrentData = function() {
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentData(); loadTorrentData();
} };

View file

@ -34,8 +34,8 @@ var trackersDynTable = new Class({
insertRow: function(row) { insertRow: function(row) {
var url = row[0]; var url = row[0];
if (this.rows.has(url)) { if (this.rows.has(url)) {
var tr = this.rows.get(url); var tableRow = this.rows.get(url);
this.updateRow(tr, row); this.updateRow(tableRow, row);
return; return;
} }
//this.removeRow(id); //this.removeRow(id);
@ -60,7 +60,7 @@ var loadTrackersData = function() {
return; return;
} }
var new_hash = torrentsTable.getCurrentTorrentHash(); var new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash == "") { if (new_hash === "") {
tTable.removeAllRows(); tTable.removeAllRows();
clearTimeout(loadTrackersDataTimer); clearTimeout(loadTrackersDataTimer);
loadTrackersDataTimer = loadTrackersData.delay(10000); loadTrackersDataTimer = loadTrackersData.delay(10000);
@ -85,7 +85,7 @@ var loadTrackersData = function() {
if (trackers) { if (trackers) {
// Update Trackers data // Update Trackers data
trackers.each(function(tracker) { trackers.each(function(tracker) {
var row = new Array(); var row = [];
row.length = 4; row.length = 4;
row[0] = escapeHtml(tracker.url); row[0] = escapeHtml(tracker.url);
row[1] = tracker.status; row[1] = tracker.status;
@ -101,19 +101,19 @@ var loadTrackersData = function() {
loadTrackersDataTimer = loadTrackersData.delay(10000); loadTrackersDataTimer = loadTrackersData.delay(10000);
} }
}).send(); }).send();
} };
var updateTrackersData = function() { var updateTrackersData = function() {
clearTimeout(loadTrackersDataTimer); clearTimeout(loadTrackersDataTimer);
loadTrackersData(); loadTrackersData();
} };
tTable = new trackersDynTable(); tTable = new trackersDynTable();
tTable.setup($('trackersTable')); tTable.setup($('trackersTable'));
// Add trackers code // Add trackers code
$('addTrackersPlus').addEvent('click', function addTrackerDlg() { $('addTrackersPlus').addEvent('click', function addTrackerDlg() {
if (current_hash.length == 0) return; if (current_hash.length === 0) return;
new MochaUI.Window({ new MochaUI.Window({
id: 'trackersPage', id: 'trackersPage',
title: "QBT_TR(Trackers addition dialog)QBT_TR[CONTEXT=TrackersAdditionDlg]", title: "QBT_TR(Trackers addition dialog)QBT_TR[CONTEXT=TrackersAdditionDlg]",

View file

@ -34,8 +34,8 @@ var webseedsDynTable = new Class({
insertRow: function(row) { insertRow: function(row) {
var url = row[0]; var url = row[0];
if (this.rows.has(url)) { if (this.rows.has(url)) {
var tr = this.rows.get(url); var tableRow = this.rows.get(url);
this.updateRow(tr, row); this.updateRow(tableRow, row);
return; return;
} }
//this.removeRow(id); //this.removeRow(id);
@ -60,7 +60,7 @@ var loadWebSeedsData = function() {
return; return;
} }
var new_hash = torrentsTable.getCurrentTorrentHash(); var new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash == "") { if (new_hash === "") {
wsTable.removeAllRows(); wsTable.removeAllRows();
clearTimeout(loadWebSeedsDataTimer); clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
@ -85,7 +85,7 @@ var loadWebSeedsData = function() {
if (webseeds) { if (webseeds) {
// Update WebSeeds data // Update WebSeeds data
webseeds.each(function(webseed) { webseeds.each(function(webseed) {
var row = new Array(); var row = [];
row.length = 1; row.length = 1;
row[0] = webseed.url; row[0] = webseed.url;
wsTable.insertRow(row); wsTable.insertRow(row);
@ -98,12 +98,12 @@ var loadWebSeedsData = function() {
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
} }
}).send(); }).send();
} };
var updateWebSeedsData = function() { var updateWebSeedsData = function() {
clearTimeout(loadWebSeedsDataTimer); clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsData(); loadWebSeedsData();
} };
wsTable = new webseedsDynTable(); wsTable = new webseedsDynTable();
wsTable.setup($('webseedsTable')); wsTable.setup($('webseedsTable'));