Skip to content

Commit 5824b20

Browse files
author
Tim Berners-Lee
committed
Body of selected thing in tabs is kept when hidden and so does not have to be redrawn when re-selected
1 parent f223b85 commit 5824b20

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

lib/tabs.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ UI.tabs.tabWidget = function(options){
3333
var wholetable = box.appendChild(dom.createElement('table'))
3434

3535
var tabContainer, tabElement, mainDiv
36-
var bodyDiv = dom.createElement('div')
37-
bodyDiv.setAttribute('style', 'resize: both; margin:0; border: 0.5em; border-style: solid; border-color: #eed; padding: 1em; min-width: 30em; min-height: 20em; width:100%;')
36+
//var bodyDiv = dom.createElement('div')
37+
var bodyDivStyle = 'resize: both; margin:0; border: 0.5em; border-style: solid; border-color: #eed; padding: 1em; min-width: 30em; min-height: 20em; width:100%;'
38+
//bodyDiv.setAttribute('style', )
3839
if (vertical){
3940
var onlyTR = wholetable.appendChild(dom.createElement('tr'))
4041
var mainTD = dom.createElement('td')
@@ -48,7 +49,7 @@ UI.tabs.tabWidget = function(options){
4849
}
4950
tabContainer = tabTD.appendChild(dom.createElement('table'))
5051
tabElement = 'tr'
51-
mainTD.appendChild(bodyDiv)
52+
//mainTD.appendChild(bodyDiv)
5253

5354
} else { // horizontal
5455
tabContainer = dom.createElement('tr')
@@ -63,8 +64,9 @@ UI.tabs.tabWidget = function(options){
6364
tabContainer = tabTR
6465
var mainTD = mainTR.appendChild(dom.createElement('td'))
6566
tabElement = 'td'
66-
mainTD.appendChild(bodyDiv)
67+
//mainTD.appendChild(bodyDiv)
6768
}
69+
var bodyContainer = mainTD.appendChild(dom.createElement('table'))
6870

6971
var getItems = function(){
7072
if (options.ordered){
@@ -81,12 +83,19 @@ UI.tabs.tabWidget = function(options){
8183
var tabStyle = corners + 'margin: 0.3em; padding: 0.7em;'
8284
var unselectedStyle = tabStyle + ' background-color: #eed; border: 0.05em 0 0.5em 0.05em; border-color: grey;' // @@ rotate border
8385
var selectedStyle = tabStyle + ' background-color: #ddc;'
86+
var shownStyle = ''
87+
var hiddenStyle = shownStyle + 'display: none;'
8488

8589
var resetTabStyle = function() {
8690
for (var i = 0; i < tabContainer.children.length; i++){
8791
tabContainer.children[i].firstChild.setAttribute('style', unselectedStyle)
8892
}
8993
}
94+
var resetBodyStyle = function() {
95+
for (var i = 0; i < bodyContainer.children.length; i++){
96+
bodyContainer.children[i].setAttribute('style', hiddenStyle)
97+
}
98+
}
9099

91100

92101
var makeNewSlot = function(item){
@@ -95,10 +104,19 @@ UI.tabs.tabWidget = function(options){
95104
var div = ele.appendChild(dom.createElement('div'))
96105
div.setAttribute('style', unselectedStyle)
97106
div.addEventListener('click', function(e){
98-
resetTabStyle()
107+
var bodyDiv
108+
if (!e.altKey){
109+
resetTabStyle()
110+
resetBodyStyle()
111+
}
99112
div.setAttribute('style', selectedStyle)
100-
bodyDiv.innerHTML = 'loading item ...' + item
101-
options.showMain(bodyDiv, ele.subject)
113+
ele.bodyTR.setAttribute('style', shownStyle)
114+
if (!ele.bodyTR.firstChild) {
115+
bodyDiv = ele.bodyTR.appendChild(dom.createElement('div'))
116+
bodyDiv.setAttribute('style', bodyDivStyle)
117+
bodyDiv.innerHTML = 'loading item ...' + item
118+
options.showMain(bodyDiv, ele.subject)
119+
}
102120
})
103121
div.textContent = UI.utils.label(item)
104122
return ele
@@ -133,19 +151,28 @@ UI.tabs.tabWidget = function(options){
133151
var insertables = items.slice(left, right - tabContainer.children.length + items.length + 1)
134152
while (right >= left) { // remove extra
135153
tabContainer.removeChild(tabContainer.children[left])
154+
bodyContainer.removeChild(bodyContainer.children[left])
136155
right -= 1
137156
}
138157
for (i=0; i< insertables.length; i++){
158+
var newSlot = makeNewSlot(insertables[i])
159+
var newBodyTR = dom.createElement('tr')
160+
//var newBodyDiv = newBodyTR.appendChild(dom.createElement('div'))
161+
newSlot.bodyTR = newBodyTR
162+
dom.createElement('tr')
139163
if (left === tabContainer.children.length) { // None left of original on right
140-
tabContainer.appendChild(makeNewSlot(insertables[i]))
164+
tabContainer.appendChild(newSlot)
165+
bodyContainer.appendChild(newBodyTR)
141166
console.log(' appending new ' + insertables[i])
142167
} else {
143168
console.log(' inserting at ' + (left + i) + ' new ' + insertables[i])
144-
tabContainer.insertBefore(makeNewSlot(insertables[i]),tabContainer.children[left + i])
169+
tabContainer.insertBefore(newSlot, tabContainer.children[left + i])
170+
bodyContainer.insertBefore(newBodyTR, bodyContainer.children[left + i])
145171
}
146172
}
147173
}
148174

175+
// UNMAINTAINED
149176
var unorderedSync = function(){
150177
var items = getItems()
151178
if (!vertical) {

lib/utils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Tabulator Utilities
2-
// ===================
1+
// Solid-UI general Utilities
2+
// ==========================
33
//
44
// This must load AFTER the rdflib.js and log-ext.js (or log.js).
55
//
@@ -21,6 +21,12 @@ UI.utils.hashColor = function(who) {
2121
return '#' + ((hash(who) & 0xffffff) | 0xc0c0c0).toString(16); // c0c0c0 or 808080 forces pale
2222
}
2323

24+
UI.utils.gen_uuid = function () { // http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
25+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
26+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)
27+
return v.toString(16)
28+
})
29+
}
2430

2531

2632
// http://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep

0 commit comments

Comments
 (0)