2019-08-02 10:09:36 +00:00
|
|
|
/*
|
|
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
|
|
|
Copyright © 2011 Center for History and New Media
|
|
|
|
George Mason University, Fairfax, Virginia, USA
|
|
|
|
http://zotero.org
|
|
|
|
|
|
|
|
This file is part of Zotero.
|
|
|
|
|
|
|
|
Zotero is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Zotero is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2024-03-02 07:51:55 +00:00
|
|
|
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
Services.scriptloader.loadSubScript("chrome://zotero/content/include.js", this);
|
|
|
|
Services.scriptloader.loadSubScript("chrome://zotero/content/customElements.js", this);
|
|
|
|
|
|
|
|
var Scaffold_Load = new function () {
|
2022-06-08 22:16:50 +00:00
|
|
|
this.onLoad = async function () {
|
|
|
|
document.addEventListener('dialogaccept', () => this.accept());
|
|
|
|
|
2019-08-02 10:09:36 +00:00
|
|
|
var listitem, translator, listcell, set;
|
|
|
|
var listbox = document.getElementById("listbox");
|
2019-08-10 12:40:01 +00:00
|
|
|
|
|
|
|
listbox.addEventListener('dblclick', () => {
|
2022-06-08 22:16:50 +00:00
|
|
|
var translatorID = document.getElementById("listbox").selectedItem.dataset.zoteroID;
|
2019-08-10 12:40:01 +00:00
|
|
|
if (!translatorID) return;
|
|
|
|
this.accept();
|
|
|
|
window.close();
|
|
|
|
});
|
|
|
|
|
2022-11-01 20:05:17 +00:00
|
|
|
listbox.addEventListener('keypress', (e) => {
|
|
|
|
if (e.key == ' ' && e.target == listbox) {
|
2022-08-30 14:07:15 +00:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-02 07:51:55 +00:00
|
|
|
var translators = {};
|
2019-08-02 10:09:36 +00:00
|
|
|
|
2024-03-02 07:51:55 +00:00
|
|
|
// Get the matching translators
|
2019-08-02 10:09:36 +00:00
|
|
|
var translatorProvider = window.arguments[0].translatorProvider;
|
|
|
|
var url = window.arguments[0].url;
|
2024-03-02 07:51:55 +00:00
|
|
|
var rootUrl = window.arguments[0].rootUrl;
|
2019-08-02 10:09:36 +00:00
|
|
|
url = Zotero.Proxies.proxyToProper(url);
|
2022-06-08 22:16:50 +00:00
|
|
|
translators["Matching Translators"] = (await translatorProvider.getWebTranslatorsForLocation(url, rootUrl))[0];
|
|
|
|
translators["Web Translators"] = (await translatorProvider.getAllForType("web"))
|
2019-08-02 10:09:36 +00:00
|
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
2022-06-08 22:16:50 +00:00
|
|
|
translators["Import Translators"] = (await translatorProvider.getAllForType("import"))
|
2019-08-02 10:09:36 +00:00
|
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
2022-06-08 22:16:50 +00:00
|
|
|
translators["Export Translators"] = (await translatorProvider.getAllForType("export"))
|
2021-12-29 01:32:56 +00:00
|
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
2022-06-08 22:16:50 +00:00
|
|
|
translators["Search Translators"] = (await translatorProvider.getAllForType("search"))
|
2021-12-29 01:32:56 +00:00
|
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
2019-08-02 10:09:36 +00:00
|
|
|
|
|
|
|
for (set in translators) {
|
|
|
|
// Make a separator
|
2022-06-08 22:16:50 +00:00
|
|
|
listitem = document.createXULElement("richlistitem");
|
2019-08-02 10:09:36 +00:00
|
|
|
listitem.setAttribute("disabled", true);
|
2022-06-08 22:16:50 +00:00
|
|
|
// Need to set this to disable up/down keys selecting:
|
|
|
|
listitem.style.MozUserInput = 'none';
|
|
|
|
listitem.append(set);
|
2019-08-02 10:09:36 +00:00
|
|
|
listbox.appendChild(listitem);
|
2024-03-02 07:51:55 +00:00
|
|
|
for (var j = 0; j < translators[set].length; j++) {
|
|
|
|
translator = translators[set][j];
|
2022-06-08 22:16:50 +00:00
|
|
|
listitem = document.createXULElement("richlistitem");
|
|
|
|
// set search label for type-to-find functionality. This is not displayed.
|
|
|
|
listitem.searchLabel = translator.label;
|
2019-08-02 10:09:36 +00:00
|
|
|
// And the ID goes in DOM user data
|
2022-06-08 22:16:50 +00:00
|
|
|
listitem.dataset.zoteroID = translator.translatorID;
|
2019-08-02 10:09:36 +00:00
|
|
|
|
2022-06-08 22:16:50 +00:00
|
|
|
listcell = document.createXULElement("hbox");
|
|
|
|
listcell.setAttribute('flex', '1');
|
|
|
|
listcell.append(translator.label);
|
2019-08-02 10:09:36 +00:00
|
|
|
listitem.appendChild(listcell);
|
|
|
|
|
|
|
|
listbox.appendChild(listitem);
|
|
|
|
}
|
|
|
|
}
|
2022-06-08 22:16:50 +00:00
|
|
|
};
|
2019-08-02 10:09:36 +00:00
|
|
|
|
|
|
|
this.accept = function () {
|
2022-06-08 22:16:50 +00:00
|
|
|
var translatorID = document.getElementById("listbox").selectedItem.dataset.zoteroID;
|
2019-08-02 10:09:36 +00:00
|
|
|
var translator = window.arguments[0].translatorProvider.get(translatorID);
|
|
|
|
|
|
|
|
Zotero.debug(translatorID);
|
|
|
|
window.arguments[0].dataOut = translator;
|
2024-03-02 07:51:55 +00:00
|
|
|
};
|
|
|
|
};
|