/
topbar.js
117 lines (107 loc) · 3.98 KB
/
topbar.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Scripts for the Horde topbar.
*
* @copyright 2014-2015 Horde LLC
* @license LGPL-2 (http://www.horde.org/licenses/lgpl)
*/
var HordeTopbar = {
// Vars used and defaulting to null/false:
// conf, searchGhost
/**
* Updates the date in the sub bar.
*/
updateDate: function()
{
var d = $('horde-sub-date');
if (d) {
d.update(Date.today().toString(this.conf.format));
this.updateDate.bind(this).delay(10);
}
},
refreshTopbar: function()
{
HordeCore.doAction('topbarUpdate', {
app: this.conf.app,
hash: this.conf.hash,
location: window.location.href
}, {
callback: this.onUpdateTopbar.bind(this),
uri: this.conf.URI_AJAX
});
},
onUpdateTopbar: function(r)
{
if (this.conf.hash != r.hash) {
$('horde-navigation').update();
this._renderTree(r.nodes, r.root_nodes);
this.conf.hash = r.hash;
}
},
_renderTree: function(nodes, root_nodes)
{
root_nodes.each(function(root_node) {
var elm, item,
active = nodes[root_node].active ? '-active' : '',
container = new Element('DIV', { className: nodes[root_node]['class'] });
elm = new Element('A', { className: 'horde-mainnavi' + active, href: nodes[root_node].url ? nodes[root_node].url : '#' });
if (nodes[root_node].onclick) {
elm.writeAttribute('onclick', nodes[root_node].onclick);
}
container.insert(elm);
item = new Element('LI').insert(container);
if (nodes[root_node].children) {
if (!nodes[root_node].noarrow) {
elm.insert(new Element('SPAN', { className: 'horde-point-arrow' + active })
.insert('▾'));
}
item.insert(this._renderBranch(nodes, nodes[root_node].children));
}
elm.insert(nodes[root_node].label.escapeHTML());
$('horde-navigation')
.insert(new Element('DIV', { className: 'horde-navipoint' })
.insert(new Element('DIV', { className: 'horde-point-left' + active }))
.insert(new Element('UL', { className: 'horde-dropdown' })
.insert(item))
.insert(new Element('DIV', { className: 'horde-point-right' + active })));
}, this);
},
_renderBranch: function(nodes, children)
{
var list = new Element('UL');
children.each(function(child) {
var container, elm, item,
attr = nodes[child].children
? { className: 'arrow' }
: undefined;
container = new Element('DIV', { className: 'horde-drowdown-str' });
if (nodes[child].url) {
elm = new Element('A', { className: 'horde-mainnavi', href: nodes[child].url });
if (nodes[child].onclick) {
elm.writeAttribute('onclick', nodes[child].onclick);
}
container.insert(elm);
} else {
elm = container;
}
elm.insert(nodes[child].label.escapeHTML());
item = new Element('LI', attr).insert(container);
if (nodes[child].children) {
item.insert(this._renderBranch(nodes, nodes[child].children));
}
list.insert(item);
}, this);
return list;
},
onDomLoad: function()
{
if ($('horde-search-input')) {
this.searchGhost = new FormGhost('horde-search-input');
}
this.updateDate();
if (this.conf.refresh) {
new PeriodicalExecuter(this.refreshTopbar.bind(this),
this.conf.refresh);
}
}
};
document.observe('dom:loaded', HordeTopbar.onDomLoad.bind(HordeTopbar));