-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardlist.js
More file actions
81 lines (71 loc) · 2.64 KB
/
cardlist.js
File metadata and controls
81 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Card List Windoid — HyperCode
* Displays a list of all cards in the stack and allows quick navigation.
*/
export class CardList {
constructor(app) {
this.app = app;
this._el = null;
this._visible = false;
}
init() {
const el = document.getElementById('cards-windoid');
this._el = el;
el.innerHTML = `
<div class="windoid-title" id="cards-drag">
<span class="windoid-close" style="float:left;width:11px;height:11px;border:1px solid #000;margin:1px 0 0 0px;cursor:pointer;background:#fff;" title="Close"></span>
Cards
</div>
<div class="cards-list-inner" id="cards-list-container">
<!-- Card items will be rendered here -->
</div>`;
this.app.ui._makeDraggable(el, el.querySelector('#cards-drag'));
el.querySelector('.windoid-close').addEventListener('click', () => this.hide());
el.style.display = 'none';
// Listen for card changes to refresh the list
// (If we had a formal event system, we'd use it here)
}
toggle() {
if (this._el.style.display === 'none') this.show();
else this.hide();
}
show() {
this._visible = true;
this._el.style.display = 'block';
this.refresh();
this.app.ui._updateMenuLabels();
}
hide() {
this._visible = false;
this._el.style.display = 'none';
this.app.ui._updateMenuLabels();
}
refresh() {
if (!this._el) return;
const container = this._el.querySelector('#cards-list-container');
if (!container) return;
const { cards, currentCardIndex } = this.app.state;
container.innerHTML = cards.map((card, idx) => `
<div class="card-list-item ${idx === currentCardIndex ? 'active' : ''}" data-index="${idx}">
<span class="card-list-num">${idx + 1}.</span>
<span class="card-list-name">${this._esc(card.name || 'Untitled')}</span>
</div>
`).join('');
container.querySelectorAll('.card-list-item').forEach(el => {
el.onclick = () => {
const idx = parseInt(el.dataset.index);
// Highlight briefly
el.classList.add('clicking');
setTimeout(() => {
el.classList.remove('clicking');
this.app.goToCard(idx + 1);
this.refresh(); // Update active state
}, 150);
};
});
}
_esc(str) {
if (!str) return '';
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
}