-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenu.js
More file actions
142 lines (106 loc) · 3.24 KB
/
Menu.js
File metadata and controls
142 lines (106 loc) · 3.24 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* $RCSfile: Menu.js,v $
* $Revision: 1.6 $ $Date: 2012/08/15 19:08:06 $
* Auth: Jochen Fritz (jfritz@steptools.com)
*
* Copyright (c) 1991-2012 by STEP Tools Inc.
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation is hereby granted, provided that this copyright
* notice and license appear on all copies of the software.
*
* STEP TOOLS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
* SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. STEP TOOLS
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES.
*/
"use strict";
function Menu(menu_el, win) {
this.menu_el = menu_el;
this.selections = {};
var self = this;
menu_el.addEventListener("click", this, false);
menu_el.addEventListener("contextmenu", this, false);
this.emsize = Number(getComputedStyle(menu_el, "")
.fontSize.match(/(\d+)px/)[1]);
}
METHODS(Menu, {
addOption : function(cls, fn) {
this.selections[cls] = fn;
},
isUp : function() {
// return this.targ != null;
return this.menu_el.classList.contains("menu-visible");
},
popupAt : function(x,y) {
this.popupX = x;
this.popupY = y;
this.menu_el.classList.add("menu-visible");
var win = this.menu_el.ownerDocument.defaultView;
this.menu_el.style.left = x + win.scrollX + (this.emsize / 4);
this.menu_el.style.top = y + win.scrollY + (this.emsize / 4);
var menu_bbox = this.menu_el.getBoundingClientRect();
var wh = window.innerHeight;
var ww = window.innerWidth;
if (menu_bbox.bottom > wh) {
if (menu_bbox.height > wh)
this.menu_el.style.top = win.scrollY;
else {
this.menu_el.style.top = wh -menu_bbox.height +win.scrollY;
}
}
if (menu_bbox.right > ww) {
if (menu_bbox.width > ww)
this.menu_el.style.left = win.scrollX;
else {
this.menu_el.style.left = ww -menu_bbox.width +win.scrollX;
}
}
},
popup : function(el) {
this.popdown();
this.targ = el;
this.targ.classList.add("menu-target");
var rect = el.getBoundingClientRect();
this.popupAt(rect.left, rect.top);
},
popdown : function() {
if (this.targ) {
this.targ.classList.remove("menu-target");
}
this.menu_el.classList.remove("menu-visible");
this.targ = null;
},
setStepFile : function(stp) {
var doc = this.menu_el.ownerDocument;
var dl = doc.getElementById("menu_download");
if (stp && 0)
dl.style.display = "list-item"
else
delete dl.style.display;
dl.innerHTML="<a href='" +stp+"'>Download STEP File</a>" ;
},
handleEvent : function(ev) {
var targ = this.targ;
this.popdown();
ev.preventDefault();
var el = ev.target;
while (el && el != this.menu_el) {
var fn = this.getOption(el.classList);
if (fn)
fn(targ, ev);
el = el.parentNode;
}
},
getOption : function(cl) {
for (var i=0; i<cl.length; i++) {
var it = cl.item(i);
if (this.selections[it])
return this.selections[it];
}
return null;
},
});