-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathurls.js
59 lines (56 loc) · 2.07 KB
/
urls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import $ from "jquery";
import sagecell from "./sagecell";
export const URLs = {};
/**
* Initialize the important URLs. The root URL derived from one of
* the following locations:
* 1. the variable sagecell.root
* 2. a tag of the form <link property="sagecell-root" href="...">
* 3. the root of the URL of the executing script
*/
export function initializeURLs() {
var root;
var el;
if (sagecell.root) {
root = sagecell.root;
} else if ((el = $("link[property=sagecell-root]")).length > 0) {
root = el.last().attr("href");
} else {
/* get the first part of the last script element's src that loaded something called 'embedded_sagecell.js'
also, strip off the static/ part of the url if the src looked like 'static/embedded_sagecell.js'
modified from MathJax source
We could use the jquery reverse plugin at http://www.mail-archive.com/[email protected]/msg04272.html
and the jquery .each() to get this as well, but this approach avoids creating a reversed list, etc. */
var scripts = (
document.documentElement || document
).getElementsByTagName("script");
var namePattern = /^.*?(?=(?:static\/)?embedded_sagecell.js)/;
for (var i = scripts.length - 1; i >= 0; i--) {
var m = (scripts[i].src || "").match(namePattern);
if (m) {
root = m[0];
break;
}
}
if (!root || root === "/") {
root = window.location.protocol + "//" + window.location.host + "/";
}
}
if (root.slice(-1) !== "/") {
root += "/";
}
if (root === "http://sagecell.sagemath.org/") {
root = "https://sagecell.sagemath.org/";
}
Object.assign(URLs, {
cell: root + "sagecell.html",
completion: root + "complete",
help: root + "help.html",
kernel: root + "kernel",
permalink: root + "permalink",
root: root,
sockjs: root + "sockjs",
spinner: root + "static/spinner.gif",
terms: root + "tos.html",
});
}