contextmenu_wev8.js
7.68 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
var _PopTimer = 0;
//右菜菜单类
function contextMenu(){
this.items = new Array();
this.addItem = function (item){
this.items[this.items.length] = item;
}
this.show = function (oDoc){
var S = "";
var i;
S = "<div id=\"rightmenu\" style=\"BACKGROUND-COLOR: #ffffff; BORDER: #000000 1px solid; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; Z-INDEX: 10\">";
S += "<table class=\"menutable\" border=\"0\" height=\"";
S += this.items.length * 20;
S += "\" cellpadding=\"0\" cellspacing=\"0\">";
S += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\" width=\"2\"></td><td>";
S += "<table class=\"menutable\" border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
S += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
S += "</td><td width=\"2\"></td></tr>";
S += "<tr><td bgcolor=\"#d0d0ce\"></td><td>";
S += "<table class=\"menutable\" border=\"0\" width=\"100%\" height=\"100%\" cellpadding=3 cellspacing=0 bgcolor=\"#ffffff\">";
oDoc.write(S);
for(i=0; i<this.items.length; i++){
this.items[i].show(oDoc);
}
S = "</table></td><td></td></tr>";
S += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\"></td><td>";
S += "<table class=\"menutable\" border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
S += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
S += "</td><td></td></tr>";
S += "</table></div>\n";
oDoc.write(S);
}
}
//右键菜单项类
function contextItem(text, icon, cmd, type){
this.text = text ? text : "";
this.icon = icon ? icon : "";
this.cmd = cmd ? cmd : "";
this.type = type ? type : "menu";
this.show = function (oDoc){
var S = "";
if(this.type == "menu"){
S += "<tr ";
S += "onmouseover=\"changeStyle(this, 'on');\" ";
S += "onmouseout=\"changeStyle(this, 'out');\" ";
S += "onclick=\"hideMenu();";
S += this.cmd;
S += "\">";
S += "<td class=\"ltdexit\" width=\"16\">";
if (this.icon == "")
S += " ";
else{
S += "<img border=\"0\" src=\"";
S += this.icon;
S += "\" style=\"POSITION: relative\"></img>";
}
S += "</td><td class=\"mtdexit\">";
S += this.text;
S += "</td><td class=\"rtdexit\" width=\"5\"> </td></tr>";
}
else if (this.type == "separator"){
S += "<tr><td class=\"ltdexit\"> </td>";
S += "<td class=\"mtdexit\" colspan=\"2\"><hr color=\"#000000\" size=\"1\"></td></tr>";
}
oDoc.write(S);
}
}
//当鼠标在菜单项上移动时,更改样式,显示XP效果
function changeStyle(obj, cmd){
if(obj) try {
var imgObj = obj.children(0).children(0);
if(cmd == 'on'){
obj.children(0).className = "ltdfocus";
obj.children(1).className = "mtdfocus";
obj.children(2).className = "rtdfocus";
if(imgObj){
if(imgObj.tagName.toUpperCase() == "IMG"){
imgObj.style.left = "-1px";
imgObj.style.top = "-1px";
}
}
}
else if(cmd == 'out') {
obj.children(0).className = "ltdexit";
obj.children(1).className = "mtdexit";
obj.children(2).className = "rtdexit";
if(imgObj){
if(imgObj.tagName.toUpperCase() == "IMG"){
imgObj.style.left = "0px";
imgObj.style.top = "0px";
}
}
}
}
catch (e) {}
}
function StopTimeout(){
clearTimeout(_PopTimer);
}
function StartTimeout(){
if(_PopTimer == 0) _PopTimer = setTimeout('hideMenu()', 500);
}
//弹出右键菜单
function showMenu(){
//if(event.srcElement.tagName != "BODY") return false;
var x, y, w, h, ox, oy;
x = event.clientX;
y = event.clientY;
var obj = document.getElementById("rightmenu");
if (obj == null)
return true;
ox = document.body.clientWidth;
oy = document.body.clientHeight;
if(x > ox || y > oy) return false;
w = obj.offsetWidth;
h = obj.offsetHeight;
if((x + w) > ox) x = x - w;
if((y + h) > oy) y = y - h;
obj.style.posLeft = x + document.body.scrollLeft;
obj.style.posTop = y + document.body.scrollTop;
obj.style.visibility = "visible";
return false;
}
//隐藏右键菜单
function hideMenu(){
if(event.button == 0){
var obj = document.getElementById("rightmenu");
if (obj == null) return true;
obj.style.visibility = "hidden";
obj.style.posLeft = 0;
obj.style.posTop = 0;
}
}
//预选在文档中输出XP左键菜单所必须的样式CSS
function writeContextStyle(){
var S = "";
S += "<STYLE type=text/css>";
S += ".menutable {Font-FAMILY: \"Tahoma\",\"Verdana\",\"宋体\"; FONT-SIZE: 9pt}";
S += ".mtdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; CURSOR: hand}";
S += ".mtdexit {BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid}";
S += ".ltdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; CURSOR: hand}";
S += ".ltdexit {BACKGROUND-COLOR: #d0d0ce; BORDER-BOTTOM: #d0d0ce 1px solid; BORDER-TOP: #d0d0ce 1px solid; BORDER-LEFT: #d0d0ce 1px solid}";
S += ".rtdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; CURSOR: hand}";
S += ".rtdexit {BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-RIGHT: #ffffff 1px solid}";
S += "</STYLE>";
document.write(S);
}
//配置是否要在页面中启用右键菜单
function toggleMenu(isEnable){
if(isEnable)
document.oncontextmenu = showMenu;
else
document.oncontextmenu = new function() {return true;};
}
//执行输出XP菜单样式
writeContextStyle();
/*至此完整,实际应用中不要把以下DrawContextMenu放在这里*/
//在网页上创建右键菜单
function DrawContextMenu(){
var popmnu, item;
popmnu = new contextMenu();
/*item = new contextItem("新建流程图", "image/new_wev8.gif", "mnuNewFlow();", "menu");
popmnu.addItem(item);
item = new contextItem("打开流程图", "image/open_wev8.gif", "mnuOpenFlow();", "menu");
popmnu.addItem(item);*/
/*item = new contextItem("保存流程图", "image/save_wev8.gif", "mnuSaveFlow();", "menu");
popmnu.addItem(item);
item = new contextItem("流程图属性", "image/edit_wev8.gif", "mnuEditFlow();", "menu");
popmnu.addItem(item);*/
/*item = new contextItem("重新载入流程图", "image/refresh_wev8.gif", "mnuReloadFlow();", "menu");
popmnu.addItem(item);
item = new contextItem("", "", "", "separator");
popmnu.addItem(item);
item = new contextItem("新建[任务]", "image/add_proc_wev8.gif", "mnuAddProc();", "menu");
popmnu.addItem(item);
item = new contextItem("新建[路径]", "image/add_step_wev8.gif", "mnuAddStep();", "menu");
popmnu.addItem(item);
item = new contextItem("复制选中任务", "image/copy_wev8.gif", "mnuCopyProc();", "menu");
popmnu.addItem(item);
item = new contextItem("编辑选中对象", "image/edit_obj_wev8.gif", "mnuEditObj();", "menu");
popmnu.addItem(item);*/
item = new contextItem("删除选中对象", "image/del_obj_wev8.gif", "mnuDelObj();", "menu");
popmnu.addItem(item);
/*item = new contextItem("移到最前面", "image/front_wev8.gif", "mnuSetZIndex('F');", "menu");
popmnu.addItem(item);
item = new contextItem("移到最后面", "image/back_wev8.gif", "mnuSetZIndex('B');", "menu");
popmnu.addItem(item);*/
popmnu.show(this.document);
delete item;
delete popmnu;
}
DrawContextMenu();
document.onclick = hideMenu;
document.oncontextmenu = showMenu;