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