forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.ts
More file actions
63 lines (53 loc) · 2.04 KB
/
shell.ts
File metadata and controls
63 lines (53 loc) · 2.04 KB
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
60
61
62
63
namespace pxt.shell {
export enum EditorLayoutType {
IDE,
Sandbox,
Widget,
Controller
}
let layoutType: EditorLayoutType;
let editorReadonly: boolean = false;
function init() {
if (layoutType !== undefined) return;
const sandbox = /sandbox=1|#sandbox|#sandboxproject/i.test(window.location.href)
// in iframe
|| pxt.BrowserUtils.isIFrame();
const nosandbox = /nosandbox=1/i.test(window.location.href);
const controller = /controller=1/i.test(window.location.href) && pxt.BrowserUtils.isIFrame();
const readonly = /readonly=1/i.test(window.location.href);
const layout = /editorlayout=(widget|sandbox|ide)/i.exec(window.location.href);
layoutType = EditorLayoutType.IDE;
if (nosandbox)
layoutType = EditorLayoutType.Widget;
else if (controller)
layoutType = EditorLayoutType.Controller;
else if (sandbox)
layoutType = EditorLayoutType.Sandbox;
if (controller && readonly) editorReadonly = true;
if (layout) {
switch (layout[1].toLowerCase()) {
case "widget": layoutType = EditorLayoutType.Widget; break;
case "sandbox": layoutType = EditorLayoutType.Sandbox; break;
case "ide": layoutType = EditorLayoutType.IDE; break;
}
}
pxt.debug(`shell: layout type ${EditorLayoutType[layoutType]}, readonly ${isReadOnly()}`);
}
export function layoutTypeClass(): string {
init();
return pxt.shell.EditorLayoutType[layoutType].toLowerCase();
}
export function isSandboxMode() {
init();
return layoutType == EditorLayoutType.Sandbox;
}
export function isReadOnly() {
return (isSandboxMode()
&& !/[?&]edit=1/i.test(window.location.href)) ||
(isControllerMode() && editorReadonly);
}
export function isControllerMode() {
init();
return layoutType == EditorLayoutType.Controller;
}
}