-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (74 loc) · 2.86 KB
/
script.js
File metadata and controls
96 lines (74 loc) · 2.86 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
LiveG Docs
Copyright (C) LiveG. All Rights Reserved.
https://docs.liveg.tech
Licensed by the LiveG Open-Source Licence, which can be found at LICENCE.md.
*/
import * as $g from "https://opensource.liveg.tech/Adapt-UI/src/adaptui.js";
import * as astronaut from "https://opensource.liveg.tech/Adapt-UI/astronaut/astronaut.js";
import * as l10n from "https://opensource.liveg.tech/Adapt-UI/src/l10n.js";
window.$g = $g;
astronaut.unpack();
import * as docView from "./docview.js";
import * as productsView from "./productsview.js";
$g.waitForLoad().then(function() {
return $g.l10n.selectLocaleFromResources({
"en_GB": "locales/en_GB.json",
"fr_FR": "locales/fr_FR.json"
});
}).then(function(locale) {
window._ = function() {
return locale.translate(...arguments);
};
$g.theme.setProperty("primaryHue", "190");
$g.theme.setProperty("primarySaturation", "80%");
$g.theme.setProperty("primaryLightness", "25%");
fetch("data/products.json").then(function(response) {
return response.json();
}).then(function(data) {
var productId = $g.core.parameter("product");
var startingPage = $g.core.parameter("page") || "index.md";
var docViewContainer = Container() ();
var docViewScreen = Screen() ();
var productsViewScreen = productsView.ProductsViewScreen({products: data.products, locale: l10n.getSystemLocaleCode()}) ();
var isOpeningDocView = false;
function setDocViewScreen() {
var currentProduct = data.products[productId] || null;
docViewScreen = docView.DocViewScreen({
productId,
startingPage,
product: currentProduct,
locale: l10n.getSystemLocaleCode()
}) ();
docViewScreen.on("showproducts", function() {
$g.sel("title").setText(_("livegDocs"));
window.history.pushState({}, window.title, "/");
productsViewScreen.screenBack();
});
docViewContainer.clear().add(docViewScreen);
}
docViewContainer.setStyle("position", "relative");
productsViewScreen.on("opendoc", function(event) {
if (isOpeningDocView) {
return;
}
isOpeningDocView = true;
productId = event.detail.product;
startingPage = event.detail.page || "index.md";
setDocViewScreen();
docViewScreen.screenForward().then(function() {
isOpeningDocView = false;
});
});
if (productId != null) {
setDocViewScreen();
docViewScreen.show();
} else {
productsViewScreen.show();
}
astronaut.render(Container() (
productsViewScreen,
docViewContainer
));
});
});