Commit ae5dc8ad4e093e668b8fcff19e4434330f5d9d24
route to views via hash fragment. tabs is just another view
Dominic Tarr committed on 7/22/2016, 3:51:01 AMParent: 79737575585dc62349a1a2dc95a1ca4f2558e6c5
Files changed
modules/index.js | changed |
modules/tabs.js | changed |
modules/app.js | added |
modules/index.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 | module.exports = { |
2 | 2 | "_screen_view.js": require('./_screen_view.js'), |
3 | 3 | "about.js": require('./about.js'), |
4 | + "app.js": require('./app.js'), | |
4 | 5 | "avatar-image.js": require('./avatar-image.js'), |
5 | 6 | "avatar-profile.js": require('./avatar-profile.js'), |
6 | 7 | "avatar.js": require('./avatar.js'), |
7 | 8 | "blob-url.js": require('./blob-url.js'), |
modules/tabs.js | ||
---|---|---|
@@ -11,18 +11,21 @@ | ||
11 | 11 | return el |
12 | 12 | } |
13 | 13 | |
14 | 14 | var plugs = require('../plugs') |
15 | -var screen_view = plugs.first(exports.screen_view = []) | |
15 | +var screen_view = plugs.first(exports._screen_view = []) | |
16 | 16 | var search_box = plugs.first(exports.search_box = []) |
17 | 17 | |
18 | 18 | exports.message_render = [] |
19 | 19 | |
20 | -exports.app = function () { | |
20 | +exports.screen_view = function (path) { | |
21 | + if(path !== 'tabs') | |
22 | + return | |
23 | + | |
21 | 24 | var search |
22 | 25 | var tabs = Tabs(function (name) { |
23 | 26 | search.value = name |
24 | - sessionStorage.selectedTab = tabs.selected | |
27 | +// sessionStorage.selectedTab = tabs.selected | |
25 | 28 | }) |
26 | 29 | // tabs.classList.add('screen') |
27 | 30 | |
28 | 31 | search = search_box(function (path, change) { |
@@ -33,18 +36,18 @@ | ||
33 | 36 | var el = screen_view(path) |
34 | 37 | if(el) { |
35 | 38 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
36 | 39 | tabs.add(path, el, change) |
37 | - localStorage.openTabs = JSON.stringify(tabs.tabs) | |
40 | +// localStorage.openTabs = JSON.stringify(tabs.tabs) | |
38 | 41 | return change |
39 | 42 | } |
40 | 43 | }) |
41 | 44 | |
42 | 45 | tabs.insertBefore(search, tabs.querySelector('.hypertabs__content')) |
43 | 46 | |
44 | 47 | var saved = [] |
45 | - try { saved = JSON.parse(localStorage.openTabs) } | |
46 | - catch (_) { } | |
48 | +// try { saved = JSON.parse(localStorage.openTabs) } | |
49 | +// catch (_) { } | |
47 | 50 | |
48 | 51 | if(!saved || saved.length < 3) |
49 | 52 | saved = ['/public', '/private', '/notifications'] |
50 | 53 | |
@@ -54,9 +57,10 @@ | ||
54 | 57 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
55 | 58 | if(el) tabs.add(path, el, false) |
56 | 59 | }) |
57 | 60 | |
58 | - tabs.select(sessionStorage.selectedTab || saved[0] || '/public') | |
61 | +// tabs.select(sessionStorage.selectedTab || saved[0] || '/public') | |
62 | + tabs.select('/public') | |
59 | 63 | |
60 | 64 | tabs.onclick = function (ev) { |
61 | 65 | var link = ancestor(ev.target) |
62 | 66 | if(!link) return |
@@ -74,9 +78,9 @@ | ||
74 | 78 | var el = screen_view(path) |
75 | 79 | if(el) { |
76 | 80 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
77 | 81 | tabs.add(path, el, !ev.ctrlKey) |
78 | - localStorage.openTabs = JSON.stringify(tabs.tabs) | |
82 | +// localStorage.openTabs = JSON.stringify(tabs.tabs) | |
79 | 83 | } |
80 | 84 | |
81 | 85 | return false |
82 | 86 | } |
@@ -103,9 +107,9 @@ | ||
103 | 107 | if (tabs.selected && tabs.selected[0] !== '/') { |
104 | 108 | var sel = tabs.selected |
105 | 109 | tabs.selectRelative(-1) |
106 | 110 | tabs.remove(sel) |
107 | - localStorage.openTabs = JSON.stringify(tabs.tabs) | |
111 | +// localStorage.openTabs = JSON.stringify(tabs.tabs) | |
108 | 112 | } |
109 | 113 | return |
110 | 114 | |
111 | 115 | // activate the search field |
@@ -150,5 +154,4 @@ | ||
150 | 154 | }) |
151 | 155 | |
152 | 156 | return tabs |
153 | 157 | } |
154 | - |
modules/app.js | ||
---|---|---|
@@ -1,0 +1,30 @@ | ||
1 | +var plugs = require('../plugs') | |
2 | +var h = require('hyperscript') | |
3 | + | |
4 | +var screen_view = plugs.first(exports.screen_view = []) | |
5 | + | |
6 | +exports.app = function () { | |
7 | + function hash() { | |
8 | + return window.location.hash.substring(1) | |
9 | + } | |
10 | + | |
11 | + var view = screen_view(hash() || 'tabs') | |
12 | + | |
13 | + var screen = h('div.screen.column', view) | |
14 | + | |
15 | + window.onhashchange = function (ev) { | |
16 | + var _view = view | |
17 | + screen.replaceChild(view = screen_view(hash()), _view) | |
18 | + } | |
19 | + | |
20 | + return screen | |
21 | + | |
22 | +} | |
23 | + | |
24 | + | |
25 | + | |
26 | + | |
27 | + | |
28 | + | |
29 | + | |
30 | + |
Built with git-ssb-web