-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathcontextMenoo.js
69 lines (63 loc) · 2.31 KB
/
contextMenoo.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
/*
@description mootools based context menu
@author Daniel Niquet | http://utils.softr.net
@based in http://thinkweb2.com/projects/prototype
@version 0.5
@date 8/25/07
@requires mootools 1.11
*/
contextMenoo = new Class({
options:{
selector: '.contextmenu', className: '.protoMenu', pageOffset: 25, fade: false, headline: 'Menu'
},
initialize: function (op) {
this.setOptions(op);
this.cont=new Element('div',{'class': this.options.className});
this.Fade=this.cont.effect('opacity');
this.cont.adopt(new Element('b', {'class': 'head'}).setHTML(this.options.headline));
this.options.menuItems.each(function(item){
this.cont.adopt(item.separator ?
new Element('div', {'class': 'separator'}) :
new Element('a', { 'href': '#', 'title': item.name, 'onclick': 'return false;', 'class': item.disabled ? 'disabled' : ''}).addEvent('click', this.onClick.bindWithEvent(this,[item.callback])).setHTML(item.name))
}.bind(this));
this.Fade.set(0);
$(document.body).adopt(this.cont);
document.addEvents({
'click':this.hide.bind(this),'contextmenu':this.hide.bind(this)
});
$$(this.options.selector).each(function(el){
el.addEvent(window.opera?'click':'contextmenu',function(e){
if(window.opera && !e.ctrlKey) return;
this.show(e);
}.bind(this));
},this);
},
hide: function(){this.Fade.set(0);},
show: function(e) {
e=new Event(e).stop();
var oCont=this.cont.getCoordinates(),
size = {'height':window.getHeight(), 'width':window.getWidth(), 'top': window.getScrollTop(),'cW':oCont.width, 'cH':oCont.height};
this.cont.setStyles({
left: ((e.page.x + size.cW + this.options.pageOffset) > size.width ? (size.width - size.cW - this.options.pageOffset) : e.page.x),
top: ((e.page.y - size.top + size.cH) > size.height && (e.page.y - size.top) > size.cH ? (e.page.y - size.cH) : e.page.y)
});
this.Fade.set(0);
this.options.fade?this.Fade.start(0,1):this.Fade.set(1);
},
onClick:function(e,args){
if (args && !e.target.hasClass('disabled')) this.Fade.set(0);args();
}
});
contextMenoo.implement(new Options());
function AddContextMenu(select, classNames, fader, headl, oLinks)
{
window.addEvent('domready', function(){
var menuObj = new contextMenoo({
selector: select,
className: classNames,
fade: fader,
menuItems: oLinks,
headline: headl
});
});
}