Skip to content

Commit

Permalink
Add Options for the open and close event
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian committed Sep 28, 2010
1 parent eecf27b commit 0ff2b3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -100,7 +100,8 @@ Documentation
- mouseoverDelay - (number: defaults to 0) The time (delay) before the onOpen event get fired
- listSelector - (string: defaults to `ul`) The list tagname
- itemSelector - (string: defaults to `li`) The items tagname

- openEvent - (string: defaults to 'mouseenter') The event name when the menu should open
- closeEvent - (string: defaults to 'mouseleave') The event name when the menu should close

#### Events ####
- open - (function) The function which opens a part of the menu
Expand Down
33 changes: 15 additions & 18 deletions Source/MooDropMenu.js
Expand Up @@ -34,7 +34,9 @@ var MooDropMenu = new Class({
mouseoutDelay: 200,
mouseoverDelay: 0,
listSelector: 'ul',
itemSelector: 'li'
itemSelector: 'li',
openEvent: 'mouseenter',
closeEvent: 'mouseleave'
},

initialize: function(menu, options, level){
Expand All @@ -50,27 +52,22 @@ var MooDropMenu = new Class({
var parent = el.getParent(options.itemSelector),
timer;

parent.addEvents({
parent.addEvent(options.openEvent, function(){
parent.store('DropDownOpen', true);

'mouseenter': function(){
parent.store('DropDownOpen', true);
clearTimeout(timer);
if (options.mouseoverDelay) timer = this.fireEvent.delay(options.mouseoverDelay, this, ['open', el]);
else this.fireEvent('open', el);

clearTimeout(timer);
if (options.mouseoverDelay) timer = this.fireEvent.delay(options.mouseoverDelay, this, ['open', el]);
else this.fireEvent('open', el);
}.bind(this)).addEvent(options.closeEvent, function(){
parent.store('DropDownOpen', false);

}.bind(this),
clearTimeout(timer);
timer = (function(){
if (!parent.retrieve('DropDownOpen')) this.fireEvent('close', el);
}).delay(options.mouseoutDelay, this);

'mouseleave': function(){
parent.store('DropDownOpen', false);

clearTimeout(timer);
timer = (function(){
if (!parent.retrieve('DropDownOpen')) this.fireEvent('close', el);
}).delay(options.mouseoutDelay, this);

}.bind(this)
});
}.bind(this));

}, this);
},
Expand Down

0 comments on commit 0ff2b3a

Please sign in to comment.