Browse Source

Merge pull request #7031 from Piccirello/fix-js-errors

Fix various javascript errors and follow best practices
adaptive-webui-19844
Mike Tzou 8 years ago committed by GitHub
parent
commit
db2dec3d28
  1. 47
      src/webui/www/public/scripts/client.js
  2. 36
      src/webui/www/public/scripts/contextmenu.js
  3. 28
      src/webui/www/public/scripts/download.js
  4. 37
      src/webui/www/public/scripts/dynamicTable.js
  5. 16
      src/webui/www/public/scripts/misc.js
  6. 20
      src/webui/www/public/scripts/mocha-init.js
  7. 24
      src/webui/www/public/scripts/parametrics.js
  8. 38
      src/webui/www/public/scripts/prop-files.js
  9. 18
      src/webui/www/public/scripts/prop-general.js
  10. 14
      src/webui/www/public/scripts/prop-trackers.js
  11. 12
      src/webui/www/public/scripts/prop-webseeds.js

47
src/webui/www/public/scripts/client.js

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

36
src/webui/www/public/scripts/contextmenu.js

@ -23,7 +23,7 @@ var ContextMenu = new Class({ @@ -23,7 +23,7 @@ var ContextMenu = new Class({
//initialization
initialize: function(options) {
//set options
this.setOptions(options)
this.setOptions(options);
//option diffs menu
this.menu = $(this.options.menu);
@ -69,19 +69,19 @@ var ContextMenu = new Class({ @@ -69,19 +69,19 @@ var ContextMenu = new Class({
});
// position the menu
var xPos = e.page.x + this.options.offsets.x;
var yPos = e.page.y + this.options.offsets.y;
if (xPos + this.menu.offsetWidth > document.documentElement.clientWidth)
xPos -= this.menu.offsetWidth;
if (yPos + this.menu.offsetHeight > document.documentElement.clientHeight)
yPos = document.documentElement.clientHeight - this.menu.offsetHeight;
if (xPos < 0)
xPos = 0;
if (yPos < 0)
yPos = 0;
var xPosMenu = e.page.x + this.options.offsets.x;
var yPosMenu = e.page.y + this.options.offsets.y;
if (xPosMenu + this.menu.offsetWidth > document.documentElement.clientWidth)
xPosMenu -= this.menu.offsetWidth;
if (yPosMenu + this.menu.offsetHeight > document.documentElement.clientHeight)
yPosMenu = document.documentElement.clientHeight - this.menu.offsetHeight;
if (xPosMenu < 0)
xPosMenu = 0;
if (yPosMenu < 0)
yPosMenu = 0;
this.menu.setStyles({
left: xPos,
top: yPos,
left: xPosMenu,
top: yPosMenu,
position: 'absolute',
'z-index': '2000'
});
@ -260,19 +260,19 @@ var TorrentsTableContextMenu = new Class({ @@ -260,19 +260,19 @@ var TorrentsTableContextMenu = new Class({
h.each(function(item, index){
var data = torrentsTable.rows.get(item).full_data;
if (data['seq_dl'] != true)
if (data['seq_dl'] !== true)
all_are_seq_dl = false;
else
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;
else
there_are_f_l_piece_prio = true;
if (data['progress'] != 1.0) // not downloaded
all_are_downloaded = false;
else if (data['super_seeding'] != true)
else if (data['super_seeding'] !== true)
all_are_super_seeding = false;
if (data['state'] != 'pausedUP' && data['state'] != 'pausedDL')
@ -280,7 +280,7 @@ var TorrentsTableContextMenu = new Class({ @@ -280,7 +280,7 @@ var TorrentsTableContextMenu = new Class({
else
there_are_paused = true;
if (data['force_start'] != true)
if (data['force_start'] !== true)
all_are_force_start = false;
else
there_are_force_start = true;
@ -344,7 +344,7 @@ var TorrentsTableContextMenu = new Class({ @@ -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: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) {
sortedCategories.push(category.name);
});

28
src/webui/www/public/scripts/download.js

@ -22,20 +22,20 @@ @@ -22,20 +22,20 @@
*/
getSavePath = function() {
var req = new Request({
url: 'command/getSavePath',
method: 'get',
noCache: true,
onFailure: function() {
alert("Could not contact qBittorrent");
},
onSuccess: function(data) {
if (data) {
$('savepath').setProperty('value', data);
}
}
}).send();
}
var req = new Request({
url: 'command/getSavePath',
method: 'get',
noCache: true,
onFailure: function() {
alert("Could not contact qBittorrent");
},
onSuccess: function(data) {
if (data) {
$('savepath').setProperty('value', data);
}
}
}).send();
};
$(window).addEventListener("load", function() {
getSavePath();

37
src/webui/www/public/scripts/dynamicTable.js

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

16
src/webui/www/public/scripts/misc.js

@ -16,8 +16,8 @@ function friendlyUnit(value, isSpeed) { @@ -16,8 +16,8 @@ function friendlyUnit(value, isSpeed) {
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
var i = 0;
while (value >= 1024. && i < 6) {
value /= 1024.;
while (value >= 1024.0 && i < 6) {
value /= 1024.0;
++i;
}
@ -28,7 +28,7 @@ function friendlyUnit(value, isSpeed) { @@ -28,7 +28,7 @@ function friendlyUnit(value, isSpeed) {
}
var ret;
if (i == 0)
if (i === 0)
ret = value + " " + units[i];
else
ret = (Math.floor(10 * value) / 10).toFixed(friendlyUnitPrecision(i)) //Don't round up
@ -46,7 +46,7 @@ function friendlyDuration(seconds) { @@ -46,7 +46,7 @@ function friendlyDuration(seconds) {
var MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA)
return "∞";
if (seconds == 0)
if (seconds === 0)
return "0";
if (seconds < 60)
return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]";
@ -56,11 +56,11 @@ function friendlyDuration(seconds) { @@ -56,11 +56,11 @@ function friendlyDuration(seconds) {
var hours = minutes / 60;
minutes = minutes % 60;
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;
hours = hours % 24;
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 "∞";
}
@ -96,11 +96,11 @@ if (!Date.prototype.toISOString) { @@ -96,11 +96,11 @@ if (!Date.prototype.toISOString) {
*/
function parseHtmlLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
return text.replace(exp,"<a target='_blank' href='$1'>$1</a>");
}
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
}

20
src/webui/www/public/scripts/mocha-init.js

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

24
src/webui/www/public/scripts/parametrics.js

@ -4,7 +4,7 @@ Script: Parametrics.js @@ -4,7 +4,7 @@ Script: Parametrics.js
Initializes the GUI property sliders.
Copyright:
Copyright (c) 2007-2008 Greg Houston, <http://greghoustondesign.com/>.
Copyright (c) 2007-2008 Greg Houston, <http://greghoustondesign.com/>.
License:
MIT-style license.
@ -28,7 +28,7 @@ MochaUI.extend({ @@ -28,7 +28,7 @@ MochaUI.extend({
if (data) {
var tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.
maximum = tmp / 1024.0;
}
else {
if (hashes[0] == "global")
@ -59,7 +59,7 @@ MochaUI.extend({ @@ -59,7 +59,7 @@ MochaUI.extend({
}.bind(this)
});
// Set default value
if (up_limit == 0) {
if (up_limit === 0) {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
@ -88,7 +88,7 @@ MochaUI.extend({ @@ -88,7 +88,7 @@ MochaUI.extend({
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (up_limit / 1024.).round(),
initialStep: (up_limit / 1024.0).round(),
onChange: function(pos) {
if (pos > 0) {
$('uplimitUpdatevalue').value = pos;
@ -101,12 +101,12 @@ MochaUI.extend({ @@ -101,12 +101,12 @@ MochaUI.extend({
}.bind(this)
});
// Set default value
if (up_limit == 0) {
if (up_limit === 0) {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
else {
$('uplimitUpdatevalue').value = (up_limit / 1024.).round();
$('uplimitUpdatevalue').value = (up_limit / 1024.0).round();
$('upLimitUnit').style.visibility = "visible";
}
}
@ -132,7 +132,7 @@ MochaUI.extend({ @@ -132,7 +132,7 @@ MochaUI.extend({
if (data) {
var tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.
maximum = tmp / 1024.0;
}
else {
if (hashes[0] == "global")
@ -163,7 +163,7 @@ MochaUI.extend({ @@ -163,7 +163,7 @@ MochaUI.extend({
}.bind(this)
});
// Set default value
if (dl_limit == 0) {
if (dl_limit === 0) {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
@ -192,7 +192,7 @@ MochaUI.extend({ @@ -192,7 +192,7 @@ MochaUI.extend({
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (dl_limit / 1024.).round(),
initialStep: (dl_limit / 1024.0).round(),
onChange: function(pos) {
if (pos > 0) {
$('dllimitUpdatevalue').value = pos;
@ -205,12 +205,12 @@ MochaUI.extend({ @@ -205,12 +205,12 @@ MochaUI.extend({
}.bind(this)
});
// Set default value
if (dl_limit == 0) {
if (dl_limit === 0) {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
else {
$('dllimitUpdatevalue').value = (dl_limit / 1024.).round();
$('dllimitUpdatevalue').value = (dl_limit / 1024.0).round();
$('dlLimitUnit').style.visibility = "visible";
}
}
@ -221,4 +221,4 @@ MochaUI.extend({ @@ -221,4 +221,4 @@ MochaUI.extend({
}).send();
}
}
});
});

38
src/webui/www/public/scripts/prop-files.js

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

18
src/webui/www/public/scripts/prop-general.js

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

14
src/webui/www/public/scripts/prop-trackers.js

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

12
src/webui/www/public/scripts/prop-webseeds.js

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

Loading…
Cancel
Save