summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTrent Richardson <trentdrichardson@gmail.com>2013-12-12 10:15:25 -0500
committerTrent Richardson <trentdrichardson@gmail.com>2013-12-12 10:15:25 -0500
commitcf11a96676a422b840fbf0cb4bbc91200ae06c11 (patch)
tree4f90f1fa455a7ce7b0c14aea203ca72f0f26ef7c /src
parent69ae666cdcec0f982e2d14eefdb33efbf5bad518 (diff)
downloadjQuery-Impromptu-cf11a96676a422b840fbf0cb4bbc91200ae06c11.zip
jQuery-Impromptu-cf11a96676a422b840fbf0cb4bbc91200ae06c11.tar.gz
jQuery-Impromptu-cf11a96676a422b840fbf0cb4bbc91200ae06c11.tar.bz2
Fixes #24 Pressing Enter in sub-state causes page to hang and become unusable
Diffstat (limited to 'src')
-rw-r--r--src/index.html14
-rw-r--r--src/jquery-impromptu.js17
2 files changed, 28 insertions, 3 deletions
diff --git a/src/index.html b/src/index.html
index 7dd9560..74f4d88 100644
--- a/src/index.html
+++ b/src/index.html
@@ -425,6 +425,7 @@ $.prompt(statesdemo);</pre>
$.prompt.close();
}
},
+ /*
state1: {
html:'Are you sure?',
buttons: { No: -1, Yes: 0 },
@@ -437,6 +438,19 @@ $.prompt(statesdemo);</pre>
$.prompt.goToState('state0');
}
},
+ */
+ state1: {
+ html:'Are you sure? &lt;input type="text" name="email" /&gt;',
+ buttons: { No: -1, Yes: 0 },
+ focus: "input[name='email']",
+ submit:function(e,v,m,f){
+ e.preventDefault();
+ if(v==0)
+ $.prompt.goToState('state2');
+ else if(v==-1)
+ $.prompt.goToState('state0');
+ }
+ },
state2: {
title: "You're Done!",
html: "Congratulations, you've finished this example!",
diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js
index dc0970b..6021f97 100644
--- a/src/jquery-impromptu.js
+++ b/src/jquery-impromptu.js
@@ -144,10 +144,21 @@
var key = (window.event) ? event.keyCode : e.keyCode;
//escape key closes
- if(key===27) {
+ if(key === 27) {
fadeClicked();
}
+ //enter key pressed trigger the default button if its not on it, ignore if it is a textarea
+ if(key === 13){
+ var $defBtn = $.prompt.getCurrentState().find('.'+ opts.prefix +'defaultbutton');
+ var $tgt = $(e.target);
+
+ if($tgt.is('textarea,.'+opts.prefix+'button') === false && $defBtn.length > 0){
+ e.preventDefault();
+ $defBtn.click();
+ }
+ }
+
//constrain tabs, tabs should iterate through the state and not leave
if (key === 9){
var $inputels = $('input,select,textarea,button',$.prompt.getCurrentState());
@@ -438,7 +449,7 @@
defbtn = stateobj.focus === i || (isNaN(stateobj.focus) && stateobj.defaultButton === i) ? ($.prompt.currentPrefix + 'defaultbutton ' + opts.classes.defaultButton) : '';
if(typeof v === 'object'){
- state += '<button class="'+ opts.classes.button +' '+ defbtn;
+ state += '<button class="'+ opts.classes.button +' '+ $.prompt.currentPrefix + 'button '+ defbtn;
if(typeof v.classes !== "undefined"){
state += ' '+ ($.isArray(v.classes)? v.classes.join(' ') : v.classes) + ' ';
@@ -447,7 +458,7 @@
state += '" name="' + opts.prefix + '_' + statename + '_button' + v.title.replace(/[^a-z0-9]+/gi,'') + '" id="' + opts.prefix + '_' + statename + '_button' + v.title.replace(/[^a-z0-9]+/gi,'') + '" value="' + v.value + '">' + v.title + '</button>';
} else {
- state += '<button class="'+ opts.classes.button +' '+ defbtn +'" name="' + opts.prefix + '_' + statename + '_button' + k + '" id="' + opts.prefix + '_' + statename + '_button' + k + '" value="' + v + '">' + k + '</button>';
+ state += '<button class="'+ $.prompt.currentPrefix + 'button '+ opts.classes.button +' '+ defbtn +'" name="' + opts.prefix + '_' + statename + '_button' + k + '" id="' + opts.prefix + '_' + statename + '_button' + k + '" value="' + v + '">' + k + '</button>';
}
i++;