mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Move JavaScript code into explicit namespaces
This cleans up the global namespace by explicitly exporting shared values. All html and JavaScript files have been converted to use explicit exports except for client.js and mocha-init.js
This commit is contained in:
parent
b144d3b797
commit
1439bcc864
32 changed files with 6204 additions and 5838 deletions
|
@ -28,112 +28,126 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const webseedsDynTable = new Class({
|
||||
if (window.qBittorrent === undefined) {
|
||||
window.qBittorrent = {};
|
||||
}
|
||||
|
||||
initialize: function() {},
|
||||
window.qBittorrent.PropWebseeds = (function() {
|
||||
const exports = function() {
|
||||
return {
|
||||
updateData: updateData
|
||||
};
|
||||
};
|
||||
|
||||
setup: function(table) {
|
||||
this.table = $(table);
|
||||
this.rows = new Hash();
|
||||
},
|
||||
const webseedsDynTable = new Class({
|
||||
|
||||
removeRow: function(url) {
|
||||
if (this.rows.has(url)) {
|
||||
const tr = this.rows.get(url);
|
||||
tr.dispose();
|
||||
this.rows.erase(url);
|
||||
initialize: function() {},
|
||||
|
||||
setup: function(table) {
|
||||
this.table = $(table);
|
||||
this.rows = new Hash();
|
||||
},
|
||||
|
||||
removeRow: function(url) {
|
||||
if (this.rows.has(url)) {
|
||||
const tr = this.rows.get(url);
|
||||
tr.dispose();
|
||||
this.rows.erase(url);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
removeAllRows: function() {
|
||||
this.rows.each(function(tr, url) {
|
||||
this.removeRow(url);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
updateRow: function(tr, row) {
|
||||
const tds = tr.getElements('td');
|
||||
for (let i = 0; i < row.length; ++i) {
|
||||
tds[i].set('html', row[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
||||
removeAllRows: function() {
|
||||
this.rows.each(function(tr, url) {
|
||||
this.removeRow(url);
|
||||
}.bind(this));
|
||||
},
|
||||
insertRow: function(row) {
|
||||
const url = row[0];
|
||||
if (this.rows.has(url)) {
|
||||
const tableRow = this.rows.get(url);
|
||||
this.updateRow(tableRow, row);
|
||||
return;
|
||||
}
|
||||
//this.removeRow(id);
|
||||
const tr = new Element('tr');
|
||||
this.rows.set(url, tr);
|
||||
for (let i = 0; i < row.length; ++i) {
|
||||
const td = new Element('td');
|
||||
td.set('html', row[i]);
|
||||
td.injectInside(tr);
|
||||
}
|
||||
tr.injectInside(this.table);
|
||||
},
|
||||
});
|
||||
|
||||
updateRow: function(tr, row) {
|
||||
const tds = tr.getElements('td');
|
||||
for (let i = 0; i < row.length; ++i) {
|
||||
tds[i].set('html', row[i]);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
let current_hash = "";
|
||||
|
||||
insertRow: function(row) {
|
||||
const url = row[0];
|
||||
if (this.rows.has(url)) {
|
||||
const tableRow = this.rows.get(url);
|
||||
this.updateRow(tableRow, row);
|
||||
let loadWebSeedsDataTimer;
|
||||
const loadWebSeedsData = function() {
|
||||
if ($('prop_webseeds').hasClass('invisible')
|
||||
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
|
||||
// Tab changed, don't do anything
|
||||
return;
|
||||
}
|
||||
//this.removeRow(id);
|
||||
const tr = new Element('tr');
|
||||
this.rows.set(url, tr);
|
||||
for (let i = 0; i < row.length; ++i) {
|
||||
const td = new Element('td');
|
||||
td.set('html', row[i]);
|
||||
td.injectInside(tr);
|
||||
}
|
||||
tr.injectInside(this.table);
|
||||
},
|
||||
});
|
||||
|
||||
this.current_hash = "";
|
||||
|
||||
let loadWebSeedsDataTimer;
|
||||
const loadWebSeedsData = function() {
|
||||
if ($('prop_webseeds').hasClass('invisible')
|
||||
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
|
||||
// Tab changed, don't do anything
|
||||
return;
|
||||
}
|
||||
const new_hash = torrentsTable.getCurrentTorrentHash();
|
||||
if (new_hash === "") {
|
||||
wsTable.removeAllRows();
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
|
||||
return;
|
||||
}
|
||||
if (new_hash != current_hash) {
|
||||
wsTable.removeAllRows();
|
||||
current_hash = new_hash;
|
||||
}
|
||||
const url = new URI('api/v2/torrents/webseeds?hash=' + current_hash);
|
||||
new Request.JSON({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'get',
|
||||
onFailure: function() {
|
||||
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsDataTimer = loadWebSeedsData.delay(20000);
|
||||
},
|
||||
onSuccess: function(webseeds) {
|
||||
$('error_div').set('html', '');
|
||||
if (webseeds) {
|
||||
// Update WebSeeds data
|
||||
webseeds.each(function(webseed) {
|
||||
const row = [];
|
||||
row.length = 1;
|
||||
row[0] = webseed.url;
|
||||
wsTable.insertRow(row);
|
||||
});
|
||||
}
|
||||
else {
|
||||
wsTable.removeAllRows();
|
||||
}
|
||||
const new_hash = torrentsTable.getCurrentTorrentHash();
|
||||
if (new_hash === "") {
|
||||
wsTable.removeAllRows();
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
|
||||
return;
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
if (new_hash != current_hash) {
|
||||
wsTable.removeAllRows();
|
||||
current_hash = new_hash;
|
||||
}
|
||||
const url = new URI('api/v2/torrents/webseeds?hash=' + current_hash);
|
||||
new Request.JSON({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'get',
|
||||
onFailure: function() {
|
||||
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsDataTimer = loadWebSeedsData.delay(20000);
|
||||
},
|
||||
onSuccess: function(webseeds) {
|
||||
$('error_div').set('html', '');
|
||||
if (webseeds) {
|
||||
// Update WebSeeds data
|
||||
webseeds.each(function(webseed) {
|
||||
const row = [];
|
||||
row.length = 1;
|
||||
row[0] = webseed.url;
|
||||
wsTable.insertRow(row);
|
||||
});
|
||||
}
|
||||
else {
|
||||
wsTable.removeAllRows();
|
||||
}
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
updateWebSeedsData = function() {
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsData();
|
||||
};
|
||||
const updateData = function() {
|
||||
clearTimeout(loadWebSeedsDataTimer);
|
||||
loadWebSeedsData();
|
||||
};
|
||||
|
||||
const wsTable = new webseedsDynTable();
|
||||
wsTable.setup($('webseedsTable'));
|
||||
const wsTable = new webseedsDynTable();
|
||||
wsTable.setup($('webseedsTable'));
|
||||
|
||||
return exports();
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue