Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality for on click event #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion js/jquery.gritter.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tmp = this._tpl_item;

// Assign callbacks
$(['before_open', 'after_open', 'before_close', 'after_close']).each(function(i, val){
$(['before_open', 'after_open', 'before_close', 'after_close','on_click']).each(function(i, val){
Gritter['_' + val + '_' + number] = ($.isFunction(params[val])) ? params[val] : function(){}
});

Expand Down Expand Up @@ -163,6 +163,27 @@
if(!sticky){
this._setFadeTimer(item, number);
}

// Add on_click listener
$(item).click(function(){
Gritter['_' + 'on_click' + '_' + number]($(this));
});

/**
* In order to avoid conflicts between on_click and before/after_close
* Disable on_click event when hover over close button
* Enable on_click event on mouse leave
*/
$(item).find('.gritter-close').bind('mouseenter mouseleave', function(event){
if(event.type == 'mouseenter'){
$(item).off("click");
}
else {
$(item).on("click",function(){
Gritter['_' + 'on_click' + '_' + number]($(this));
});
}
});

// Bind the hover/unhover states
$(item).bind('mouseenter mouseleave', function(event){
Expand Down