summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/jquery-impromptu.js221
-rw-r--r--dist/jquery-impromptu.min.js2
-rw-r--r--src/jquery-impromptu.js105
-rw-r--r--test/jquery-impromptu_spec.js2
4 files changed, 176 insertions, 154 deletions
diff --git a/dist/jquery-impromptu.js b/dist/jquery-impromptu.js
index a488f69..a537db4 100644
--- a/dist/jquery-impromptu.js
+++ b/dist/jquery-impromptu.js
@@ -8,7 +8,7 @@
* setDefaults - Sets the default options
* @param message String/Object - String of html or Object of states
* @param options Object - Options to set the prompt
- * @return jQuery - container with overlay and prompt
+ * @return jQuery - container with overlay and prompt
*/
$.prompt = function(message, options) {
// only for backwards compat, to be removed in future version
@@ -18,7 +18,7 @@
$.prompt.options = $.extend({},$.prompt.defaults,options);
$.prompt.currentPrefix = $.prompt.options.prefix;
-
+
// Be sure any previous timeouts are destroyed
if($.prompt.timeout){
clearTimeout($.prompt.timeout);
@@ -28,7 +28,7 @@
var opts = $.prompt.options,
$body = $(document.body),
$window = $(window);
-
+
//build the box and fade
var msgbox = '<div class="'+ $.prompt.options.prefix +'box '+ opts.classes.box +'">';
if(opts.useiframe && ($('object, applet').length > 0)) {
@@ -100,8 +100,8 @@
} else if (typeof forminputs[obj.name] === Array || typeof forminputs[obj.name] === 'object') {
forminputs[obj.name].push(obj.value);
} else {
- forminputs[obj.name] = [forminputs[obj.name],obj.value];
- }
+ forminputs[obj.name] = [forminputs[obj.name],obj.value];
+ }
});
// trigger an event
@@ -109,7 +109,7 @@
promptsubmite.stateName = stateobj.name;
promptsubmite.state = $state;
$state.trigger(promptsubmite, [clicked, msg, forminputs]);
-
+
if(!promptsubmite.isDefaultPrevented()){
$.prompt.close(true, clicked,msg,forminputs);
}
@@ -138,21 +138,21 @@
$.prompt.close(true);
}
};
-
+
// listen for esc or tab keys
var keyDownEventHandler = function(e){
var key = (window.event) ? event.keyCode : e.keyCode;
-
+
//escape key closes
if(key === 27) {
- fadeClicked();
+ 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();
@@ -165,7 +165,7 @@
var fwd = !e.shiftKey && e.target === $inputels[$inputels.length-1];
var back = e.shiftKey && e.target === $inputels[0];
if (fwd || back) {
- setTimeout(function(){
+ setTimeout(function(){
if (!$inputels){
return;
}
@@ -179,10 +179,10 @@
}
}
};
-
+
$.prompt.position();
$.prompt.style();
-
+
$.prompt.jqif.click(fadeClicked);
$window.resize({animate:false}, $.prompt.position);
$.prompt.jqi.find('.'+ opts.prefix +'close').click($.prompt.close);
@@ -201,7 +201,7 @@
$.prompt.jqib.trigger('impromptu:loaded');
});
-
+
// Timeout
if(opts.timeout > 0){
$.prompt.timeout = setTimeout(function(){ $.prompt.close(true); },opts.timeout);
@@ -209,7 +209,7 @@
return $.prompt.jqib;
};
-
+
$.prompt.defaults = {
prefix:'jqi',
classes: {
@@ -243,9 +243,9 @@
defaultButton: 0,
useiframe: false,
top: '15%',
- position: {
- container: null,
- x: null,
+ position: {
+ container: null,
+ x: null,
y: null,
arrow: null,
width: null
@@ -262,9 +262,9 @@
},
focus: 0,
defaultButton: 0,
- position: {
- container: null,
- x: null,
+ position: {
+ container: null,
+ x: null,
y: null,
arrow: null,
width: null
@@ -274,19 +274,19 @@
}
}
};
-
+
/**
- * currentPrefix String - At any time this show be the prefix
+ * currentPrefix String - At any time this show be the prefix
* of the current prompt ex: "jqi"
*/
$.prompt.currentPrefix = $.prompt.defaults.prefix;
-
+
/**
* currentStateName String - At any time this is the current state
* of the current prompt ex: "state0"
*/
$.prompt.currentStateName = "";
-
+
/**
* setDefaults - Sets the default options
* @param o Object - Options to set as defaults
@@ -295,7 +295,7 @@
$.prompt.setDefaults = function(o) {
$.prompt.defaults = $.extend({}, $.prompt.defaults, o);
};
-
+
/**
* setStateDefaults - Sets the default options for a state
* @param o Object - Options to set as defaults
@@ -319,14 +319,14 @@
windowHeight = $(window).height(),
documentHeight = $(document).height(),
height = bodyHeight > windowHeight ? bodyHeight : windowHeight,
- top = parseInt($window.scrollTop(),10) + ($.prompt.options.top.toString().indexOf('%') >= 0?
+ top = parseInt($window.scrollTop(),10) + ($.prompt.options.top.toString().indexOf('%') >= 0?
(windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10));
// when resizing the window turn off animation
if(e !== undefined && e.data.animate === false){
$.fx.off = true;
}
-
+
$.prompt.jqib.css({
position: "absolute",
height: height,
@@ -349,7 +349,7 @@
// tour positioning
if(pos && pos.container){
var offset = $(pos.container).offset();
-
+
if($.isPlainObject(offset) && offset.top !== undefined){
$.prompt.jqi.css({
position: "absolute"
@@ -392,7 +392,7 @@
$.fx.off = restoreFx;
}
};
-
+
/**
* style - Restyles the prompt (Used internally)
* @return void
@@ -444,32 +444,38 @@
if(stateobj.title && stateobj.title !== ''){
title = '<div class="lead '+ opts.prefix + 'title '+ opts.classes.title +'">'+ stateobj.title +'</div>';
}
- state += '<div id="'+ opts.prefix +'state_'+ statename +'" class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'" style="display:none;">'+
+
+ var showHtml = stateobj.html;
+ if (typeof stateobj.html === 'function') {
+ showHtml = 'Error: html function must return text';
+ }
+
+ state += '<div id="'+ opts.prefix +'state_'+ statename +'" class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'" style="display:none;">'+
arrow + title +
- '<div class="'+ opts.prefix +'message '+ opts.classes.message +'">' + stateobj.html +'</div>'+
+ '<div class="'+ opts.prefix +'message '+ opts.classes.message +'">' + showHtml +'</div>'+
'<div class="'+ opts.prefix +'buttons '+ opts.classes.buttons +'"'+ ($.isEmptyObject(stateobj.buttons)? 'style="display:none;"':'') +'>';
-
+
for(k in stateobj.buttons){
v = stateobj.buttons[k],
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 +' '+ $.prompt.currentPrefix + 'button '+ defbtn;
-
+
if(typeof v.classes !== "undefined"){
state += ' '+ ($.isArray(v.classes)? v.classes.join(' ') : v.classes) + ' ';
}
-
+
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="'+ $.prompt.currentPrefix + 'button '+ opts.classes.button +' '+ defbtn +'" name="' + opts.prefix + '_' + statename + '_button' + k.replace(/[^a-z0-9]+/gi,'') + '" id="' + opts.prefix + '_' + statename + '_button' + k.replace(/[^a-z0-9]+/gi,'') + '" value="' + v + '">' + k + '</button>';
-
+
}
i++;
}
state += '</div></div>';
-
+
$state = $(state);
$state.on('impromptu:submit', stateobj.submit);
@@ -485,7 +491,7 @@
return $state;
};
-
+
/**
* removeState - Removes a state from the prompt
* @param state String - Name of the state
@@ -499,7 +505,7 @@
if($state.length === 0){
return false;
}
-
+
// transition away from it before deleting
if($state.css('display') !== 'none'){
if(newState !== undefined && $.prompt.getState(newState).length > 0){
@@ -533,7 +539,7 @@
$.prompt.getStateContent = function(state) {
return $.prompt.getState(state);
};
-
+
/**
* getCurrentState - Get the current visible state
* @return jQuery - the current visible state
@@ -541,7 +547,7 @@
$.prompt.getCurrentState = function() {
return $.prompt.getState($.prompt.getCurrentStateName());
};
-
+
/**
* getCurrentStateName - Get the name of the current visible state
* @return String - the current visible state's name
@@ -549,77 +555,88 @@
$.prompt.getCurrentStateName = function() {
return $.prompt.currentStateName;
};
-
+
/**
* goToState - Goto the specified state
* @param state String - name of the state to transition to
* @param subState Boolean - true to be a sub state within the currently open state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
- */
+ */
$.prompt.goToState = function(state, subState, callback) {
var $jqi = $.prompt.get(),
jqiopts = $.prompt.options,
$state = $.prompt.getState(state),
stateobj = jqiopts.states[$state.data('jqi-name')],
- promptstatechanginge = new $.Event('impromptu:statechanging');
-
- // subState can be ommitted
- if(typeof subState === 'function'){
- callback = subState;
- subState = false;
- }
-
- $.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
-
- if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'parentstate').removeClass($.prompt.currentPrefix +'parentstate');
+ promptstatechanginge = new $.Event('impromptu:statechanging'),
+ opts = $.prompt.options;
- if(subState){ // hide any open substates
- // get rid of any substates
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'substate').not($state)
- .slideUp(jqiopts.promptspeed)
- .removeClass('.'+ $.prompt.currentPrefix +'substate')
- .find('.'+ $.prompt.currentPrefix +'arrow').hide();
+ if(stateobj !== undefined){
- // add parent state class so it can be visible, but blocked
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state:visible').addClass($.prompt.currentPrefix +'parentstate');
- // add substate class so we know it will be smaller
- $state.addClass($.prompt.currentPrefix +'substate');
+ if (typeof stateobj.html === 'function') {
+ var contentLaterFunc = stateobj.html;
+ $state.find('.' + opts.prefix +'message ').html(contentLaterFunc());
}
- else{ // hide any open states
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state').not($state)
- .slideUp(jqiopts.promptspeed)
- .find('.'+ $.prompt.currentPrefix +'arrow').hide();
+
+ // subState can be ommitted
+ if(typeof subState === 'function'){
+ callback = subState;
+ subState = false;
}
- $.prompt.currentStateName = stateobj.name;
- $state.slideDown(jqiopts.promptspeed,function(){
- var $t = $(this);
+ $.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
+
+ if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'parentstate').removeClass($.prompt.currentPrefix +'parentstate');
+
+ if(subState){ // hide any open substates
+ // get rid of any substates
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'substate').not($state)
+ .slideUp(jqiopts.promptspeed)
+ .removeClass('.'+ $.prompt.currentPrefix +'substate')
+ .find('.'+ $.prompt.currentPrefix +'arrow').hide();
- // if focus is a selector, find it, else its button index
- if(typeof(stateobj.focus) === 'string'){
- $t.find(stateobj.focus).eq(0).focus();
+ // add parent state class so it can be visible, but blocked
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state:visible').addClass($.prompt.currentPrefix +'parentstate');
+
+ // add substate class so we know it will be smaller
+ $state.addClass($.prompt.currentPrefix +'substate');
}
- else{
- $t.find('.'+ $.prompt.currentPrefix +'defaultbutton').focus();
+ else{ // hide any open states
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state').not($state)
+ .slideUp(jqiopts.promptspeed)
+ .find('.'+ $.prompt.currentPrefix +'arrow').hide();
}
+ $.prompt.currentStateName = stateobj.name;
- $t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
-
- if (typeof callback === 'function'){
- $.prompt.jqib.on('impromptu:statechanged', callback);
- }
- $.prompt.jqib.trigger('impromptu:statechanged', [state]);
- if (typeof callback === 'function'){
- $.prompt.jqib.off('impromptu:statechanged', callback);
+ $state.slideDown(jqiopts.promptspeed,function(){
+ var $t = $(this);
+
+ // if focus is a selector, find it, else its button index
+ if(typeof(stateobj.focus) === 'string'){
+ $t.find(stateobj.focus).eq(0).focus();
+ }
+ else{
+ $t.find('.'+ $.prompt.currentPrefix +'defaultbutton').focus();
+ }
+
+ $t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
+
+ if (typeof callback === 'function'){
+ $.prompt.jqib.on('impromptu:statechanged', callback);
+ }
+ $.prompt.jqib.trigger('impromptu:statechanged', [state]);
+ if (typeof callback === 'function'){
+ $.prompt.jqib.off('impromptu:statechanged', callback);
+ }
+ });
+ if(!subState){
+ $.prompt.position();
}
- });
- if(!subState){
- $.prompt.position();
- }
- }
+ } // end isDefaultPrevented()
+ }// end stateobj !== undefined
+
return $state;
};
@@ -627,7 +644,7 @@
* nextState - Transition to the next state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
- */
+ */
$.prompt.nextState = function(callback) {
var $next = $('#'+ $.prompt.currentPrefix +'state_'+ $.prompt.getCurrentStateName()).next();
if($next.length > 0){
@@ -635,12 +652,12 @@
}
return $next;
};
-
+
/**
* prevState - Transition to the previous state
* @param callback Function - called when the transition is complete
* @return jQuery - the newly active state
- */
+ */
$.prompt.prevState = function(callback) {
var $prev = $('#'+ $.prompt.currentPrefix +'state_'+ $.prompt.getCurrentStateName()).prev();
if($prev.length > 0){
@@ -648,7 +665,7 @@
}
return $prev;
};
-
+
/**
* close - Closes the prompt
* @param callback Function - called when the transition is complete
@@ -656,7 +673,7 @@
* @param msg jQuery - The state message body (only used internally)
* @param forvals Object - key/value pairs of all form field names and values (only used internally)
* @return jQuery - the newly active state
- */
+ */
$.prompt.close = function(callCallback, clicked, msg, formvals){
if($.prompt.timeout){
clearTimeout($.prompt.timeout);
@@ -667,15 +684,15 @@
$.prompt.jqib.fadeOut('fast',function(){
$.prompt.jqib.trigger('impromptu:close', [clicked,msg,formvals]);
-
+
$.prompt.jqib.remove();
-
+
$(window).off('resize',$.prompt.position);
});
}
$.prompt.currentStateName = "";
};
-
+
/**
* Enable using $('.selector').prompt({});
* This will grab the html within the prompt as the prompt message
@@ -687,8 +704,8 @@
if(options.withDataAndEvents === undefined){
options.withDataAndEvents = false;
}
-
+
$.prompt($(this).clone(options.withDataAndEvents).html(),options);
};
-
+
})(jQuery);
diff --git a/dist/jquery-impromptu.min.js b/dist/jquery-impromptu.min.js
index 1cd696c..b2e1f4d 100644
--- a/dist/jquery-impromptu.min.js
+++ b/dist/jquery-impromptu.min.js
@@ -1,4 +1,4 @@
/*! jQuery-Impromptu - v5.2.5 - 2014-05-26
* http://trentrichardson.com/Impromptu
* Copyright (c) 2014 Trent Richardson; Licensed MIT */
-(function(t){"use strict";t.prompt=function(e,o){void 0!==o&&void 0!==o.classes&&"string"==typeof o.classes&&(o={box:o.classes}),t.prompt.options=t.extend({},t.prompt.defaults,o),t.prompt.currentPrefix=t.prompt.options.prefix,t.prompt.timeout&&clearTimeout(t.prompt.timeout),t.prompt.timeout=!1;var p=t.prompt.options,r=t(document.body),i=t(window),n='<div class="'+t.prompt.options.prefix+"box "+p.classes.box+'">';n+=p.useiframe&&t("object, applet").length>0?'<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+p.prefix+"fade "+p.classes.fade+'"></iframe>':'<div class="'+p.prefix+"fade "+p.classes.fade+'"></div>',n+='<div class="'+p.prefix+" "+p.classes.prompt+'">'+'<form action="javascript:false;" onsubmit="return false;" class="'+p.prefix+"form "+p.classes.form+'">'+'<div class="'+p.prefix+"close "+p.classes.close+'">'+p.closeText+"</div>"+'<div class="'+p.prefix+'states"></div>'+"</form>"+"</div>"+"</div>",t.prompt.jqib=t(n).appendTo(r),t.prompt.jqi=t.prompt.jqib.children("."+p.prefix),t.prompt.jqif=t.prompt.jqib.children("."+p.prefix+"fade"),e.constructor===String&&(e={state0:{title:p.title,html:e,buttons:p.buttons,position:p.position,focus:p.focus,defaultButton:p.defaultButton,submit:p.submit}}),t.prompt.options.states={};var s,a;for(s in e)a=t.extend({},t.prompt.defaults.state,{name:s},e[s]),t.prompt.addState(a.name,a),""===t.prompt.currentStateName&&(t.prompt.currentStateName=a.name);t.prompt.jqi.on("click","."+p.prefix+"buttons button",function(){var e=t(this),o=e.parents("."+p.prefix+"state"),r=t.prompt.options.states[o.data("jqi-name")],i=o.children("."+p.prefix+"message"),n=r.buttons[e.text()]||r.buttons[e.html()],s={};if(void 0===n)for(var a in r.buttons)(r.buttons[a].title===e.text()||r.buttons[a].title===e.html())&&(n=r.buttons[a].value);t.each(t.prompt.jqi.children("form").serializeArray(),function(t,e){void 0===s[e.name]?s[e.name]=e.value:typeof s[e.name]===Array||"object"==typeof s[e.name]?s[e.name].push(e.value):s[e.name]=[s[e.name],e.value]});var m=new t.Event("impromptu:submit");m.stateName=r.name,m.state=o,o.trigger(m,[n,i,s]),m.isDefaultPrevented()||t.prompt.close(!0,n,i,s)});var m=function(){if(p.persistent){var e=(""+p.top).indexOf("%")>=0?i.height()*(parseInt(p.top,10)/100):parseInt(p.top,10),o=parseInt(t.prompt.jqi.css("top").replace("px",""),10)-e;t("html,body").animate({scrollTop:o},"fast",function(){var e=0;t.prompt.jqib.addClass(p.prefix+"warning");var o=setInterval(function(){t.prompt.jqib.toggleClass(p.prefix+"warning"),e++>1&&(clearInterval(o),t.prompt.jqib.removeClass(p.prefix+"warning"))},100)})}else t.prompt.close(!0)},u=function(e){var o=window.event?event.keyCode:e.keyCode;if(27===o&&m(),13===o){var r=t.prompt.getCurrentState().find("."+p.prefix+"defaultbutton"),i=t(e.target);i.is("textarea,."+p.prefix+"button")===!1&&r.length>0&&(e.preventDefault(),r.click())}if(9===o){var n=t("input,select,textarea,button",t.prompt.getCurrentState()),s=!e.shiftKey&&e.target===n[n.length-1],a=e.shiftKey&&e.target===n[0];if(s||a)return setTimeout(function(){if(n){var t=n[a===!0?n.length-1:0];t&&t.focus()}},10),!1}};return t.prompt.position(),t.prompt.style(),t.prompt.jqif.click(m),i.resize({animate:!1},t.prompt.position),t.prompt.jqi.find("."+p.prefix+"close").click(t.prompt.close),t.prompt.jqib.on("keydown",u).on("impromptu:loaded",p.loaded).on("impromptu:close",p.close).on("impromptu:statechanging",p.statechanging).on("impromptu:statechanged",p.statechanged),t.prompt.jqif[p.show](p.overlayspeed),t.prompt.jqi[p.show](p.promptspeed,function(){var e=t.prompt.jqi.find("."+p.prefix+"states ."+p.prefix+"state").eq(0);t.prompt.goToState(e.data("jqi-name")),t.prompt.jqib.trigger("impromptu:loaded")}),p.timeout>0&&(t.prompt.timeout=setTimeout(function(){t.prompt.close(!0)},p.timeout)),t.prompt.jqib},t.prompt.defaults={prefix:"jqi",classes:{box:"",fade:"",prompt:"",form:"",close:"",title:"",message:"",buttons:"",button:"",defaultButton:""},title:"",closeText:"&times;",buttons:{Ok:!0},loaded:function(){},submit:function(){},close:function(){},statechanging:function(){},statechanged:function(){},opacity:.6,zIndex:999,overlayspeed:"slow",promptspeed:"fast",show:"fadeIn",focus:0,defaultButton:0,useiframe:!1,top:"15%",position:{container:null,x:null,y:null,arrow:null,width:null},persistent:!0,timeout:0,states:{},state:{name:null,title:"",html:"",buttons:{Ok:!0},focus:0,defaultButton:0,position:{container:null,x:null,y:null,arrow:null,width:null},submit:function(){return!0}}},t.prompt.currentPrefix=t.prompt.defaults.prefix,t.prompt.currentStateName="",t.prompt.setDefaults=function(e){t.prompt.defaults=t.extend({},t.prompt.defaults,e)},t.prompt.setStateDefaults=function(e){t.prompt.defaults.state=t.extend({},t.prompt.defaults.state,e)},t.prompt.position=function(e){var o=t.fx.off,p=t.prompt.getCurrentState(),r=t.prompt.options.states[p.data("jqi-name")],i=r?r.position:void 0,n=t(window),s=document.body.scrollHeight,a=t(window).height(),m=(t(document).height(),s>a?s:a),u=parseInt(n.scrollTop(),10)+((""+t.prompt.options.top).indexOf("%")>=0?a*(parseInt(t.prompt.options.top,10)/100):parseInt(t.prompt.options.top,10));if(void 0!==e&&e.data.animate===!1&&(t.fx.off=!0),t.prompt.jqib.css({position:"absolute",height:m,width:"100%",top:0,left:0,right:0,bottom:0}),t.prompt.jqif.css({position:"fixed",height:m,width:"100%",top:0,left:0,right:0,bottom:0}),i&&i.container){var l=t(i.container).offset();t.isPlainObject(l)&&void 0!==l.top&&(t.prompt.jqi.css({position:"absolute"}),t.prompt.jqi.animate({top:l.top+i.y,left:l.left+i.x,marginLeft:0,width:void 0!==i.width?i.width:null}),u=l.top+i.y-((""+t.prompt.options.top).indexOf("%")>=0?a*(parseInt(t.prompt.options.top,10)/100):parseInt(t.prompt.options.top,10)),t("html,body").animate({scrollTop:u},"slow","swing",function(){}))}else i&&i.width?(t.prompt.jqi.css({position:"absolute",left:"50%"}),t.prompt.jqi.animate({top:i.y||u,left:i.x||"50%",marginLeft:-1*(i.width/2),width:i.width})):t.prompt.jqi.css({position:"absolute",top:u,left:"50%",marginLeft:-1*(t.prompt.jqi.outerWidth(!1)/2)});void 0!==e&&e.data.animate===!1&&(t.fx.off=o)},t.prompt.style=function(){t.prompt.jqif.css({zIndex:t.prompt.options.zIndex,display:"none",opacity:t.prompt.options.opacity}),t.prompt.jqi.css({zIndex:t.prompt.options.zIndex+1,display:"none"}),t.prompt.jqib.css({zIndex:t.prompt.options.zIndex})},t.prompt.get=function(){return t("."+t.prompt.currentPrefix)},t.prompt.addState=function(e,o,p){var r,i,n,s="",a=null,m="",u="",l=t.prompt.options,f=t("."+t.prompt.currentPrefix+"states"),c=0;o=t.extend({},t.prompt.defaults.state,{name:e},o),null!==o.position.arrow&&(m='<div class="'+l.prefix+"arrow "+l.prefix+"arrow"+o.position.arrow+'"></div>'),o.title&&""!==o.title&&(u='<div class="lead '+l.prefix+"title "+l.classes.title+'">'+o.title+"</div>"),s+='<div id="'+l.prefix+"state_"+e+'" class="'+l.prefix+'state" data-jqi-name="'+e+'" style="display:none;">'+m+u+'<div class="'+l.prefix+"message "+l.classes.message+'">'+o.html+"</div>"+'<div class="'+l.prefix+"buttons "+l.classes.buttons+'"'+(t.isEmptyObject(o.buttons)?'style="display:none;"':"")+">";for(i in o.buttons)n=o.buttons[i],r=o.focus===c||isNaN(o.focus)&&o.defaultButton===c?t.prompt.currentPrefix+"defaultbutton "+l.classes.defaultButton:"","object"==typeof n?(s+='<button class="'+l.classes.button+" "+t.prompt.currentPrefix+"button "+r,n.classes!==void 0&&(s+=" "+(t.isArray(n.classes)?n.classes.join(" "):n.classes)+" "),s+='" name="'+l.prefix+"_"+e+"_button"+n.title.replace(/[^a-z0-9]+/gi,"")+'" id="'+l.prefix+"_"+e+"_button"+n.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+n.value+'">'+n.title+"</button>"):s+='<button class="'+t.prompt.currentPrefix+"button "+l.classes.button+" "+r+'" name="'+l.prefix+"_"+e+"_button"+i.replace(/[^a-z0-9]+/gi,"")+'" id="'+l.prefix+"_"+e+"_button"+i.replace(/[^a-z0-9]+/gi,"")+'" value="'+n+'">'+i+"</button>",c++;return s+="</div></div>",a=t(s),a.on("impromptu:submit",o.submit),void 0!==p?f.find("#"+t.prompt.currentPrefix+"state_"+p).after(a):f.append(a),t.prompt.options.states[e]=o,a},t.prompt.removeState=function(e,o){var p=t.prompt.getState(e),r=function(){p.remove()};return 0===p.length?!1:("none"!==p.css("display")?void 0!==o&&t.prompt.getState(o).length>0?t.prompt.goToState(o,!1,r):p.next().length>0?t.prompt.nextState(r):p.prev().length>0?t.prompt.prevState(r):t.prompt.close():p.slideUp("slow",r),!0)},t.prompt.getState=function(e){return t("#"+t.prompt.currentPrefix+"state_"+e)},t.prompt.getStateContent=function(e){return t.prompt.getState(e)},t.prompt.getCurrentState=function(){return t.prompt.getState(t.prompt.getCurrentStateName())},t.prompt.getCurrentStateName=function(){return t.prompt.currentStateName},t.prompt.goToState=function(e,o,p){var r=(t.prompt.get(),t.prompt.options),i=t.prompt.getState(e),n=r.states[i.data("jqi-name")],s=new t.Event("impromptu:statechanging");return"function"==typeof o&&(p=o,o=!1),t.prompt.jqib.trigger(s,[t.prompt.getCurrentStateName(),e]),!s.isDefaultPrevented()&&i.length>0&&(t.prompt.jqi.find("."+t.prompt.currentPrefix+"parentstate").removeClass(t.prompt.currentPrefix+"parentstate"),o?(t.prompt.jqi.find("."+t.prompt.currentPrefix+"substate").not(i).slideUp(r.promptspeed).removeClass("."+t.prompt.currentPrefix+"substate").find("."+t.prompt.currentPrefix+"arrow").hide(),t.prompt.jqi.find("."+t.prompt.currentPrefix+"state:visible").addClass(t.prompt.currentPrefix+"parentstate"),i.addClass(t.prompt.currentPrefix+"substate")):t.prompt.jqi.find("."+t.prompt.currentPrefix+"state").not(i).slideUp(r.promptspeed).find("."+t.prompt.currentPrefix+"arrow").hide(),t.prompt.currentStateName=n.name,i.slideDown(r.promptspeed,function(){var o=t(this);"string"==typeof n.focus?o.find(n.focus).eq(0).focus():o.find("."+t.prompt.currentPrefix+"defaultbutton").focus(),o.find("."+t.prompt.currentPrefix+"arrow").show(r.promptspeed),"function"==typeof p&&t.prompt.jqib.on("impromptu:statechanged",p),t.prompt.jqib.trigger("impromptu:statechanged",[e]),"function"==typeof p&&t.prompt.jqib.off("impromptu:statechanged",p)}),o||t.prompt.position()),i},t.prompt.nextState=function(e){var o=t("#"+t.prompt.currentPrefix+"state_"+t.prompt.getCurrentStateName()).next();return o.length>0&&t.prompt.goToState(o.attr("id").replace(t.prompt.currentPrefix+"state_",""),e),o},t.prompt.prevState=function(e){var o=t("#"+t.prompt.currentPrefix+"state_"+t.prompt.getCurrentStateName()).prev();return o.length>0&&t.prompt.goToState(o.attr("id").replace(t.prompt.currentPrefix+"state_",""),e),o},t.prompt.close=function(e,o,p,r){t.prompt.timeout&&(clearTimeout(t.prompt.timeout),t.prompt.timeout=!1),t.prompt.jqib&&t.prompt.jqib.fadeOut("fast",function(){t.prompt.jqib.trigger("impromptu:close",[o,p,r]),t.prompt.jqib.remove(),t(window).off("resize",t.prompt.position)}),t.prompt.currentStateName=""},t.fn.prompt=function(e){void 0===e&&(e={}),void 0===e.withDataAndEvents&&(e.withDataAndEvents=!1),t.prompt(t(this).clone(e.withDataAndEvents).html(),e)}})(jQuery); \ No newline at end of file
+(function(t){"use strict";t.prompt=function(e,o){void 0!==o&&void 0!==o.classes&&"string"==typeof o.classes&&(o={box:o.classes}),t.prompt.options=t.extend({},t.prompt.defaults,o),t.prompt.currentPrefix=t.prompt.options.prefix,t.prompt.timeout&&clearTimeout(t.prompt.timeout),t.prompt.timeout=!1;var p=t.prompt.options,r=t(document.body),i=t(window),n='<div class="'+t.prompt.options.prefix+"box "+p.classes.box+'">';n+=p.useiframe&&t("object, applet").length>0?'<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+p.prefix+"fade "+p.classes.fade+'"></iframe>':'<div class="'+p.prefix+"fade "+p.classes.fade+'"></div>',n+='<div class="'+p.prefix+" "+p.classes.prompt+'">'+'<form action="javascript:false;" onsubmit="return false;" class="'+p.prefix+"form "+p.classes.form+'">'+'<div class="'+p.prefix+"close "+p.classes.close+'">'+p.closeText+"</div>"+'<div class="'+p.prefix+'states"></div>'+"</form>"+"</div>"+"</div>",t.prompt.jqib=t(n).appendTo(r),t.prompt.jqi=t.prompt.jqib.children("."+p.prefix),t.prompt.jqif=t.prompt.jqib.children("."+p.prefix+"fade"),e.constructor===String&&(e={state0:{title:p.title,html:e,buttons:p.buttons,position:p.position,focus:p.focus,defaultButton:p.defaultButton,submit:p.submit}}),t.prompt.options.states={};var s,a;for(s in e)a=t.extend({},t.prompt.defaults.state,{name:s},e[s]),t.prompt.addState(a.name,a),""===t.prompt.currentStateName&&(t.prompt.currentStateName=a.name);t.prompt.jqi.on("click","."+p.prefix+"buttons button",function(){var e=t(this),o=e.parents("."+p.prefix+"state"),r=t.prompt.options.states[o.data("jqi-name")],i=o.children("."+p.prefix+"message"),n=r.buttons[e.text()]||r.buttons[e.html()],s={};if(void 0===n)for(var a in r.buttons)(r.buttons[a].title===e.text()||r.buttons[a].title===e.html())&&(n=r.buttons[a].value);t.each(t.prompt.jqi.children("form").serializeArray(),function(t,e){void 0===s[e.name]?s[e.name]=e.value:typeof s[e.name]===Array||"object"==typeof s[e.name]?s[e.name].push(e.value):s[e.name]=[s[e.name],e.value]});var m=new t.Event("impromptu:submit");m.stateName=r.name,m.state=o,o.trigger(m,[n,i,s]),m.isDefaultPrevented()||t.prompt.close(!0,n,i,s)});var m=function(){if(p.persistent){var e=(""+p.top).indexOf("%")>=0?i.height()*(parseInt(p.top,10)/100):parseInt(p.top,10),o=parseInt(t.prompt.jqi.css("top").replace("px",""),10)-e;t("html,body").animate({scrollTop:o},"fast",function(){var e=0;t.prompt.jqib.addClass(p.prefix+"warning");var o=setInterval(function(){t.prompt.jqib.toggleClass(p.prefix+"warning"),e++>1&&(clearInterval(o),t.prompt.jqib.removeClass(p.prefix+"warning"))},100)})}else t.prompt.close(!0)},u=function(e){var o=window.event?event.keyCode:e.keyCode;if(27===o&&m(),13===o){var r=t.prompt.getCurrentState().find("."+p.prefix+"defaultbutton"),i=t(e.target);i.is("textarea,."+p.prefix+"button")===!1&&r.length>0&&(e.preventDefault(),r.click())}if(9===o){var n=t("input,select,textarea,button",t.prompt.getCurrentState()),s=!e.shiftKey&&e.target===n[n.length-1],a=e.shiftKey&&e.target===n[0];if(s||a)return setTimeout(function(){if(n){var t=n[a===!0?n.length-1:0];t&&t.focus()}},10),!1}};return t.prompt.position(),t.prompt.style(),t.prompt.jqif.click(m),i.resize({animate:!1},t.prompt.position),t.prompt.jqi.find("."+p.prefix+"close").click(t.prompt.close),t.prompt.jqib.on("keydown",u).on("impromptu:loaded",p.loaded).on("impromptu:close",p.close).on("impromptu:statechanging",p.statechanging).on("impromptu:statechanged",p.statechanged),t.prompt.jqif[p.show](p.overlayspeed),t.prompt.jqi[p.show](p.promptspeed,function(){var e=t.prompt.jqi.find("."+p.prefix+"states ."+p.prefix+"state").eq(0);t.prompt.goToState(e.data("jqi-name")),t.prompt.jqib.trigger("impromptu:loaded")}),p.timeout>0&&(t.prompt.timeout=setTimeout(function(){t.prompt.close(!0)},p.timeout)),t.prompt.jqib},t.prompt.defaults={prefix:"jqi",classes:{box:"",fade:"",prompt:"",form:"",close:"",title:"",message:"",buttons:"",button:"",defaultButton:""},title:"",closeText:"&times;",buttons:{Ok:!0},loaded:function(){},submit:function(){},close:function(){},statechanging:function(){},statechanged:function(){},opacity:.6,zIndex:999,overlayspeed:"slow",promptspeed:"fast",show:"fadeIn",focus:0,defaultButton:0,useiframe:!1,top:"15%",position:{container:null,x:null,y:null,arrow:null,width:null},persistent:!0,timeout:0,states:{},state:{name:null,title:"",html:"",buttons:{Ok:!0},focus:0,defaultButton:0,position:{container:null,x:null,y:null,arrow:null,width:null},submit:function(){return!0}}},t.prompt.currentPrefix=t.prompt.defaults.prefix,t.prompt.currentStateName="",t.prompt.setDefaults=function(e){t.prompt.defaults=t.extend({},t.prompt.defaults,e)},t.prompt.setStateDefaults=function(e){t.prompt.defaults.state=t.extend({},t.prompt.defaults.state,e)},t.prompt.position=function(e){var o=t.fx.off,p=t.prompt.getCurrentState(),r=t.prompt.options.states[p.data("jqi-name")],i=r?r.position:void 0,n=t(window),s=document.body.scrollHeight,a=t(window).height(),m=(t(document).height(),s>a?s:a),u=parseInt(n.scrollTop(),10)+((""+t.prompt.options.top).indexOf("%")>=0?a*(parseInt(t.prompt.options.top,10)/100):parseInt(t.prompt.options.top,10));if(void 0!==e&&e.data.animate===!1&&(t.fx.off=!0),t.prompt.jqib.css({position:"absolute",height:m,width:"100%",top:0,left:0,right:0,bottom:0}),t.prompt.jqif.css({position:"fixed",height:m,width:"100%",top:0,left:0,right:0,bottom:0}),i&&i.container){var f=t(i.container).offset();t.isPlainObject(f)&&void 0!==f.top&&(t.prompt.jqi.css({position:"absolute"}),t.prompt.jqi.animate({top:f.top+i.y,left:f.left+i.x,marginLeft:0,width:void 0!==i.width?i.width:null}),u=f.top+i.y-((""+t.prompt.options.top).indexOf("%")>=0?a*(parseInt(t.prompt.options.top,10)/100):parseInt(t.prompt.options.top,10)),t("html,body").animate({scrollTop:u},"slow","swing",function(){}))}else i&&i.width?(t.prompt.jqi.css({position:"absolute",left:"50%"}),t.prompt.jqi.animate({top:i.y||u,left:i.x||"50%",marginLeft:-1*(i.width/2),width:i.width})):t.prompt.jqi.css({position:"absolute",top:u,left:"50%",marginLeft:-1*(t.prompt.jqi.outerWidth(!1)/2)});void 0!==e&&e.data.animate===!1&&(t.fx.off=o)},t.prompt.style=function(){t.prompt.jqif.css({zIndex:t.prompt.options.zIndex,display:"none",opacity:t.prompt.options.opacity}),t.prompt.jqi.css({zIndex:t.prompt.options.zIndex+1,display:"none"}),t.prompt.jqib.css({zIndex:t.prompt.options.zIndex})},t.prompt.get=function(){return t("."+t.prompt.currentPrefix)},t.prompt.addState=function(e,o,p){var r,i,n,s="",a=null,m="",u="",f=t.prompt.options,l=t("."+t.prompt.currentPrefix+"states"),c=0;o=t.extend({},t.prompt.defaults.state,{name:e},o),null!==o.position.arrow&&(m='<div class="'+f.prefix+"arrow "+f.prefix+"arrow"+o.position.arrow+'"></div>'),o.title&&""!==o.title&&(u='<div class="lead '+f.prefix+"title "+f.classes.title+'">'+o.title+"</div>");var d=o.html;"function"==typeof o.html&&(d="Error: html function must return text"),s+='<div id="'+f.prefix+"state_"+e+'" class="'+f.prefix+'state" data-jqi-name="'+e+'" style="display:none;">'+m+u+'<div class="'+f.prefix+"message "+f.classes.message+'">'+d+"</div>"+'<div class="'+f.prefix+"buttons "+f.classes.buttons+'"'+(t.isEmptyObject(o.buttons)?'style="display:none;"':"")+">";for(i in o.buttons)n=o.buttons[i],r=o.focus===c||isNaN(o.focus)&&o.defaultButton===c?t.prompt.currentPrefix+"defaultbutton "+f.classes.defaultButton:"","object"==typeof n?(s+='<button class="'+f.classes.button+" "+t.prompt.currentPrefix+"button "+r,n.classes!==void 0&&(s+=" "+(t.isArray(n.classes)?n.classes.join(" "):n.classes)+" "),s+='" name="'+f.prefix+"_"+e+"_button"+n.title.replace(/[^a-z0-9]+/gi,"")+'" id="'+f.prefix+"_"+e+"_button"+n.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+n.value+'">'+n.title+"</button>"):s+='<button class="'+t.prompt.currentPrefix+"button "+f.classes.button+" "+r+'" name="'+f.prefix+"_"+e+"_button"+i.replace(/[^a-z0-9]+/gi,"")+'" id="'+f.prefix+"_"+e+"_button"+i.replace(/[^a-z0-9]+/gi,"")+'" value="'+n+'">'+i+"</button>",c++;return s+="</div></div>",a=t(s),a.on("impromptu:submit",o.submit),void 0!==p?l.find("#"+t.prompt.currentPrefix+"state_"+p).after(a):l.append(a),t.prompt.options.states[e]=o,a},t.prompt.removeState=function(e,o){var p=t.prompt.getState(e),r=function(){p.remove()};return 0===p.length?!1:("none"!==p.css("display")?void 0!==o&&t.prompt.getState(o).length>0?t.prompt.goToState(o,!1,r):p.next().length>0?t.prompt.nextState(r):p.prev().length>0?t.prompt.prevState(r):t.prompt.close():p.slideUp("slow",r),!0)},t.prompt.getState=function(e){return t("#"+t.prompt.currentPrefix+"state_"+e)},t.prompt.getStateContent=function(e){return t.prompt.getState(e)},t.prompt.getCurrentState=function(){return t.prompt.getState(t.prompt.getCurrentStateName())},t.prompt.getCurrentStateName=function(){return t.prompt.currentStateName},t.prompt.goToState=function(e,o,p){var r=(t.prompt.get(),t.prompt.options),i=t.prompt.getState(e),n=r.states[i.data("jqi-name")],s=new t.Event("impromptu:statechanging"),a=t.prompt.options;if(void 0!==n){if("function"==typeof n.html){var m=n.html;i.find("."+a.prefix+"message ").html(m())}"function"==typeof o&&(p=o,o=!1),t.prompt.jqib.trigger(s,[t.prompt.getCurrentStateName(),e]),!s.isDefaultPrevented()&&i.length>0&&(t.prompt.jqi.find("."+t.prompt.currentPrefix+"parentstate").removeClass(t.prompt.currentPrefix+"parentstate"),o?(t.prompt.jqi.find("."+t.prompt.currentPrefix+"substate").not(i).slideUp(r.promptspeed).removeClass("."+t.prompt.currentPrefix+"substate").find("."+t.prompt.currentPrefix+"arrow").hide(),t.prompt.jqi.find("."+t.prompt.currentPrefix+"state:visible").addClass(t.prompt.currentPrefix+"parentstate"),i.addClass(t.prompt.currentPrefix+"substate")):t.prompt.jqi.find("."+t.prompt.currentPrefix+"state").not(i).slideUp(r.promptspeed).find("."+t.prompt.currentPrefix+"arrow").hide(),t.prompt.currentStateName=n.name,i.slideDown(r.promptspeed,function(){var o=t(this);"string"==typeof n.focus?o.find(n.focus).eq(0).focus():o.find("."+t.prompt.currentPrefix+"defaultbutton").focus(),o.find("."+t.prompt.currentPrefix+"arrow").show(r.promptspeed),"function"==typeof p&&t.prompt.jqib.on("impromptu:statechanged",p),t.prompt.jqib.trigger("impromptu:statechanged",[e]),"function"==typeof p&&t.prompt.jqib.off("impromptu:statechanged",p)}),o||t.prompt.position())}return i},t.prompt.nextState=function(e){var o=t("#"+t.prompt.currentPrefix+"state_"+t.prompt.getCurrentStateName()).next();return o.length>0&&t.prompt.goToState(o.attr("id").replace(t.prompt.currentPrefix+"state_",""),e),o},t.prompt.prevState=function(e){var o=t("#"+t.prompt.currentPrefix+"state_"+t.prompt.getCurrentStateName()).prev();return o.length>0&&t.prompt.goToState(o.attr("id").replace(t.prompt.currentPrefix+"state_",""),e),o},t.prompt.close=function(e,o,p,r){t.prompt.timeout&&(clearTimeout(t.prompt.timeout),t.prompt.timeout=!1),t.prompt.jqib&&t.prompt.jqib.fadeOut("fast",function(){t.prompt.jqib.trigger("impromptu:close",[o,p,r]),t.prompt.jqib.remove(),t(window).off("resize",t.prompt.position)}),t.prompt.currentStateName=""},t.fn.prompt=function(e){void 0===e&&(e={}),void 0===e.withDataAndEvents&&(e.withDataAndEvents=!1),t.prompt(t(this).clone(e.withDataAndEvents).html(),e)}})(jQuery); \ No newline at end of file
diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js
index 24364e4..6c1f0f4 100644
--- a/src/jquery-impromptu.js
+++ b/src/jquery-impromptu.js
@@ -565,70 +565,75 @@
jqiopts = $.prompt.options,
$state = $.prompt.getState(state),
stateobj = jqiopts.states[$state.data('jqi-name')],
- promptstatechanginge = new $.Event('impromptu:statechanging');
- var opts = $.prompt.options;
+ promptstatechanginge = new $.Event('impromptu:statechanging'),
+ opts = $.prompt.options;
- if (typeof stateobj.html === 'function') {
- var contentLaterFunc = stateobj.html;
- $state.find('.' + opts.prefix +'message ').html(contentLaterFunc());
- }
+ if(stateobj !== undefined){
- // subState can be ommitted
- if(typeof subState === 'function'){
- callback = subState;
- subState = false;
- }
- $.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
+ if (typeof stateobj.html === 'function') {
+ var contentLaterFunc = stateobj.html;
+ $state.find('.' + opts.prefix +'message ').html(contentLaterFunc());
+ }
- if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'parentstate').removeClass($.prompt.currentPrefix +'parentstate');
+ // subState can be ommitted
+ if(typeof subState === 'function'){
+ callback = subState;
+ subState = false;
+ }
- if(subState){ // hide any open substates
- // get rid of any substates
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'substate').not($state)
- .slideUp(jqiopts.promptspeed)
- .removeClass('.'+ $.prompt.currentPrefix +'substate')
- .find('.'+ $.prompt.currentPrefix +'arrow').hide();
+ $.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
- // add parent state class so it can be visible, but blocked
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state:visible').addClass($.prompt.currentPrefix +'parentstate');
+ if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'parentstate').removeClass($.prompt.currentPrefix +'parentstate');
- // add substate class so we know it will be smaller
- $state.addClass($.prompt.currentPrefix +'substate');
- }
- else{ // hide any open states
- $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state').not($state)
- .slideUp(jqiopts.promptspeed)
- .find('.'+ $.prompt.currentPrefix +'arrow').hide();
- }
- $.prompt.currentStateName = stateobj.name;
+ if(subState){ // hide any open substates
+ // get rid of any substates
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'substate').not($state)
+ .slideUp(jqiopts.promptspeed)
+ .removeClass('.'+ $.prompt.currentPrefix +'substate')
+ .find('.'+ $.prompt.currentPrefix +'arrow').hide();
- $state.slideDown(jqiopts.promptspeed,function(){
- var $t = $(this);
+ // add parent state class so it can be visible, but blocked
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state:visible').addClass($.prompt.currentPrefix +'parentstate');
- // if focus is a selector, find it, else its button index
- if(typeof(stateobj.focus) === 'string'){
- $t.find(stateobj.focus).eq(0).focus();
+ // add substate class so we know it will be smaller
+ $state.addClass($.prompt.currentPrefix +'substate');
}
- else{
- $t.find('.'+ $.prompt.currentPrefix +'defaultbutton').focus();
+ else{ // hide any open states
+ $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state').not($state)
+ .slideUp(jqiopts.promptspeed)
+ .find('.'+ $.prompt.currentPrefix +'arrow').hide();
}
+ $.prompt.currentStateName = stateobj.name;
- $t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
+ $state.slideDown(jqiopts.promptspeed,function(){
+ var $t = $(this);
- if (typeof callback === 'function'){
- $.prompt.jqib.on('impromptu:statechanged', callback);
- }
- $.prompt.jqib.trigger('impromptu:statechanged', [state]);
- if (typeof callback === 'function'){
- $.prompt.jqib.off('impromptu:statechanged', callback);
+ // if focus is a selector, find it, else its button index
+ if(typeof(stateobj.focus) === 'string'){
+ $t.find(stateobj.focus).eq(0).focus();
+ }
+ else{
+ $t.find('.'+ $.prompt.currentPrefix +'defaultbutton').focus();
+ }
+
+ $t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
+
+ if (typeof callback === 'function'){
+ $.prompt.jqib.on('impromptu:statechanged', callback);
+ }
+ $.prompt.jqib.trigger('impromptu:statechanged', [state]);
+ if (typeof callback === 'function'){
+ $.prompt.jqib.off('impromptu:statechanged', callback);
+ }
+ });
+ if(!subState){
+ $.prompt.position();
}
- });
- if(!subState){
- $.prompt.position();
- }
- }
+ } // end isDefaultPrevented()
+ }// end stateobj !== undefined
+
return $state;
};
diff --git a/test/jquery-impromptu_spec.js b/test/jquery-impromptu_spec.js
index c3a722a..4aa9669 100644
--- a/test/jquery-impromptu_spec.js
+++ b/test/jquery-impromptu_spec.js
@@ -57,7 +57,7 @@ describe('jquery-impromptu', function() {
var okBtn = $('#jqi_state0_buttonOk'),
cancelBtn = $('#jqi_state0_buttonCancel');
- expect($('.jqibutton').length).toBe(2);
+ expect($('.jqibutton')).toHaveLength(2);
expect(okBtn).toExist();
expect(cancelBtn).toExist();