Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New option for simplemodal #1

Open
wants to merge 1 commit into from

2 participants

@nicholasbs

Hi,

I wanted to allow any keypress to close my dialog, so I added a new option (anykeyClose, false by default) to simplemodal.

Thanks for an awesome library! It's just what I was looking for and only took a minute to get working.

Best,
-Nick

@ericmmartin
Owner

Thanks Nicholas. I'm not sure that there are enough situations to warrant this change - do you have a use case?

@nicholasbs

My use case was for Hackruiter.com. If you press ? on the frontpage, you'll get a modal dialog with keyboard shortcuts, and I wanted any key press to close the help window.

In general, I think any time you want to have modal display of info/help but make it hard for the user to get caught in it, having any key to close is useful. I've definitely seen other sites that have used this behavior on, but I can't think of them off the top of my head.

Best,
-Nick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 17, 2011
  1. @nicholasbs
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/jquery.simplemodal.js
View
7 src/jquery.simplemodal.js
@@ -152,6 +152,7 @@
SimpleModal will automatically add the closeClass to this element.
* closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
* escClose: (Boolean:true) Allow Esc keypress to close the dialog?
+ * anykeyClose: (Boolean:false) Allow any keypress to close the dialog?
* overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
* position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
* persist: (Boolean:false) Persist the data across modal calls? Only used for existing
@@ -185,6 +186,7 @@
closeHTML: '<a class="modalCloseImg" title="Close"></a>',
closeClass: 'simplemodal-close',
escClose: true,
+ anykeyClose: false,
overlayClose: false,
position: null,
persist: false,
@@ -375,7 +377,10 @@
// bind keydown events
$(document).bind('keydown.simplemodal', function (e) {
- if (s.o.modal && e.keyCode === 9) { // TAB
+ if (s.o.close && s.o.anykeyClose) {
+ e.preventDefault();
+ s.close();
+ } else if (s.o.modal && e.keyCode === 9) { // TAB
s.watchTab(e);
}
else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
Something went wrong with that request. Please try again.