-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpand-toolbar-widget.js
72 lines (55 loc) · 2.37 KB
/
expand-toolbar-widget.js
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
/*\
title: $:/plugins/axxie/clear-view/expand-toolbar-widget.js
type: application/javascript
module-type: widget
Widget that places required visual and hidden elements into the dom.
The expanding and collapsing is implemented by css.
\*/
(function () {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var ExpandToolbar = function (parseTreeNode, options) {
this.initialise(parseTreeNode, options);
};
var globalId = 1;
/*
Inherit from the base widget class
*/
ExpandToolbar.prototype = new Widget();
/*
Render this widget into the DOM
*/
ExpandToolbar.prototype.render = function (parent, nextSibling) {
this.parentDomNode = parent;
var buttonClass = this.wiki.getTiddlerText("$:/config/Toolbar/ButtonClass", ".tc-btn-invisible");
var id = "collapse" + globalId++;
var html =
'<input id="' + id + '" type="checkbox" class="toolbar-expander-checkbox">' +
'<label for="' + id + '" class="' + buttonClass + ' toolbar-expander">' +
this.wiki.getTiddlerText("$:/core/images/chevron-left", "") +
'</label>' +
'<label for="' + id + '" class="' + buttonClass + ' toolbar-collapser">' +
this.wiki.getTiddlerText("$:/core/images/chevron-right", "") +
'</label>';
var template = this.document.createElement('div');
template.innerHTML = html;
var tiddlerViewFrame = parent;
while (tiddlerViewFrame && !tiddlerViewFrame.classList.contains('tc-tiddler-view-frame')) {
tiddlerViewFrame = tiddlerViewFrame.parentElement;
}
if (!tiddlerViewFrame) return;
var tiddlerControls = tiddlerViewFrame.getElementsByClassName('tc-tiddler-controls')[0]
tiddlerControls.insertAdjacentElement("beforebegin", template.firstChild);
tiddlerControls.insertAdjacentElement("beforebegin", template.firstChild);
tiddlerControls.insertAdjacentElement("afterend", template.firstChild);
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
ExpandToolbar.prototype.refresh = function (changedTiddlers) {
return false;
};
exports['expand-toolbar'] = ExpandToolbar;
})();