mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-09 17:12:31 -06: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:
@@ -681,22 +681,24 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
$('qbittorrentVersion').innerText = ("qBittorrent " + qbtVersion()
|
||||
(function() {
|
||||
$('qbittorrentVersion').innerText = ("qBittorrent " + qbtVersion()
|
||||
+ " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
|
||||
|
||||
new Request.JSON({
|
||||
url: 'api/v2/app/buildInfo',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: function(info) {
|
||||
if (!info) return;
|
||||
new Request.JSON({
|
||||
url: 'api/v2/app/buildInfo',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: function(info) {
|
||||
if (!info) return;
|
||||
|
||||
$('qtVersion').textContent = info.qt;
|
||||
$('libtorrentVersion').textContent = info.libtorrent;
|
||||
$('boostVersion').textContent = info.boost;
|
||||
$('opensslVersion').textContent = info.openssl;
|
||||
$('zlibVersion').textContent = info.zlib;
|
||||
$('qbittorrentVersion').textContent += " (" + info.bitness + "-bit)";
|
||||
}
|
||||
}).send();
|
||||
$('qtVersion').textContent = info.qt;
|
||||
$('libtorrentVersion').textContent = info.libtorrent;
|
||||
$('boostVersion').textContent = info.boost;
|
||||
$('opensslVersion').textContent = info.openssl;
|
||||
$('zlibVersion').textContent = info.zlib;
|
||||
$('qbittorrentVersion').textContent += " (" + info.bitness + "-bit)";
|
||||
}
|
||||
}).send();
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -13,35 +13,37 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
MochaUI.initializeTabs('aboutTabs');
|
||||
(function() {
|
||||
MochaUI.initializeTabs('aboutTabs');
|
||||
|
||||
$('aboutAboutLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutAboutContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutAboutLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutAboutContent').removeClass('invisible');
|
||||
});
|
||||
|
||||
$('aboutAuthorLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutAuthorContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutAuthorLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutAuthorContent').removeClass('invisible');
|
||||
});
|
||||
|
||||
$('aboutSpecialThanksLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutSpecialThanksContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutSpecialThanksLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutSpecialThanksContent').removeClass('invisible');
|
||||
});
|
||||
|
||||
$('aboutTranslatorsLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutTranslatorsContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutTranslatorsLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutTranslatorsContent').removeClass('invisible');
|
||||
});
|
||||
|
||||
$('aboutLicenseLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutLicenseContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutLicenseLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutLicenseContent').removeClass('invisible');
|
||||
});
|
||||
|
||||
$('aboutLibrariesLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutLibrariesContent').removeClass('invisible');
|
||||
});
|
||||
$('aboutLibrariesLink').addEvent('click', function() {
|
||||
$$('.aboutTabContent').addClass('invisible');
|
||||
$('aboutLibrariesContent').removeClass('invisible');
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -32,79 +32,94 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const categoriesFilterContextMenu = new CategoriesFilterContextMenu({
|
||||
targets: '.categoriesFilterContextMenuTarget',
|
||||
menu: 'categoriesFilterMenu',
|
||||
actions: {
|
||||
createCategory: function(element, ref) {
|
||||
createCategoryFN();
|
||||
if (window.qBittorrent === undefined) {
|
||||
window.qBittorrent = {};
|
||||
}
|
||||
|
||||
window.qBittorrent.Filters = (function() {
|
||||
const exports = function() {
|
||||
return {
|
||||
categoriesFilterContextMenu: categoriesFilterContextMenu,
|
||||
tagsFilterContextMenu: tagsFilterContextMenu
|
||||
};
|
||||
};
|
||||
|
||||
const categoriesFilterContextMenu = new window.qBittorrent.ContextMenu.CategoriesFilterContextMenu({
|
||||
targets: '.categoriesFilterContextMenuTarget',
|
||||
menu: 'categoriesFilterMenu',
|
||||
actions: {
|
||||
createCategory: function(element, ref) {
|
||||
createCategoryFN();
|
||||
},
|
||||
editCategory: function(element, ref) {
|
||||
editCategoryFN(element.id);
|
||||
},
|
||||
deleteCategory: function(element, ref) {
|
||||
removeCategoryFN(element.id);
|
||||
},
|
||||
deleteUnusedCategories: function(element, ref) {
|
||||
deleteUnusedCategoriesFN();
|
||||
},
|
||||
startTorrentsByCategory: function(element, ref) {
|
||||
startTorrentsByCategoryFN(element.id);
|
||||
},
|
||||
pauseTorrentsByCategory: function(element, ref) {
|
||||
pauseTorrentsByCategoryFN(element.id);
|
||||
},
|
||||
deleteTorrentsByCategory: function(element, ref) {
|
||||
deleteTorrentsByCategoryFN(element.id);
|
||||
}
|
||||
},
|
||||
editCategory: function(element, ref) {
|
||||
editCategoryFN(element.id);
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
},
|
||||
deleteCategory: function(element, ref) {
|
||||
removeCategoryFN(element.id);
|
||||
},
|
||||
deleteUnusedCategories: function(element, ref) {
|
||||
deleteUnusedCategoriesFN();
|
||||
},
|
||||
startTorrentsByCategory: function(element, ref) {
|
||||
startTorrentsByCategoryFN(element.id);
|
||||
},
|
||||
pauseTorrentsByCategory: function(element, ref) {
|
||||
pauseTorrentsByCategoryFN(element.id);
|
||||
},
|
||||
deleteTorrentsByCategory: function(element, ref) {
|
||||
deleteTorrentsByCategoryFN(element.id);
|
||||
onShow: function() {
|
||||
this.options.element.firstChild.click();
|
||||
}
|
||||
},
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
},
|
||||
onShow: function() {
|
||||
this.options.element.firstChild.click();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const tagsFilterContextMenu = new TagsFilterContextMenu({
|
||||
targets: '.tagsFilterContextMenuTarget',
|
||||
menu: 'tagsFilterMenu',
|
||||
actions: {
|
||||
createTag: function(element, ref) {
|
||||
createTagFN();
|
||||
const tagsFilterContextMenu = new window.qBittorrent.ContextMenu.TagsFilterContextMenu({
|
||||
targets: '.tagsFilterContextMenuTarget',
|
||||
menu: 'tagsFilterMenu',
|
||||
actions: {
|
||||
createTag: function(element, ref) {
|
||||
createTagFN();
|
||||
},
|
||||
deleteTag: function(element, ref) {
|
||||
removeTagFN(element.id);
|
||||
},
|
||||
deleteUnusedTags: function(element, ref) {
|
||||
deleteUnusedTagsFN();
|
||||
},
|
||||
startTorrentsByTag: function(element, ref) {
|
||||
startTorrentsByTagFN(element.id);
|
||||
},
|
||||
pauseTorrentsByTag: function(element, ref) {
|
||||
pauseTorrentsByTagFN(element.id);
|
||||
},
|
||||
deleteTorrentsByTag: function(element, ref) {
|
||||
deleteTorrentsByTagFN(element.id);
|
||||
}
|
||||
},
|
||||
deleteTag: function(element, ref) {
|
||||
removeTagFN(element.id);
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
},
|
||||
deleteUnusedTags: function(element, ref) {
|
||||
deleteUnusedTagsFN();
|
||||
},
|
||||
startTorrentsByTag: function(element, ref) {
|
||||
startTorrentsByTagFN(element.id);
|
||||
},
|
||||
pauseTorrentsByTag: function(element, ref) {
|
||||
pauseTorrentsByTagFN(element.id);
|
||||
},
|
||||
deleteTorrentsByTag: function(element, ref) {
|
||||
deleteTorrentsByTagFN(element.id);
|
||||
onShow: function() {
|
||||
this.options.element.firstChild.click();
|
||||
}
|
||||
},
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
},
|
||||
onShow: function() {
|
||||
this.options.element.firstChild.click();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (LocalPreferences.get('filter_status_collapsed') === "true")
|
||||
toggleFilterDisplay('status');
|
||||
if (LocalPreferences.get('filter_status_collapsed') === "true")
|
||||
toggleFilterDisplay('status');
|
||||
|
||||
if (LocalPreferences.get('filter_category_collapsed') === "true")
|
||||
toggleFilterDisplay('category');
|
||||
if (LocalPreferences.get('filter_category_collapsed') === "true")
|
||||
toggleFilterDisplay('category');
|
||||
|
||||
if (LocalPreferences.get('filter_tag_collapsed') === "true")
|
||||
toggleFilterDisplay('tag');
|
||||
if (LocalPreferences.get('filter_tag_collapsed') === "true")
|
||||
toggleFilterDisplay('tag');
|
||||
|
||||
return exports();
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<div>
|
||||
<input type="text" id="newPluginPath" placeholder="QBT_TR(URL or local directory)QBT_TR[CONTEXT=PluginSourceDlg]" autocorrect="off" autocapitalize="none" />
|
||||
<div style="margin-top: 10px; text-align: center;">
|
||||
<button id="newPluginCancel" onclick="closeSearchWindow('installSearchPlugin');">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button>
|
||||
<button id="newPluginOk" onclick="newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button>
|
||||
<button id="newPluginCancel" onclick="qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button>
|
||||
<button id="newPluginOk" onclick="qBittorrent.InstallSearchPlugin.newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,41 +29,55 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
this.initInstallSearchPlugin = function() {
|
||||
new Keyboard({
|
||||
defaultEventType: 'keydown',
|
||||
events: {
|
||||
'Enter': function(e) {
|
||||
// accept enter key as a click
|
||||
new Event(e).stop();
|
||||
if (window.qBittorrent === undefined) {
|
||||
window.qBittorrent = {};
|
||||
}
|
||||
|
||||
const elem = e.event.srcElement;
|
||||
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))
|
||||
newPluginOk();
|
||||
else if (elem.id === "newPluginCancel")
|
||||
closeSearchWindow('installSearchPlugin');
|
||||
window.qBittorrent.InstallSearchPlugin = (function() {
|
||||
const exports = function() {
|
||||
return {
|
||||
newPluginOk: newPluginOk
|
||||
};
|
||||
};
|
||||
|
||||
const init = function() {
|
||||
new Keyboard({
|
||||
defaultEventType: 'keydown',
|
||||
events: {
|
||||
'Enter': function(e) {
|
||||
// accept enter key as a click
|
||||
new Event(e).stop();
|
||||
|
||||
const elem = e.event.srcElement;
|
||||
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))
|
||||
newPluginOk();
|
||||
else if (elem.id === "newPluginCancel")
|
||||
window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
|
||||
}
|
||||
}
|
||||
}
|
||||
}).activate();
|
||||
}).activate();
|
||||
|
||||
$('newPluginPath').select();
|
||||
};
|
||||
$('newPluginPath').select();
|
||||
};
|
||||
|
||||
this.newPluginOk = function() {
|
||||
const path = $("newPluginPath").get("value").trim();
|
||||
if (path)
|
||||
new Request({
|
||||
url: 'api/v2/search/installPlugin',
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
sources: path,
|
||||
},
|
||||
onRequest: function() {
|
||||
closeSearchWindow('installSearchPlugin');
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
const newPluginOk = function() {
|
||||
const path = $("newPluginPath").get("value").trim();
|
||||
if (path)
|
||||
new Request({
|
||||
url: 'api/v2/search/installPlugin',
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
sources: path,
|
||||
},
|
||||
onRequest: function() {
|
||||
window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
initInstallSearchPlugin();
|
||||
init();
|
||||
|
||||
return exports();
|
||||
})();
|
||||
</script>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,31 +14,33 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
// Tabs
|
||||
MochaUI.initializeTabs('preferencesTabs');
|
||||
(function() {
|
||||
// Tabs
|
||||
MochaUI.initializeTabs('preferencesTabs');
|
||||
|
||||
$('PrefDownloadsLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('DownloadsTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefConnectionLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('ConnectionTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefSpeedLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('SpeedTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefBittorrentLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('BittorrentTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefWebUILink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('WebUITab').removeClass('invisible');
|
||||
});
|
||||
$('PrefAdvancedLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('AdvancedTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefDownloadsLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('DownloadsTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefConnectionLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('ConnectionTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefSpeedLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('SpeedTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefBittorrentLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('BittorrentTab').removeClass('invisible');
|
||||
});
|
||||
$('PrefWebUILink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('WebUITab').removeClass('invisible');
|
||||
});
|
||||
$('PrefAdvancedLink').addEvent('click', function(e) {
|
||||
$$('.PrefTab').addClass('invisible');
|
||||
$('AdvancedTab').removeClass('invisible');
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -155,7 +155,9 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const selectedTab = $(LocalPreferences.get('selected_tab', 'PropGeneralLink'));
|
||||
if (selectedTab)
|
||||
selectedTab.click();
|
||||
(function() {
|
||||
const selectedTab = $(LocalPreferences.get('selected_tab', 'PropGeneralLink'));
|
||||
if (selectedTab)
|
||||
selectedTab.click();
|
||||
})();
|
||||
</script>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -65,9 +65,9 @@
|
||||
<span>QBT_TR(Warning: Be sure to comply with your country's copyright laws when downloading torrents from any of these search engines.)QBT_TR[CONTEXT=PluginSelectDlg]</span>
|
||||
<span style="font-style: italic;">QBT_TR(You can get new search engine plugins here:)QBT_TR[CONTEXT=PluginSelectDlg] <a href="http://plugins.qbittorrent.org" target="_blank">http://plugins.qbittorrent.org</a></span>
|
||||
<div style="width: 100%; margin-top: 10px;">
|
||||
<button style="width: 33%; line-height: 1.4em;" onclick="installPlugin();">QBT_TR(Install new plugin)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
<button style="width: 33%; line-height: 1.4em;" onclick="checkForUpdates();">QBT_TR(Check for updates)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
<button style="width: 32%; line-height: 1.4em;" onclick="closeSearchWindow('searchPlugins');">QBT_TR(Close)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
<button style="width: 33%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.installPlugin();">QBT_TR(Install new plugin)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
<button style="width: 33%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.checkForUpdates();">QBT_TR(Check for updates)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
<button style="width: 32%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.closeSearchWindow('searchPlugins');">QBT_TR(Close)QBT_TR[CONTEXT=PluginSelectDlg]</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -79,142 +79,161 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
this.searchPluginsTableContextMenu = undefined;
|
||||
this.prevOffsetLeft = undefined;
|
||||
this.prevOffsetTop = undefined;
|
||||
if (window.qBittorrent === undefined) {
|
||||
window.qBittorrent = {};
|
||||
}
|
||||
|
||||
this.initSearchPlugins = function() {
|
||||
searchPluginsTableContextMenu = new SearchPluginsTableContextMenu({
|
||||
targets: '.searchPluginsTableRow',
|
||||
menu: 'searchPluginsTableMenu',
|
||||
actions: {
|
||||
Enabled: enablePlugin,
|
||||
Uninstall: uninstallPlugin
|
||||
},
|
||||
offsets: calculateContextMenuOffsets()
|
||||
});
|
||||
searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu);
|
||||
updateSearchPluginsTable();
|
||||
};
|
||||
|
||||
this.closeSearchWindow = function(id) {
|
||||
window.parent.MochaUI.closeWindow(window.parent.$(id));
|
||||
};
|
||||
|
||||
this.installPlugin = function(path) {
|
||||
new MochaUI.Window({
|
||||
id: 'installSearchPlugin',
|
||||
title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
|
||||
loadMethod: 'xhr',
|
||||
contentURL: 'views/installsearchplugin.html',
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
width: 500,
|
||||
height: 120
|
||||
});
|
||||
};
|
||||
|
||||
this.uninstallPlugin = function() {
|
||||
const plugins = searchPluginsTable.selectedRowsIds().join('|');
|
||||
const url = new URI('api/v2/search/uninstallPlugin');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
names: plugins,
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
this.enablePlugin = function() {
|
||||
const plugins = searchPluginsTable.selectedRowsIds();
|
||||
let enable = true;
|
||||
if (plugins && plugins.length)
|
||||
enable = !getPlugin(plugins[0]).enabled;
|
||||
|
||||
const url = new URI('api/v2/search/enablePlugin');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
names: plugins.join('|'),
|
||||
enable: enable
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
this.checkForUpdates = function() {
|
||||
const url = new URI('api/v2/search/updatePlugins');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post'
|
||||
}).send();
|
||||
};
|
||||
|
||||
this.calculateContextMenuOffsets = function() {
|
||||
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
|
||||
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
|
||||
|
||||
return {
|
||||
x: -(prevOffsetLeft + 20),
|
||||
y: -(prevOffsetTop + 2)
|
||||
window.qBittorrent.SearchPlugins = (function() {
|
||||
const exports = function() {
|
||||
return {
|
||||
closeSearchWindow: closeSearchWindow,
|
||||
installPlugin: installPlugin,
|
||||
checkForUpdates: checkForUpdates,
|
||||
updateTable: updateTable
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
this.updateSearchPluginsTableContextMenuOffset = function() {
|
||||
// only re-calculate if window has moved
|
||||
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
|
||||
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
|
||||
};
|
||||
let searchPluginsTable;
|
||||
let searchPluginsTableContextMenu;
|
||||
let prevOffsetLeft;
|
||||
let prevOffsetTop;
|
||||
|
||||
this.setupSearchPluginTableEvents = function(enable) {
|
||||
if (enable)
|
||||
$$(".searchPluginsTableRow").each(function(target) {
|
||||
target.addEventListener('dblclick', enablePlugin, false);
|
||||
target.addEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
|
||||
const initSearchPlugins = function() {
|
||||
searchPluginsTable = new window.qBittorrent.DynamicTable.SearchPluginsTable();
|
||||
searchPluginsTableContextMenu = new window.qBittorrent.ContextMenu.SearchPluginsTableContextMenu({
|
||||
targets: '.searchPluginsTableRow',
|
||||
menu: 'searchPluginsTableMenu',
|
||||
actions: {
|
||||
Enabled: enablePlugin,
|
||||
Uninstall: uninstallPlugin
|
||||
},
|
||||
offsets: calculateContextMenuOffsets()
|
||||
});
|
||||
else
|
||||
$$(".searchPluginsTableRow").each(function(target) {
|
||||
target.removeEventListener('dblclick', enablePlugin, false);
|
||||
target.removeEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
|
||||
searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu);
|
||||
updateTable();
|
||||
};
|
||||
|
||||
const closeSearchWindow = function(id) {
|
||||
window.parent.MochaUI.closeWindow(window.parent.$(id));
|
||||
};
|
||||
|
||||
const installPlugin = function(path) {
|
||||
new MochaUI.Window({
|
||||
id: 'installSearchPlugin',
|
||||
title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
|
||||
loadMethod: 'xhr',
|
||||
contentURL: 'views/installsearchplugin.html',
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
width: 500,
|
||||
height: 120
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
this.updateSearchPluginsTable = function() {
|
||||
// clear event listeners
|
||||
setupSearchPluginTableEvents(false);
|
||||
|
||||
const oldPlugins = Object.keys(searchPluginsTable.rows);
|
||||
// remove old rows from the table
|
||||
for (let i = 0; i < oldPlugins.length; ++i) {
|
||||
let found = false;
|
||||
for (let j = 0; j < searchPlugins.length; ++j) {
|
||||
if (searchPlugins[j].name === oldPlugins[i]) {
|
||||
found = true;
|
||||
break;
|
||||
const uninstallPlugin = function() {
|
||||
const plugins = searchPluginsTable.selectedRowsIds().join('|');
|
||||
const url = new URI('api/v2/search/uninstallPlugin');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
names: plugins,
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
const enablePlugin = function() {
|
||||
const plugins = searchPluginsTable.selectedRowsIds();
|
||||
let enable = true;
|
||||
if (plugins && plugins.length)
|
||||
enable = !window.qBittorrent.Search.getPlugin(plugins[0]).enabled;
|
||||
|
||||
const url = new URI('api/v2/search/enablePlugin');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post',
|
||||
data: {
|
||||
names: plugins.join('|'),
|
||||
enable: enable
|
||||
}
|
||||
}).send();
|
||||
};
|
||||
|
||||
const checkForUpdates = function() {
|
||||
const url = new URI('api/v2/search/updatePlugins');
|
||||
new Request({
|
||||
url: url,
|
||||
noCache: true,
|
||||
method: 'post'
|
||||
}).send();
|
||||
};
|
||||
|
||||
const calculateContextMenuOffsets = function() {
|
||||
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
|
||||
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
|
||||
|
||||
return {
|
||||
x: -(prevOffsetLeft + 20),
|
||||
y: -(prevOffsetTop + 2)
|
||||
};
|
||||
};
|
||||
|
||||
const updateSearchPluginsTableContextMenuOffset = function() {
|
||||
// only re-calculate if window has moved
|
||||
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
|
||||
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
|
||||
};
|
||||
|
||||
const setupSearchPluginTableEvents = function(enable) {
|
||||
if (enable)
|
||||
$$(".searchPluginsTableRow").each(function(target) {
|
||||
target.addEventListener('dblclick', enablePlugin, false);
|
||||
target.addEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
|
||||
});
|
||||
else
|
||||
$$(".searchPluginsTableRow").each(function(target) {
|
||||
target.removeEventListener('dblclick', enablePlugin, false);
|
||||
target.removeEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
|
||||
});
|
||||
};
|
||||
|
||||
const updateTable = function() {
|
||||
// clear event listeners
|
||||
setupSearchPluginTableEvents(false);
|
||||
|
||||
const oldPlugins = Object.keys(searchPluginsTable.rows);
|
||||
// remove old rows from the table
|
||||
for (let i = 0; i < oldPlugins.length; ++i) {
|
||||
let found = false;
|
||||
for (let j = 0; j < window.qBittorrent.Search.searchPlugins.length; ++j) {
|
||||
if (window.qBittorrent.Search.searchPlugins[j].name === oldPlugins[i]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
searchPluginsTable.removeRow(oldPlugins[i]);
|
||||
}
|
||||
if (!found)
|
||||
searchPluginsTable.removeRow(oldPlugins[i]);
|
||||
}
|
||||
|
||||
for (let i = 0; i < searchPlugins.length; ++i) {
|
||||
searchPlugins[i].rowId = searchPlugins[i].name;
|
||||
searchPluginsTable.updateRowData(searchPlugins[i]);
|
||||
}
|
||||
for (let i = 0; i < window.qBittorrent.Search.searchPlugins.length; ++i) {
|
||||
window.qBittorrent.Search.searchPlugins[i].rowId = window.qBittorrent.Search.searchPlugins[i].name;
|
||||
searchPluginsTable.updateRowData(window.qBittorrent.Search.searchPlugins[i]);
|
||||
}
|
||||
|
||||
searchPluginsTable.updateTable();
|
||||
searchPluginsTable.altRow();
|
||||
searchPluginsTable.updateTable();
|
||||
searchPluginsTable.altRow();
|
||||
|
||||
// add event listeners
|
||||
setupSearchPluginTableEvents(true);
|
||||
};
|
||||
// add event listeners
|
||||
setupSearchPluginTableEvents(true);
|
||||
};
|
||||
|
||||
initSearchPlugins();
|
||||
initSearchPlugins();
|
||||
|
||||
return exports();
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -18,81 +18,95 @@
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
//create a context menu
|
||||
const torrentsTableContextMenu = new TorrentsTableContextMenu({
|
||||
targets: '.torrentsTableContextMenuTarget',
|
||||
menu: 'torrentsTableMenu',
|
||||
actions: {
|
||||
start: function(element, ref) {
|
||||
startFN();
|
||||
},
|
||||
pause: function(element, ref) {
|
||||
pauseFN();
|
||||
},
|
||||
forceStart: function(element, ref) {
|
||||
setForceStartFN();
|
||||
},
|
||||
if (window.qBittorrent === undefined) {
|
||||
window.qBittorrent = {};
|
||||
}
|
||||
|
||||
delete: function(element, ref) {
|
||||
deleteFN();
|
||||
},
|
||||
window.qBittorrent.TransferList = (function() {
|
||||
const exports = function() {
|
||||
return {
|
||||
contextMenu: contextMenu,
|
||||
};
|
||||
};
|
||||
|
||||
setLocation: function(element, ref) {
|
||||
setLocationFN();
|
||||
},
|
||||
//create a context menu
|
||||
const contextMenu = new window.qBittorrent.ContextMenu.TorrentsTableContextMenu({
|
||||
targets: '.torrentsTableContextMenuTarget',
|
||||
menu: 'torrentsTableMenu',
|
||||
actions: {
|
||||
start: function(element, ref) {
|
||||
startFN();
|
||||
},
|
||||
pause: function(element, ref) {
|
||||
pauseFN();
|
||||
},
|
||||
forceStart: function(element, ref) {
|
||||
setForceStartFN();
|
||||
},
|
||||
|
||||
rename: function(element, ref) {
|
||||
renameFN();
|
||||
},
|
||||
queueTop: function(element, ref) {
|
||||
setQueuePositionFN('topPrio');
|
||||
},
|
||||
queueUp: function(element, ref) {
|
||||
setQueuePositionFN('increasePrio');
|
||||
},
|
||||
queueDown: function(element, ref) {
|
||||
setQueuePositionFN('decreasePrio');
|
||||
},
|
||||
queueBottom: function(element, ref) {
|
||||
setQueuePositionFN('bottomPrio');
|
||||
},
|
||||
delete: function(element, ref) {
|
||||
deleteFN();
|
||||
},
|
||||
|
||||
downloadLimit: function(element, ref) {
|
||||
downloadLimitFN();
|
||||
},
|
||||
uploadLimit: function(element, ref) {
|
||||
uploadLimitFN();
|
||||
},
|
||||
shareRatio: function(element, ref) {
|
||||
shareRatioFN();
|
||||
},
|
||||
setLocation: function(element, ref) {
|
||||
setLocationFN();
|
||||
},
|
||||
|
||||
sequentialDownload: function(element, ref) {
|
||||
toggleSequentialDownloadFN();
|
||||
},
|
||||
firstLastPiecePrio: function(element, ref) {
|
||||
toggleFirstLastPiecePrioFN();
|
||||
},
|
||||
rename: function(element, ref) {
|
||||
renameFN();
|
||||
},
|
||||
queueTop: function(element, ref) {
|
||||
setQueuePositionFN('topPrio');
|
||||
},
|
||||
queueUp: function(element, ref) {
|
||||
setQueuePositionFN('increasePrio');
|
||||
},
|
||||
queueDown: function(element, ref) {
|
||||
setQueuePositionFN('decreasePrio');
|
||||
},
|
||||
queueBottom: function(element, ref) {
|
||||
setQueuePositionFN('bottomPrio');
|
||||
},
|
||||
|
||||
autoTorrentManagement: function(element, ref) {
|
||||
autoTorrentManagementFN();
|
||||
},
|
||||
forceRecheck: function(element, ref) {
|
||||
recheckFN();
|
||||
},
|
||||
forceReannounce: function(element, ref) {
|
||||
reannounceFN();
|
||||
},
|
||||
downloadLimit: function(element, ref) {
|
||||
downloadLimitFN();
|
||||
},
|
||||
uploadLimit: function(element, ref) {
|
||||
uploadLimitFN();
|
||||
},
|
||||
shareRatio: function(element, ref) {
|
||||
shareRatioFN();
|
||||
},
|
||||
|
||||
superSeeding: function(element, ref) {
|
||||
setSuperSeedingFN(!ref.getItemChecked('superSeeding'));
|
||||
sequentialDownload: function(element, ref) {
|
||||
toggleSequentialDownloadFN();
|
||||
},
|
||||
firstLastPiecePrio: function(element, ref) {
|
||||
toggleFirstLastPiecePrioFN();
|
||||
},
|
||||
|
||||
autoTorrentManagement: function(element, ref) {
|
||||
autoTorrentManagementFN();
|
||||
},
|
||||
forceRecheck: function(element, ref) {
|
||||
recheckFN();
|
||||
},
|
||||
forceReannounce: function(element, ref) {
|
||||
reannounceFN();
|
||||
},
|
||||
|
||||
superSeeding: function(element, ref) {
|
||||
setSuperSeedingFN(!ref.getItemChecked('superSeeding'));
|
||||
}
|
||||
},
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
}
|
||||
},
|
||||
offsets: {
|
||||
x: -15,
|
||||
y: 2
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
torrentsTable.setup('torrentsTableDiv', 'torrentsTableFixedHeaderDiv', torrentsTableContextMenu);
|
||||
torrentsTable.setup('torrentsTableDiv', 'torrentsTableFixedHeaderDiv', contextMenu);
|
||||
|
||||
return exports();
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user