Skip to content

Commit b4bf16c

Browse files
author
Shane Stebner
committed
.off fix
1 parent 9108be2 commit b4bf16c

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

src/jAlert-v3.js

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -509,44 +509,22 @@
509509
/* Bind mouseup handler to document if this alert has closeOnClick enabled */
510510
if( alert.options.closeOnClick ){
511511

512-
/* Unbind any other mouseup */
513-
$(document).off('mouseup');
512+
/* Unbind if already exists */
513+
$(document).off('mouseup', $.fn.jAlert.onMouseUp);
514514

515515
/* Bind mouseup */
516-
$(document).on('mouseup', function(e){
517-
518-
/* Find top visible jAlert and see if it has closeOnClick enabled */
519-
var lastVisibleAlert = $('.jAlert:visible:last');
520-
521-
if( lastVisibleAlert.options.closeOnClick )
522-
{
523-
lastVisibleAlert.closeAlert();
524-
}
525-
526-
});
516+
$(document).on('mouseup', $.fn.jAlert.onMouseUp);
527517

528518
}
529519

530520
/* Bind on keydown handler to document and if esc was pressed, find all visible jAlerts with that close option enabled and close them */
531521
if( alert.options.closeOnEsc ){
532522

533-
$(document).off('keydown');
534-
535-
$(document).on('keydown', function(e){
536-
537-
if(e.keyCode === 27){
523+
/* Unbind if already exists */
524+
$(document).off('keydown', $.fn.jAlert.onEscKeyDown);
538525

539-
/* Find top visible jAlert and see if it has closeOnClick enabled */
540-
var lastVisibleAlert = $('.jAlert:visible:last');
541-
542-
if( lastVisibleAlert.options.closeOnEsc )
543-
{
544-
lastVisibleAlert.closeAlert();
545-
}
546-
547-
}
548-
549-
});
526+
/* Bind keydown */
527+
$(document).on('keydown', $.fn.jAlert.onEscKeyDown);
550528

551529
}
552530

@@ -666,6 +644,37 @@
666644
return false;
667645
}
668646
}
647+
648+
/* Mouseup on document */
649+
$.fn.jAlert.onMouseUp = function(e){
650+
651+
/* Find top visible jAlert and see if it has closeOnClick enabled */
652+
var lastVisibleAlert = $('.jAlert:visible:last');
653+
654+
if( lastVisibleAlert.options.closeOnClick )
655+
{
656+
lastVisibleAlert.closeAlert();
657+
}
658+
659+
};
660+
661+
/* Keydown on document (escape key) */
662+
$.fn.jAlert.onEscKeyDown = function(e){
663+
664+
/* Escape = 27 */
665+
if(e.keyCode === 27){
666+
667+
/* Find top visible jAlert and see if it has closeOnClick enabled */
668+
var lastVisibleAlert = $('.jAlert:visible:last');
669+
670+
if( lastVisibleAlert.options.closeOnEsc )
671+
{
672+
lastVisibleAlert.closeAlert();
673+
}
674+
675+
}
676+
677+
};
669678

670679
/* If you're not using the DOM (aka, you're not hiding or showing a specific alert, you can just use $.jAlert */
671680
$.jAlert = function(options){

src/jAlert-v3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)