-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopbar.js
114 lines (97 loc) · 2.53 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
/* Copyright (c) 2016 Christophe Duparquet.
* http://github.com/duparq/uprog
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*/
/* Initialize menus
* Compute and add element ids
* Add event handlers
*/
var opened_menu = null ;
var menus = document.getElementById("menus").children;
for (i = 0 ; i < menus.length ; i++) {
/*
* Process all menus
*/
var menu = menus[i]
var menu_name = menu.children[0].getAttribute("name")
menu.children[0].id = "menu-"+menu_name
var content = menu.children[1]
var entries = content.children
log("Create menu: "+menu_name);
menu.onclick = onMenuClick ;
menu.onmouseover = onMouseOverMenu ;
for ( j=0 ; j<entries.length ; j++ ) {
/*
* Process all entries of a menu
*/
var entry = entries[j]
var name = entry.getAttribute("name")
entry.id = "menu-"+menu_name+"-"+name
entry.onclick = onMenuEntryClick ;
log(" Create entry: "+name);
}
}
// log("Navigator language: "+navigator.language);
// log(" body: height="+document.body.style.height)
// log(" workarea: h="+document.getElementById("console").clientHeight);
/* Close the opened menu if the user clicks outside of it
*/
window.onclick = function(ev) {
// log("window.onclick(): ?");
close_menus();
}
/* Close any opened menu
*/
function close_menus ( )
{
if ( opened_menu !== null ) {
log("close_menus: "+opened_menu);
opened_menu.children[0].classList.remove("opened");
opened_menu.children[1].classList.remove("show");
opened_menu = null ;
}
}
/* Open a menu
*/
function open_menu ( menu )
{
close_menus();
log("open_menu: "+menu);
menu.children[0].classList.add("opened");
menu.children[1].classList.add("show");
opened_menu = menu ;
}
/* Change opened menu
*/
function onMouseOverMenu(ev) {
log("onMouseOverMenu()");
if ( opened_menu !== null && opened_menu !== this ) {
open_menu(this);
ev.stopPropagation();
}
}
/* Open menu
*/
function onMenuClick(ev) {
log("onMenuClick()");
if ( this !== opened_menu )
open_menu(this);
else
close_menus();
/* Stop propagation, otherwize the window will get the event and
* close the just opened menu!
*/
ev.stopPropagation();
}
/* Do action and close menu
*/
function onMenuEntryClick(ev) {
close_menus();
ev.stopPropagation();
log("onMenuEntryClick(): "+this.getAttribute("name")+" "+this.id);
}