Skip to content

Commit b9a448a

Browse files
committed
Save sidebar & flavor
1 parent 7bf4171 commit b9a448a

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

dev/src/Flavor.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,24 @@ import BrowserSolver from "./helpers/BrowserSolver.js";
2323
import ServerSolver from "./helpers/ServerSolver.js";
2424
import profiles from "./profiles/profiles.js";
2525

26+
import app from "./app";
27+
2628
export default class Flavor extends EventDispatcher {
2729

2830
constructor(flavor) {
2931
super();
30-
this.value = flavor;
32+
this.value = app.prefs.read("flavor");
3133
this._browserSolver = new BrowserSolver();
3234
this._serverSolver = new ServerSolver();
3335
}
3436

3537
set value(id) {
36-
let profile = profiles[id.toLowerCase() || "js"];
38+
let profile = profiles[(id && id.toLowerCase()) || "js"];
3739
if (!profile || profile === this._profile) { return; }
3840
Track.page("flavor/"+id);
3941
this._profile = profile;
4042
this._buildSupportMap(profile);
43+
app.prefs.write("flavor", id);
4144
this.dispatchEvent("change");
4245
}
4346

dev/src/RegExr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export default class RegExr extends EventDispatcher {
4343
constructor () { super(); }
4444

4545
init(state, account, config={}) {
46-
this.flavor = new Flavor("js");
46+
this.prefs = new Prefs();
47+
this.flavor = new Flavor();
4748
this.reference = new Reference(reference_content, this.flavor, config);
4849
this._migrateFavorites();
4950
this._initUI();
@@ -160,7 +161,6 @@ export default class RegExr extends EventDispatcher {
160161
toggle: new Tooltip($.query("#library #tooltip"), true)
161162
};
162163

163-
this.prefs = new Prefs();
164164
this.theme = new Theme(this.el);
165165

166166
let el = $.query(".app > .doc", this.el);

dev/src/views/Account.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import EventDispatcher from "../events/EventDispatcher";
2121
import $ from "../utils/DOMUtils"
2222
import Track from "../utils/Track"
2323

24-
import Tooltip from "../controls/Tooltip";
2524
import List from "../controls/List";
2625
import Server from "../net/Server";
2726

dev/src/views/Sidebar.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export default class Sidebar {
3737
this._initUI(el);
3838
this._content = this._prepContent(content);
3939
this.minList.data = [{id: "menu", label:"Menu"}].concat(content.kids);
40-
this.goto("home");
4140
app.flavor.on("change", ()=>this._onFlavorChange());
41+
let id = app.prefs.read("side");
42+
if (!id || !this._idMap[id] || id === "share") { id = "home"; }
43+
this.goto(id);
4244
if (app.isNarrow) { setTimeout(() => this.minimize(true, false), 1500); }
4345
}
4446

@@ -63,7 +65,12 @@ export default class Sidebar {
6365
if (item.hide) { return this.show(item.parent); }
6466
if (!item || item.id === "menu") { return; } // expand button on the min menu
6567
this.minimize(false);
66-
if (item.id) { Track.page("sidebar/"+item.id); }
68+
if (item.id) {
69+
Track.page("sidebar/"+item.id);
70+
if (item.id === "home" || (item.parent && item.parent.id === "home") || this._isInReference(item)) {
71+
app.prefs.write("side", item.id);
72+
}
73+
}
6774

6875
if (!item.el && !item.kids) {
6976
if (this.searchMode || !item.parent || item.parent === this.curItem) {
@@ -196,9 +203,13 @@ export default class Sidebar {
196203
if (o.example) { this.contentEl.appendChild(new Example("Example", o.example).el); }
197204
}
198205
}
199-
206+
200207
_isInReference(o) {
201-
do { if (o.id === "reference") { return true; } } while (o = o.parent);
208+
return this._isIn(o, "reference");
209+
}
210+
211+
_isIn(o, id) {
212+
do { if (o.id === id) { return true; } } while (o = o.parent);
202213
return false;
203214
}
204215

0 commit comments

Comments
 (0)