Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 8456950

Browse files
committed
Store menu status
1 parent 037aecd commit 8456950

File tree

5 files changed

+61
-29
lines changed

5 files changed

+61
-29
lines changed

lab/index.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,17 @@
3131
</div>
3232
</div>
3333
<div id="main">
34-
<div id="sidebar">
34+
<div id="sidebar" class="hidden">
3535
<div class="title">Quick reference</div>
3636
<div class="close"><i class="icon ion-close-circled"></i></div>
37-
<ul id="menu">
37+
<ul id="menu" class="menu">
3838
<li><a>Components</a>
3939
<ul id="components-menu">
40-
<li><a data-href="#overview">Overview</a></li>
41-
<li><a data-href="#action-sheets">Action Sheets</a></li>
42-
<li><a data-href="#alert">Alerts</a></li>
4340
</ul>
4441
</li>
45-
<li><a href="https://ionicframework.com/docs/api">API Reference</a></li>
46-
<li><a href="https://ionicframework.com/docs/native">Ionic Native</a></li>
47-
<li><a href="https://ionicframework.com/docs/">All Documentation</a></li>
42+
<li><a target="_blank" href="https://ionicframework.com/docs/api">API Reference</a></li>
43+
<li><a target="_blank" href="https://ionicframework.com/docs/native">Ionic Native</a></li>
44+
<li><a target="_blank" href="https://ionicframework.com/docs/">All Documentation</a></li>
4845
</ul>
4946
<div id="view-ad" class="ad">
5047
<img class="logo" src="/ionic-lab/static/img/view-logo.jpg" style="height: 64px"/>

lab/static/css/style.css

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ preview {
335335
#sidebar.hidden {
336336
display: none;
337337
}
338+
338339
#sidebar .close {
339340
cursor: pointer;
340341
position: absolute;
@@ -343,13 +344,14 @@ preview {
343344
color: #a2a9b4;
344345
font-size: 24px;
345346
}
347+
346348
#sidebar .title {
347349
font-size: 20px;
348350
margin-top: 5px;
349351
color: white;
350352
}
351353

352-
#menu {
354+
.menu {
353355
padding: 0;
354356
margin: 0;
355357
-webkit-touch-callout: none; /* iOS Safari */
@@ -360,26 +362,39 @@ preview {
360362
user-select: none; /* Non-prefixed version, currently
361363
supported by Chrome and Opera */
362364
}
363-
#menu li {
365+
.menu li {
364366
list-style: none;
365367
margin: 15px 0;
366368
}
367-
#menu li a {
369+
.menu li a {
368370
color: #a2a9b4;
369371
text-decoration: none;
370372
cursor: pointer;
371373
}
372-
#menu > li > ul {
374+
.menu > li > ul {
373375
display: none;
374376
padding: 0;
375377
margin: 0;
376378
}
377-
#menu > li > ul li {
379+
.menu > li > ul li {
378380
padding-left: 15px;
379381
}
380-
#menu > li.expanded > ul {
382+
.menu > li.expanded > ul {
381383
display: block;
382384
}
385+
.menu hr {
386+
height: 1px;
387+
border: 0;
388+
background-color: #2b3642;
389+
}
390+
.menu .version {
391+
color: #a2a9b4;
392+
opacity: 0.5;
393+
font-size: 12px;
394+
}
395+
396+
#menu {
397+
}
383398

384399
.ad {
385400
background-color: #232A31;

lab/static/js/lab.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
2-
31
var $ = document.querySelector.bind(document);
42

53
var API_ROOT = '/ionic-lab/api/v1';
64

7-
function loadSearchIndex() {
8-
var index = 'http://ionicframework.com/docs/data/index.json';
9-
fetch(index, {
10-
}).then((r) => {
11-
return r.json();
12-
}).then(json => {
13-
console.log('Loaded search index', json);
5+
var APP_CONFIG = {}
6+
7+
function loadAppConfig() {
8+
var req = new XMLHttpRequest();
9+
req.addEventListener('load', function(e) {
10+
setAppConfig(JSON.parse(req.response));
1411
})
12+
req.open('GET', API_ROOT + '/app-config', true)
13+
req.send(null);
1514
}
1615

16+
function setAppConfig(data) {
17+
APP_CONFIG = data;
18+
}
19+
20+
1721
function buildMenu() {
1822
buildComponentsMenu();
1923
const sidebar = $('#sidebar');
2024
const topLevels = sidebar.querySelectorAll('#menu > li > a');
25+
26+
const lastMenuConfig = window.localStorage.getItem('ionic_labmenu');
27+
if(lastMenuConfig === 'true' || lastMenuConfig === null) {
28+
sidebar.classList.remove('hidden');
29+
}
30+
2131
Array.prototype.map.call(topLevels, a => {
2232
if(!a.href) {
2333
a.addEventListener('click', e => {
@@ -36,13 +46,13 @@ function buildMenu() {
3646
win.focus();
3747
})
3848

39-
const s = $('#sidebar');
40-
4149
const toggleMenu = e => {
42-
if(s.classList.contains('hidden')) {
43-
s.classList.remove('hidden');
50+
if(sidebar.classList.contains('hidden')) {
51+
sidebar.classList.remove('hidden');
52+
window.localStorage.setItem('ionic_labmenu', 'true');
4453
} else {
45-
s.classList.add('hidden');
54+
sidebar.classList.add('hidden');
55+
window.localStorage.setItem('ionic_labmenu', 'false');
4656
}
4757
}
4858

@@ -170,6 +180,7 @@ function loadCordova() {
170180
}
171181

172182
//loadSearchIndex();
183+
loadAppConfig();
173184
buildMenu();
174185
showLastDevices();
175186
loadCordova();

src/dev-server/http-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as Constants from '../util/constants';
1818
import { getBooleanPropertyValue } from '../util/helpers';
1919
import { getProjectJson, IonicProject } from '../util/ionic-project';
2020

21-
import { LabAppView, ApiCordovaProject } from './lab';
21+
import { LabAppView, ApiCordovaProject, ApiPackageJson } from './lab';
2222

2323

2424
/**
@@ -40,6 +40,7 @@ export function createHttpServer(config: ServeConfig): express.Application {
4040
app.use(IONIC_LAB_URL + '/static', express.static(path.join(__dirname, '..', '..', 'lab', 'static')));
4141
app.get(IONIC_LAB_URL, LabAppView);
4242
app.get(IONIC_LAB_URL + '/api/v1/cordova', ApiCordovaProject );
43+
app.get(IONIC_LAB_URL + '/api/v1/app-config', ApiPackageJson);
4344

4445
app.get('/cordova.js', servePlatformResource, serveMockCordovaJS);
4546
app.get('/cordova_plugins.js', servePlatformResource);

src/dev-server/lab.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ export let ApiCordovaProject = (req: any, res: any) => {
1616
res.json(config);
1717
});
1818
};
19+
20+
export let ApiPackageJson = (req: any, res: any) => {
21+
res.sendFile(path.join(process.cwd(), 'package.json'), {
22+
headers: {
23+
'content-type': 'application/json'
24+
}
25+
})
26+
};

0 commit comments

Comments
 (0)