Initial bookmarks.
[wolnelektury.git] / src / wolnelektury / static / js / book_text / pbox.js
1 (function($){$(function(){
2
3     class PBox {
4         items = [];
5
6         constructor(element) {
7             this.$element = element;
8         }
9
10         addItem(item) {
11             this.items.unshift(item);
12         }
13
14         clear() {
15             $("div", this.$element).remove();
16         }
17
18         showButton(item, text, cls) {
19             let btn = $("<div>");
20             btn.addClass('zakladka-tool');
21             btn.addClass('cls');
22             btn.text(text);
23             btn.on('click', item.action);
24             this.$element.append(btn);
25         }
26
27         // What's a p?
28         // We should open at a *marker*.
29         // And it's the marker that should know its context.
30         openAt(marker) {
31             this.marker = marker;
32             this.clear();
33             $.each(this.items, (i, item) => {
34                 item.update(this);
35             });
36         }
37
38         close() {
39         }
40     }
41
42     $.pbox = new PBox($('#zakladka-box'));  // TODO: rename id
43
44
45     
46 })})(jQuery);