modules/tabs.jsView |
---|
20 | 20 | exports.screen_view = function (path) { |
21 | 21 | if(path !== 'tabs') |
22 | 22 | return |
23 | 23 | |
| 24 | + function setSelected (indexes) { |
| 25 | + var ids = indexes.map(function (index) { |
| 26 | + return tabs.get(index).id |
| 27 | + }) |
| 28 | + if(ids.length > 1) |
| 29 | + search.value = 'split('+ids.join(',')+')' |
| 30 | + else |
| 31 | + search.value = ids[0] |
| 32 | + } |
| 33 | + |
24 | 34 | var search |
25 | | - var tabs = Tabs(function (name) { |
26 | | - search.value = name |
27 | | - |
28 | | - }) |
| 35 | + var tabs = Tabs(setSelected) |
29 | 36 | |
30 | 37 | |
31 | 38 | search = search_box(function (path, change) { |
32 | 39 | if(tabs.has(path)) { |
35 | 42 | } |
36 | 43 | var el = screen_view(path) |
37 | 44 | if(el) { |
38 | 45 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
39 | | - tabs.add(path, el, change) |
| 46 | + tabs.add(el, change) |
40 | 47 | |
41 | 48 | return change |
42 | 49 | } |
43 | 50 | }) |
52 | 59 | saved = ['/public', '/private', '/notifications'] |
53 | 60 | |
54 | 61 | saved.forEach(function (path) { |
55 | 62 | var el = screen_view(path) |
| 63 | + el.id = el.id || path |
56 | 64 | if (!el) return |
57 | 65 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
58 | | - if(el) tabs.add(path, el, false) |
| 66 | + if(el) tabs.add(el, false, false) |
59 | 67 | }) |
60 | 68 | |
61 | | - |
62 | | - tabs.select('/public') |
| 69 | + tabs.select(0) |
63 | 70 | |
| 71 | + |
64 | 72 | window.onclick = function (ev) { |
65 | 73 | var link = ancestor(ev.target) |
66 | 74 | if(!link) return |
67 | 75 | var path = link.hash.substring(1) |
72 | 80 | |
73 | 81 | |
74 | 82 | if(open.isExternal(link.href)) return open(link.href) |
75 | 83 | |
76 | | - if(tabs.has(path)) return tabs.select(path) |
77 | | - |
| 84 | + if(tabs.has(path)) |
| 85 | + return tabs.select(path, !ev.ctrlKey, !!ev.shiftKey) |
| 86 | + |
78 | 87 | var el = screen_view(path) |
79 | 88 | if(el) { |
| 89 | + el.id = el.id || path |
80 | 90 | el.scroll = keyscroll(el.querySelector('.scroller__content')) |
81 | | - tabs.add(path, el, !ev.ctrlKey) |
| 91 | + tabs.add(el, !ev.ctrlKey, !!ev.shiftKey) |
82 | 92 | |
83 | 93 | } |
84 | 94 | |
85 | 95 | return false |
97 | 107 | return tabs.selectRelative(1) |
98 | 108 | |
99 | 109 | |
100 | 110 | case 74: |
101 | | - return tabs.selectedTab.scroll(1) |
| 111 | + return tabs.get(tabs.selected[0]).scroll(1) |
102 | 112 | case 75: |
103 | | - return tabs.selectedTab.scroll(-1) |
| 113 | + return tabs.get(tabs.selected[0]).scroll(-1) |
104 | 114 | |
105 | 115 | |
106 | 116 | case 88: |
107 | | - if (tabs.selected) { |
| 117 | + if (tabs.selected) { |
108 | 118 | var sel = tabs.selected |
109 | | - tabs.selectRelative(-1) |
| 119 | + var i = sel.reduce(function (a, b) { return Math.min(a, b) }) |
110 | 120 | tabs.remove(sel) |
111 | | - |
| 121 | + tabs.select(Math.max(i-1, 0)) |
112 | 122 | } |
113 | 123 | return |
114 | 124 | |
115 | 125 | |
154 | 164 | }) |
155 | 165 | |
156 | 166 | return tabs |
157 | 167 | } |
| 168 | + |