Reputation: 573
I am using JqModal in my project. Its a nice JS modal. However i need one help to attach an Close On Escape key press to the JqModal. I am loading eternal content from external URL in JqModal.
For simple Modal where no IFrame is used, its very easy to implement the CloseOnEscape key press feature.
Upvotes: 3
Views: 891
Reputation: 3136
I updated user1233802's answer for the latest version of jqModal (as of 2/21/2014):
Upvotes: 0
Reputation: 573
I made it work by updating the jqModal.js file
Steps:
Add option "closeOnEsc: true" to the jqModal. So the option will look something like this,
var p = {
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F,
closeOnEsc: true
};
Add following code to the jqModal open function.
var modal = $(h.w);
modal.unbind("keydown");
if (c.closeOnEsc) {
modal.attr("tabindex", 0);
modal.bind("keydown", function (event) {
if (event.keyCode == 27) {
event.preventDefault();
modal.jqmHide();
}
});
modal.focus();
}
Upvotes: 5
Reputation: 546
From http://forum.jquery.com/topic/jquery-jqmodal-and-the-esc-key
document.onkeydown = function(e){
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
if(keycode == 27){ // escape, close box
$('.jqmWindow').jqmHide();
}
};
Where '.jqmQWindow' is the window or container you attached jqModal to.
Upvotes: 2