-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
133 lines (116 loc) · 3.05 KB
/
main.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
Button,
CalendarNav,
CalendarNext,
CalendarPrev,
CalendarToday,
Checkbox,
Draggable,
Dropcontainer,
Dropdown,
enhance,
getInst,
Input,
Page,
Radio,
registerComponent,
Segmented,
SegmentedGroup,
Stepper,
Switch,
Textarea,
} from '@mobiscroll/javascript';
import { Router } from 'html5-history-router';
import '@mobiscroll/javascript/dist/css/mobiscroll.min.css';
import '@mobiscroll/print/dist/css/mobiscroll.min.css';
import './style.css';
import { demos, demoTitleMap } from './src/demos';
import HomePage from './src/pages/home';
registerComponent(Button);
registerComponent(Checkbox);
registerComponent(Input);
registerComponent(Draggable);
registerComponent(Dropcontainer);
registerComponent(Dropdown);
registerComponent(Textarea);
registerComponent(Page);
registerComponent(Radio);
registerComponent(Segmented);
registerComponent(SegmentedGroup);
registerComponent(Stepper);
registerComponent(Switch);
registerComponent(CalendarNext);
registerComponent(CalendarPrev);
registerComponent(CalendarToday);
registerComponent(CalendarNav);
window.isMbscDemo = true;
var router = new Router();
var app = document.getElementById('app');
var appBack = document.getElementById('app-back');
var appPath = document.getElementById('app-path');
var appTitle = document.getElementById('app-title');
var currentPage;
function destroyPage() {
var selectors = [
'[mbsc-button]',
'[mbsc-calendar-nav]',
'[mbsc-calendar-next]',
'[mbsc-calendar-prev]',
'[mbsc-calendar-today]',
'[mbsc-segmented]',
'[mbsc-segmented-group]',
'[mbsc-page]',
'.mbsc-eventcalendar',
'.mds-popup',
'.mds-select',
];
app.querySelectorAll(selectors.join(',')).forEach(function (elm) {
getInst(elm).destroy();
});
}
function loadPage(page, title, path) {
if (currentPage) {
destroyPage();
if (currentPage.destroy) {
currentPage.destroy();
}
}
app.innerHTML = "<div id='app-placeholder'>" + page.markup + '</div>';
appTitle.innerHTML = title;
appPath.innerHTML = path ? './src/demos' + path : '';
appBack.style.display = path ? 'block' : 'none';
if (page.css && !page.loaded) {
page.loaded = true;
var style = document.createElement('style');
style.innerHTML = page.css;
document.getElementsByTagName('head')[0].appendChild(style);
}
if (page.init) {
page.init();
}
currentPage = page;
enhance(app);
}
demos.forEach(function (main) {
main.items.forEach(function (sub) {
sub.items.forEach(function (group) {
group.items.forEach(function (demo) {
var path = '/' + main.unique + '/' + sub.unique + '/' + demo.unique;
demoTitleMap[path] = demo.name;
router.on(path, function () {
loadPage(demo.component, demo.name, path);
});
});
});
});
});
router.on('/', function () {
loadPage(HomePage, 'Mobiscroll JavaScript Demos');
});
document.addEventListener('click', function (ev) {
var link = ev.target.closest('.app-link');
if (link) {
ev.preventDefault();
router.pushState(link.getAttribute('href'));
}
});