diff options
Diffstat (limited to 'dist/jquery-impromptu.js')
-rw-r--r-- | dist/jquery-impromptu.js | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/dist/jquery-impromptu.js b/dist/jquery-impromptu.js index 233e010..9f10d69 100644 --- a/dist/jquery-impromptu.js +++ b/dist/jquery-impromptu.js @@ -58,6 +58,7 @@ buttons: {
Ok: true
},
+ buttonTimeout: 1000,
loaded: function(e){},
submit: function(e,v,m,f){},
close: function(e,v,m,f){},
@@ -189,7 +190,7 @@ //build the box and fade
var msgbox = '<div class="'+ opts.prefix +'box '+ opts.classes.box +'">';
if(opts.useiframe && ($('object, applet').length > 0)) {
- msgbox += '<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></iframe>';
+ msgbox += '<iframe src="javascript:false;" class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></iframe>';
} else {
msgbox += '<div class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></div>';
}
@@ -236,11 +237,20 @@ t.jqi.on('click', '.'+ opts.prefix +'buttons button', function(e){
var $t = $(this),
$state = $t.parents('.'+ opts.prefix +'state'),
- stateobj = t.options.states[$state.data('jqi-name')],
+ statename = $state.data('jqi-name'),
+ stateobj = t.options.states[statename],
msg = $state.children('.'+ opts.prefix +'message'),
clicked = stateobj.buttons[$t.text()] || stateobj.buttons[$t.html()],
forminputs = {};
+ // disable for a moment to prevent multiple clicks
+ if(t.options.buttonTimeout > 0){
+ t.disableStateButtons(statename);
+ setTimeout(function(){
+ t.enableStateButtons(statename);
+ }, t.options.buttonTimeout);
+ }
+
// if for some reason we couldn't get the value
if(clicked === undefined){
for(var i in stateobj.buttons){
@@ -441,10 +451,10 @@ showHtml = 'Error: html function must return text';
}
- state += '<div class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'" style="display:none;">'+
+ state += '<div class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'">'+
arrow + title +
'<div class="'+ opts.prefix +'message '+ opts.classes.message +'">' + showHtml +'</div>'+
- '<div class="'+ opts.prefix +'buttons '+ opts.classes.buttons +'"'+ ($.isEmptyObject(stateobj.buttons)? 'style="display:none;"':'') +'>';
+ '<div class="'+ opts.prefix +'buttons'+ ($.isEmptyObject(stateobj.buttons)? 'hide ':' ') + opts.classes.buttons +'">';
// state buttons may be in object or array, lets convert objects to arrays
if($.isArray(stateobj.buttons)){
@@ -474,7 +484,7 @@ state += '</div></div>';
- $state = $(state);
+ $state = $(state).css({display:'none'});
$state.on('impromptu:submit', stateobj.submit);
@@ -577,6 +587,38 @@ },
/**
+ * disableStateButtons - Disables the buttons in a state
+ * @param statename String - Name of the state containing buttons
+ * @param buttons Array - Array of button values to disable. By default all are disabled
+ * @param enable Boolean - True to enable the buttons instead of disabling (internally use only)
+ * @return Void
+ */
+ disableStateButtons: function(statename, buttons, enable) {
+ var t = this;
+
+ if($.isArray(statename)){
+ buttons = statename;
+ statename = null;
+ }
+
+ t.getState(statename || t.getCurrentStateName()).find('.'+ t.options.prefix + 'button').each(function(i,btn){
+ if(buttons === undefined || $.inArray(btn.value, buttons) !== -1){
+ btn.disabled = !enable;
+ }
+ });
+ },
+
+ /**
+ * enableStateButtons - Enables the buttons in a state
+ * @param statename String - Name of the state containing buttons. Defaults to current state
+ * @param buttons Array - Array of button values to enable. By default all are enabled
+ * @return Void
+ */
+ enableStateButtons: function(statename, buttons) {
+ this.disableStateButtons(statename, buttons, true);
+ },
+
+ /**
* position - Repositions the prompt (Used internally)
* @return void
*/
|