|
|
@ -39,7 +39,6 @@ var ContextMenu = new Class({ |
|
|
|
menu: 'menu_id', |
|
|
|
menu: 'menu_id', |
|
|
|
stopEvent: true, |
|
|
|
stopEvent: true, |
|
|
|
targets: 'body', |
|
|
|
targets: 'body', |
|
|
|
trigger: 'contextmenu', |
|
|
|
|
|
|
|
offsets: { |
|
|
|
offsets: { |
|
|
|
x: 0, |
|
|
|
x: 0, |
|
|
|
y: 0 |
|
|
|
y: 0 |
|
|
@ -142,50 +141,41 @@ var ContextMenu = new Class({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setupEventListeners: function(elem) { |
|
|
|
|
|
|
|
elem.addEvent('contextmenu', function(e) { |
|
|
|
|
|
|
|
this.triggerMenu(e, elem); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
elem.addEvent('click', function(e) { |
|
|
|
|
|
|
|
this.hide(); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addTarget: function(t) { |
|
|
|
addTarget: function(t) { |
|
|
|
this.targets[this.targets.length] = t; |
|
|
|
this.targets[this.targets.length] = t; |
|
|
|
t.addEvent(this.options.trigger, function(e) { |
|
|
|
this.setupEventListeners(t); |
|
|
|
//enabled?
|
|
|
|
}, |
|
|
|
if (!this.options.disabled) { |
|
|
|
|
|
|
|
|
|
|
|
triggerMenu: function(e, el) { |
|
|
|
|
|
|
|
if (this.options.disabled) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
//prevent default, if told to
|
|
|
|
//prevent default, if told to
|
|
|
|
if (this.options.stopEvent) { |
|
|
|
if (this.options.stopEvent) { |
|
|
|
e.stop(); |
|
|
|
e.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
//record this as the trigger
|
|
|
|
//record this as the trigger
|
|
|
|
this.options.element = $(t); |
|
|
|
this.options.element = $(el); |
|
|
|
this.adjustMenuPosition(e); |
|
|
|
this.adjustMenuPosition(e); |
|
|
|
//show the menu
|
|
|
|
//show the menu
|
|
|
|
this.show(); |
|
|
|
this.show(); |
|
|
|
} |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
t.addEvent('click', function(e) { |
|
|
|
|
|
|
|
this.hide(); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//get things started
|
|
|
|
//get things started
|
|
|
|
startListener: function() { |
|
|
|
startListener: function() { |
|
|
|
/* all elements */ |
|
|
|
/* all elements */ |
|
|
|
this.targets.each(function(el) { |
|
|
|
this.targets.each(function(el) { |
|
|
|
/* show the menu */ |
|
|
|
this.setupEventListeners(el); |
|
|
|
el.addEvent(this.options.trigger, function(e) { |
|
|
|
}.bind(this), this); |
|
|
|
//enabled?
|
|
|
|
|
|
|
|
if (!this.options.disabled) { |
|
|
|
|
|
|
|
//prevent default, if told to
|
|
|
|
|
|
|
|
if (this.options.stopEvent) { |
|
|
|
|
|
|
|
e.stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//record this as the trigger
|
|
|
|
|
|
|
|
this.options.element = $(el); |
|
|
|
|
|
|
|
this.adjustMenuPosition(e); |
|
|
|
|
|
|
|
//show the menu
|
|
|
|
|
|
|
|
this.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
el.addEvent('click', function(e) { |
|
|
|
|
|
|
|
this.hide(); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* menu items */ |
|
|
|
/* menu items */ |
|
|
|
this.menu.getElements('a').each(function(item) { |
|
|
|
this.menu.getElements('a').each(function(item) { |
|
|
|