2017-05-31 15:28:47 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var require = (function() {
|
2019-01-21 09:01:04 +00:00
|
|
|
var win, Zotero;
|
2018-02-24 09:54:53 +00:00
|
|
|
Components.utils.import('resource://zotero/loader.jsm');
|
2017-05-31 15:28:47 +00:00
|
|
|
var requirer = Module('/', '/');
|
|
|
|
var _runningTimers = {};
|
2019-01-21 09:01:04 +00:00
|
|
|
if (typeof window != 'undefined') {
|
|
|
|
win = window;
|
|
|
|
} else {
|
|
|
|
win = {};
|
2017-05-31 15:32:39 +00:00
|
|
|
|
2019-01-21 09:01:04 +00:00
|
|
|
win.setTimeout = function (func, ms) {
|
|
|
|
var id = Math.floor(Math.random() * (1000000000000 - 1)) + 1
|
|
|
|
var useMethodjit = Components.utils.methodjit;
|
|
|
|
var timer = Components.classes["@mozilla.org/timer;1"]
|
|
|
|
.createInstance(Components.interfaces.nsITimer);
|
|
|
|
timer.initWithCallback({"notify":function() {
|
|
|
|
// Remove timer from object so it can be garbage collected
|
|
|
|
delete _runningTimers[id];
|
|
|
|
|
|
|
|
// Execute callback function
|
|
|
|
try {
|
|
|
|
func();
|
|
|
|
} catch(err) {
|
|
|
|
// Rethrow errors that occur so that they appear in the error
|
|
|
|
// console with the appropriate name and line numbers. While the
|
|
|
|
// the errors appear without this, the line numbers get eaten.
|
|
|
|
var scriptError = Components.classes["@mozilla.org/scripterror;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIScriptError);
|
|
|
|
scriptError.init(
|
|
|
|
err.message || err.toString(),
|
|
|
|
err.fileName || err.filename || null,
|
|
|
|
null,
|
|
|
|
err.lineNumber || null,
|
|
|
|
null,
|
|
|
|
scriptError.errorFlag,
|
|
|
|
'component javascript'
|
|
|
|
);
|
|
|
|
Components.classes["@mozilla.org/consoleservice;1"]
|
|
|
|
.getService(Components.interfaces.nsIConsoleService)
|
|
|
|
.logMessage(scriptError);
|
|
|
|
typeof Zotero !== 'undefined' && Zotero.debug(err.stack, 1);
|
|
|
|
}
|
|
|
|
}}, ms, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
_runningTimers[id] = timer;
|
|
|
|
return id;
|
|
|
|
};
|
|
|
|
|
|
|
|
win.clearTimeout = function (id) {
|
|
|
|
var timer = _runningTimers[id];
|
|
|
|
if (timer) {
|
|
|
|
timer.cancel();
|
2017-05-31 15:32:39 +00:00
|
|
|
}
|
2019-01-21 09:01:04 +00:00
|
|
|
delete _runningTimers[id];
|
|
|
|
};
|
2017-05-31 15:32:39 +00:00
|
|
|
|
2019-01-21 09:01:04 +00:00
|
|
|
win.debug = function (msg) {
|
|
|
|
dump(msg + "\n\n");
|
|
|
|
};
|
|
|
|
}
|
2017-05-22 23:10:03 +00:00
|
|
|
|
|
|
|
function getZotero() {
|
|
|
|
if (typeof Zotero === 'undefined') {
|
|
|
|
try {
|
|
|
|
Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports).wrappedJSObject;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
return Zotero || {};
|
|
|
|
}
|
2017-05-31 15:28:47 +00:00
|
|
|
|
2017-05-22 23:10:03 +00:00
|
|
|
var cons;
|
2019-01-21 09:01:04 +00:00
|
|
|
if (typeof win.console !== 'undefined') {
|
2017-05-22 23:10:03 +00:00
|
|
|
cons = console;
|
|
|
|
}
|
|
|
|
if (!cons) {
|
|
|
|
cons = {};
|
|
|
|
for (let key of ['log', 'warn', 'error']) {
|
|
|
|
cons[key] = text => {getZotero(); typeof Zotero !== 'undefined' && false && Zotero.debug(`console.${key}: ${text}`)};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let globals = {
|
2019-01-21 09:01:04 +00:00
|
|
|
window: win,
|
|
|
|
document: typeof win.document !== 'undefined' && win.document || {},
|
2017-05-22 23:10:03 +00:00
|
|
|
console: cons,
|
2019-01-21 09:01:04 +00:00
|
|
|
navigator: typeof win.navigator !== 'undefined' && win.navigator || {},
|
2018-12-12 10:34:39 +00:00
|
|
|
setTimeout: win.setTimeout,
|
|
|
|
clearTimeout: win.clearTimeout,
|
2017-05-22 23:10:03 +00:00
|
|
|
};
|
|
|
|
Object.defineProperty(globals, 'Zotero', { get: getZotero });
|
2017-05-31 15:28:47 +00:00
|
|
|
var loader = Loader({
|
|
|
|
id: 'zotero/require',
|
|
|
|
paths: {
|
|
|
|
'': 'resource://zotero/',
|
2019-11-08 08:40:20 +00:00
|
|
|
'containers/': 'chrome://zotero/content/containers/',
|
2019-08-24 08:23:43 +00:00
|
|
|
'components/': 'chrome://zotero/content/components/',
|
2019-11-08 08:40:20 +00:00
|
|
|
'zotero/': 'chrome://zotero/content/modules/',
|
|
|
|
'@zotero/': 'chrome://zotero/content/modules/'
|
2017-05-31 15:28:47 +00:00
|
|
|
},
|
2017-05-22 23:10:03 +00:00
|
|
|
globals
|
2017-05-31 15:28:47 +00:00
|
|
|
});
|
2019-02-25 09:45:42 +00:00
|
|
|
let require = Require(loader, requirer);
|
|
|
|
return require
|
2019-01-21 09:01:04 +00:00
|
|
|
})();
|