diff options
-rw-r--r-- | dist/index.html | 18 | ||||
-rw-r--r-- | dist/jquery-impromptu.js | 79 | ||||
-rw-r--r-- | dist/jquery-impromptu.min.js | 2 | ||||
-rw-r--r-- | src/index.html | 37 | ||||
-rw-r--r-- | src/jquery-impromptu.js | 69 | ||||
-rw-r--r-- | test/jquery-impromptu_spec.js | 127 |
6 files changed, 238 insertions, 94 deletions
diff --git a/dist/index.html b/dist/index.html index 389ee22..8d14021 100644 --- a/dist/index.html +++ b/dist/index.html @@ -128,7 +128,7 @@ <!-- ---------------------------------------------- --> <div id="Options" class="section"> <h2>Options</h2> - <pre><code>$.prompt.open( msg , options )</code></pre> + <pre><code>$.prompt( msg , options )</code></pre> <h3>msg</h3> <p>The message can either be an html string, or an object of "states". Each state has the following properties:</p> <dl> @@ -338,7 +338,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>A prompt in the simplest of fashion.</p> -<pre class="code">$.prompt.open("Hello World!");</pre> +<pre class="code">$.prompt("Hello World!");</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -346,7 +346,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>Lets add some buttons and a title.</p> -<pre class="code">$.prompt.open("Proceeding may be good for your site..", { +<pre class="code">$.prompt("Proceeding may be good for your site..", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false } });</pre> @@ -357,13 +357,13 @@ $.prompt.getState('state2') <div class="example-container"> <p>Use the submit function to get the answer.</p> -<pre class="code">$.prompt.open("Open your javascript console to see the answer.", { +<pre class="code">$.prompt("Open your javascript console to see the answer.", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false }, submit: function(e,v,m,f){ // use e.preventDefault() to prevent closing when needed or return false. // e.preventDefault(); - + console.log("Value clicked was: "+ v); } });</pre> @@ -404,7 +404,7 @@ $.prompt.getState('state2') } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -448,7 +448,7 @@ $.prompt.open(statesdemo);</pre> } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -517,7 +517,7 @@ tourStates = [ submit: tourSubmitFunc } ]; -$.prompt.open(tourStates);</pre> +$.prompt(tourStates);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -575,7 +575,7 @@ $.prompt.open(tourStates);</pre> }, }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> diff --git a/dist/jquery-impromptu.js b/dist/jquery-impromptu.js index 989d6e4..fa173bf 100644 --- a/dist/jquery-impromptu.js +++ b/dist/jquery-impromptu.js @@ -148,7 +148,7 @@ 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>';
} else {
- msgbox +='<div class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></div>';
+ msgbox += '<div class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></div>';
}
msgbox += '<div class="'+ opts.prefix +' '+ opts.classes.prompt +'">'+
'<form action="javascript:false;" onsubmit="return false;" class="'+ opts.prefix +'form '+ opts.classes.form +'">'+
@@ -297,8 +297,13 @@ t.position();
t.style();
+ // store copy of the window resize function for interal use only
+ t._windowResize = function(e){
+ t.position(e);
+ };
+ $window.resize({ animate: false }, t._windowResize);
+
t.jqif.click(fadeClicked);
- $window.resize({animate:false}, function(){ t.position(); });
t.jqi.find('.'+ opts.prefix +'close').click(function(){ t.close(); });
t.jqib.on("keydown",keyDownEventHandler)
.on('impromptu:loaded', opts.loaded)
@@ -347,7 +352,7 @@ t.jqib.remove();
- $(window).off('resize', function(){ t.position(); });
+ $(window).off('resize', t._windowResize);
if(typeof callCallback === 'function'){
callCallback();
@@ -478,6 +483,14 @@ },
/**
+ * get - Get the box containing fade and prompt
+ * @return jQuery - the prompt
+ */
+ getBox: function() {
+ return this.jqib;
+ },
+
+ /**
* get - Get the prompt
* @return jQuery - the prompt
*/
@@ -736,6 +749,60 @@ };
// ########################################################################
+ // $.prompt will manage a queue of Impromptu instances
+ // ########################################################################
+
+ /**
+ * $.prompt create a new Impromptu instance and push it on the stack of instances
+ * @param message String/Object - String of html or Object of states
+ * @param options Object - Options to set the prompt
+ * @return jQuery - the jQuery object of the prompt within the modal
+ */
+ $.prompt = function(message, options){
+ var api = new Imp();
+ $.prompt.lifo.push(api);
+ api.open.apply(api, arguments);
+ return api.jqi;
+ };
+
+ /**
+ * @var Array - An array of Impromptu intances in a LIFO queue (last in first out)
+ */
+ $.prompt.lifo = [];
+
+ /**
+ * $.prompt.getLast - get the last element from the queue (doesn't pop, just returns)
+ * @return Imp - the instance of this Impromptu object or false if queue is empty
+ */
+ $.prompt.getLast = function(){
+ var l = $.prompt.lifo.length;
+ return (l > 0)? $.prompt.lifo[l-1] : false;
+ };
+
+ /**
+ * Copy over static methods, not worth doing a loop over for just 2
+ */
+ $.each(Imp, function(k,v){
+ $.prompt[k] = v;
+ });
+
+ /**
+ * Create a proxy for accessing all instance methods. The close method pops from queue.
+ */
+ $.each(Imp.prototype, function(k,v){
+ $.prompt[k] = function(){
+ var api = $.prompt.getLast();
+
+ if(api && typeof api[k] === "function"){
+ if(k === 'close'){
+ $.prompt.lifo.pop();
+ }
+ return api[k].apply(api, arguments);
+ }
+ };
+ });
+
+ // ########################################################################
// jQuery Plugin and public access
// ########################################################################
@@ -760,10 +827,4 @@ */
window.Impromptu = Imp;
- /**
- * Set $.prompt as a single instance
- * Can be used from here forth as $.prompt.open(state, opts)
- */
- $.prompt = new Imp();
-
}));
diff --git a/dist/jquery-impromptu.min.js b/dist/jquery-impromptu.min.js index c008440..c67e440 100644 --- a/dist/jquery-impromptu.min.js +++ b/dist/jquery-impromptu.min.js @@ -1,4 +1,4 @@ /*! jQuery-Impromptu - v5.3.1 - 2014-11-16 * http://trentrichardson.com/Impromptu * Copyright (c) 2014 Trent Richardson; Licensed MIT */ -(function(t,e){"function"==typeof define&&define.amd?define(["jquery"],e):e(t.jQuery)})(this,function(t){"use strict";var e=function(t,e){return t&&this.open(t,e),this};e.defaults={prefix:"jqi",classes:{box:"",fade:"",prompt:"",form:"",close:"",title:"",message:"",buttons:"",button:"",defaultButton:""},title:"",closeText:"×",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}}},e.setDefaults=function(i){e.defaults=t.extend({},e.defaults,i)},e.setStateDefaults=function(i){e.defaults.state=t.extend({},e.defaults.state,i)},e.prototype={open:function(i,n){var o=this;o.options=t.extend({},e.defaults,n),o.timeout&&clearTimeout(o.timeout),o.timeout=!1;var s=o.options,a=t(document.body),r=t(window),f='<div class="'+s.prefix+"box "+s.classes.box+'">';f+=s.useiframe&&t("object, applet").length>0?'<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+s.prefix+"fade "+s.classes.fade+'"></iframe>':'<div class="'+s.prefix+"fade "+s.classes.fade+'"></div>',f+='<div class="'+s.prefix+" "+s.classes.prompt+'">'+'<form action="javascript:false;" onsubmit="return false;" class="'+s.prefix+"form "+s.classes.form+'">'+'<div class="'+s.prefix+"close "+s.classes.close+'">'+s.closeText+"</div>"+'<div class="'+s.prefix+'states"></div>'+"</form>"+"</div>"+"</div>",o.jqib=t(f).appendTo(a),o.jqi=o.jqib.children("."+s.prefix),o.jqif=o.jqib.children("."+s.prefix+"fade"),i.constructor===String&&(i={state0:{title:s.title,html:i,buttons:s.buttons,position:s.position,focus:s.focus,defaultButton:s.defaultButton,submit:s.submit}}),o.options.states={};var u,l;for(u in i)l=t.extend({},e.defaults.state,{name:u},i[u]),o.addState(l.name,l),""===o.currentStateName&&(o.currentStateName=l.name);o.jqi.on("click","."+s.prefix+"buttons button",function(){var e=t(this),i=e.parents("."+s.prefix+"state"),n=o.options.states[i.data("jqi-name")],a=i.children("."+s.prefix+"message"),r=n.buttons[e.text()]||n.buttons[e.html()],f={};if(void 0===r)for(var u in n.buttons)(n.buttons[u].title===e.text()||n.buttons[u].title===e.html())&&(r=n.buttons[u].value);t.each(o.jqi.children("form").serializeArray(),function(t,e){void 0===f[e.name]?f[e.name]=e.value:typeof f[e.name]===Array||"object"==typeof f[e.name]?f[e.name].push(e.value):f[e.name]=[f[e.name],e.value]});var l=new t.Event("impromptu:submit");l.stateName=n.name,l.state=i,i.trigger(l,[r,a,f]),l.isDefaultPrevented()||o.close(!0,r,a,f)});var p=function(){if(s.persistent){var e=(""+s.top).indexOf("%")>=0?r.height()*(parseInt(s.top,10)/100):parseInt(s.top,10),i=parseInt(o.jqi.css("top").replace("px",""),10)-e;t("html,body").animate({scrollTop:i},"fast",function(){var t=0;o.jqib.addClass(s.prefix+"warning");var e=setInterval(function(){o.jqib.toggleClass(s.prefix+"warning"),t++>1&&(clearInterval(e),o.jqib.removeClass(s.prefix+"warning"))},100)})}else o.close(!0)},d=function(e){var i=window.event?event.keyCode:e.keyCode;if(27===i&&p(),13===i){var n=o.getCurrentState().find("."+s.prefix+"defaultbutton"),a=t(e.target);a.is("textarea,."+s.prefix+"button")===!1&&n.length>0&&(e.preventDefault(),n.click())}if(9===i){var r=t("input,select,textarea,button",o.getCurrentState()),f=!e.shiftKey&&e.target===r[r.length-1],u=e.shiftKey&&e.target===r[0];if(f||u)return setTimeout(function(){if(r){var t=r[u===!0?r.length-1:0];t&&t.focus()}},10),!1}};return o.position(),o.style(),o.jqif.click(p),r.resize({animate:!1},function(){o.position()}),o.jqi.find("."+s.prefix+"close").click(function(){o.close()}),o.jqib.on("keydown",d).on("impromptu:loaded",s.loaded).on("impromptu:close",s.close).on("impromptu:statechanging",s.statechanging).on("impromptu:statechanged",s.statechanged),o.jqif[s.show](s.overlayspeed),o.jqi[s.show](s.promptspeed,function(){var t=o.jqi.find("."+s.prefix+"states ."+s.prefix+"state").eq(0);o.goToState(t.data("jqi-name")),o.jqib.trigger("impromptu:loaded")}),s.timeout>0&&(o.timeout=setTimeout(function(){o.close(!0)},s.timeout)),o},close:function(e,i,n,o){var s=this;return s.timeout&&(clearTimeout(s.timeout),s.timeout=!1),s.jqib&&s.jqib.fadeOut("fast",function(){s.jqib.trigger("impromptu:close",[i,n,o]),s.jqib.remove(),t(window).off("resize",function(){s.position()}),"function"==typeof e&&e()}),s.currentStateName="",s},addState:function(i,n,o){var s,a,r,f,u,l=this,p="",d=null,c="",m="",h=l.options,v=t("."+h.prefix+"states"),g=[],b=0;if(n=t.extend({},e.defaults.state,{name:i},n),null!==n.position.arrow&&(c='<div class="'+h.prefix+"arrow "+h.prefix+"arrow"+n.position.arrow+'"></div>'),n.title&&""!==n.title&&(m='<div class="lead '+h.prefix+"title "+h.classes.title+'">'+n.title+"</div>"),s=n.html,"function"==typeof n.html&&(s="Error: html function must return text"),p+='<div class="'+h.prefix+'state" data-jqi-name="'+i+'" style="display:none;">'+c+m+'<div class="'+h.prefix+"message "+h.classes.message+'">'+s+"</div>"+'<div class="'+h.prefix+"buttons "+h.classes.buttons+'"'+(t.isEmptyObject(n.buttons)?'style="display:none;"':"")+">",t.isArray(n.buttons))g=n.buttons;else if(t.isPlainObject(n.buttons))for(r in n.buttons)n.buttons.hasOwnProperty(r)&&g.push({title:r,value:n.buttons[r]});for(b=0,u=g.length;u>b;b++)f=g[b],a=n.focus===b||isNaN(n.focus)&&n.defaultButton===b?h.prefix+"defaultbutton "+h.classes.defaultButton:"",p+='<button class="'+h.classes.button+" "+h.prefix+"button "+a,f.classes!==void 0&&(p+=" "+(t.isArray(f.classes)?f.classes.join(" "):f.classes)+" "),p+='" name="'+h.prefix+"_"+i+"_button"+f.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+f.value+'">'+f.title+"</button>";return p+="</div></div>",d=t(p),d.on("impromptu:submit",n.submit),void 0!==o?v.find('[data-jqi-name="'+o+'"]').after(d):v.append(d),l.options.states[i]=n,d},removeState:function(t,e){var i=this,n=i.getState(t),o=function(){n.remove()};return 0===n.length?!1:("none"!==n.css("display")?void 0!==e&&i.getState(e).length>0?i.goToState(e,!1,o):n.next().length>0?i.nextState(o):n.prev().length>0?i.prevState(o):i.close():n.slideUp("slow",o),!0)},getPrompt:function(){return this.jqi},getState:function(t){return this.jqi.find('[data-jqi-name="'+t+'"]')},getCurrentState:function(){return this.getState(this.getCurrentStateName())},getCurrentStateName:function(){return this.currentStateName},position:function(e){var i=this,n=t.fx.off,o=i.getCurrentState(),s=i.options.states[o.data("jqi-name")],a=s?s.position:void 0,r=t(window),f=document.body.scrollHeight,u=t(window).height(),l=(t(document).height(),f>u?f:u),p=parseInt(r.scrollTop(),10)+((""+i.options.top).indexOf("%")>=0?u*(parseInt(i.options.top,10)/100):parseInt(i.options.top,10));if(void 0!==e&&e.data.animate===!1&&(t.fx.off=!0),i.jqib.css({position:"absolute",height:l,width:"100%",top:0,left:0,right:0,bottom:0}),i.jqif.css({position:"fixed",height:l,width:"100%",top:0,left:0,right:0,bottom:0}),a&&a.container){var d=t(a.container).offset();t.isPlainObject(d)&&void 0!==d.top&&(i.jqi.css({position:"absolute"}),i.jqi.animate({top:d.top+a.y,left:d.left+a.x,marginLeft:0,width:void 0!==a.width?a.width:null}),p=d.top+a.y-((""+i.options.top).indexOf("%")>=0?u*(parseInt(i.options.top,10)/100):parseInt(i.options.top,10)),t("html,body").animate({scrollTop:p},"slow","swing",function(){}))}else a&&a.width?(i.jqi.css({position:"absolute",left:"50%"}),i.jqi.animate({top:a.y||p,left:a.x||"50%",marginLeft:-1*(a.width/2),width:a.width})):i.jqi.css({position:"absolute",top:p,left:"50%",marginLeft:-1*(i.jqi.outerWidth(!1)/2)});void 0!==e&&e.data.animate===!1&&(t.fx.off=n)},style:function(){var t=this;t.jqif.css({zIndex:t.options.zIndex,display:"none",opacity:t.options.opacity}),t.jqi.css({zIndex:t.options.zIndex+1,display:"none"}),t.jqib.css({zIndex:t.options.zIndex})},goToState:function(e,i,n){var o=this,s=(o.jqi,o.options),a=o.getState(e),r=s.states[a.data("jqi-name")],f=new t.Event("impromptu:statechanging"),u=o.options;if(void 0!==r){if("function"==typeof r.html){var l=r.html;a.find("."+u.prefix+"message ").html(l())}"function"==typeof i&&(n=i,i=!1),o.jqib.trigger(f,[o.getCurrentStateName(),e]),!f.isDefaultPrevented()&&a.length>0&&(o.jqi.find("."+u.prefix+"parentstate").removeClass(u.prefix+"parentstate"),i?(o.jqi.find("."+u.prefix+"substate").not(a).slideUp(s.promptspeed).removeClass("."+u.prefix+"substate").find("."+u.prefix+"arrow").hide(),o.jqi.find("."+u.prefix+"state:visible").addClass(u.prefix+"parentstate"),a.addClass(u.prefix+"substate")):o.jqi.find("."+u.prefix+"state").not(a).slideUp(s.promptspeed).find("."+u.prefix+"arrow").hide(),o.currentStateName=r.name,a.slideDown(s.promptspeed,function(){var i=t(this);"string"==typeof r.focus?i.find(r.focus).eq(0).focus():i.find("."+u.prefix+"defaultbutton").focus(),i.find("."+u.prefix+"arrow").show(s.promptspeed),"function"==typeof n&&o.jqib.on("impromptu:statechanged",n),o.jqib.trigger("impromptu:statechanged",[e]),"function"==typeof n&&o.jqib.off("impromptu:statechanged",n)}),i||o.position())}return a},nextState:function(t){var e=this,i=e.getCurrentState().next();return i.length>0&&e.goToState(i.data("jqi-name"),t),i},prevState:function(t){var e=this,i=e.getCurrentState().prev();return i.length>0&&e.goToState(i.data("jqi-name"),t),i}},t.fn.prompt=function(i){void 0===i&&(i={}),void 0===i.withDataAndEvents&&(i.withDataAndEvents=!1),new e(t(this).clone(i.withDataAndEvents).html(),i)},window.Impromptu=e,t.prompt=new e});
\ No newline at end of file +(function(t,e){"function"==typeof define&&define.amd?define(["jquery"],e):e(t.jQuery)})(this,function(t){"use strict";var e=function(t,e){return t&&this.open(t,e),this};e.defaults={prefix:"jqi",classes:{box:"",fade:"",prompt:"",form:"",close:"",title:"",message:"",buttons:"",button:"",defaultButton:""},title:"",closeText:"×",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}}},e.setDefaults=function(i){e.defaults=t.extend({},e.defaults,i)},e.setStateDefaults=function(i){e.defaults.state=t.extend({},e.defaults.state,i)},e.prototype={open:function(i,n){var o=this;o.options=t.extend({},e.defaults,n),o.timeout&&clearTimeout(o.timeout),o.timeout=!1;var s=o.options,a=t(document.body),r=t(window),p='<div class="'+s.prefix+"box "+s.classes.box+'">';p+=s.useiframe&&t("object, applet").length>0?'<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+s.prefix+"fade "+s.classes.fade+'"></iframe>':'<div class="'+s.prefix+"fade "+s.classes.fade+'"></div>',p+='<div class="'+s.prefix+" "+s.classes.prompt+'">'+'<form action="javascript:false;" onsubmit="return false;" class="'+s.prefix+"form "+s.classes.form+'">'+'<div class="'+s.prefix+"close "+s.classes.close+'">'+s.closeText+"</div>"+'<div class="'+s.prefix+'states"></div>'+"</form>"+"</div>"+"</div>",o.jqib=t(p).appendTo(a),o.jqi=o.jqib.children("."+s.prefix),o.jqif=o.jqib.children("."+s.prefix+"fade"),i.constructor===String&&(i={state0:{title:s.title,html:i,buttons:s.buttons,position:s.position,focus:s.focus,defaultButton:s.defaultButton,submit:s.submit}}),o.options.states={};var u,f;for(u in i)f=t.extend({},e.defaults.state,{name:u},i[u]),o.addState(f.name,f),""===o.currentStateName&&(o.currentStateName=f.name);o.jqi.on("click","."+s.prefix+"buttons button",function(){var e=t(this),i=e.parents("."+s.prefix+"state"),n=o.options.states[i.data("jqi-name")],a=i.children("."+s.prefix+"message"),r=n.buttons[e.text()]||n.buttons[e.html()],p={};if(void 0===r)for(var u in n.buttons)(n.buttons[u].title===e.text()||n.buttons[u].title===e.html())&&(r=n.buttons[u].value);t.each(o.jqi.children("form").serializeArray(),function(t,e){void 0===p[e.name]?p[e.name]=e.value:typeof p[e.name]===Array||"object"==typeof p[e.name]?p[e.name].push(e.value):p[e.name]=[p[e.name],e.value]});var f=new t.Event("impromptu:submit");f.stateName=n.name,f.state=i,i.trigger(f,[r,a,p]),f.isDefaultPrevented()||o.close(!0,r,a,p)});var l=function(){if(s.persistent){var e=(""+s.top).indexOf("%")>=0?r.height()*(parseInt(s.top,10)/100):parseInt(s.top,10),i=parseInt(o.jqi.css("top").replace("px",""),10)-e;t("html,body").animate({scrollTop:i},"fast",function(){var t=0;o.jqib.addClass(s.prefix+"warning");var e=setInterval(function(){o.jqib.toggleClass(s.prefix+"warning"),t++>1&&(clearInterval(e),o.jqib.removeClass(s.prefix+"warning"))},100)})}else o.close(!0)},d=function(e){var i=window.event?event.keyCode:e.keyCode;if(27===i&&l(),13===i){var n=o.getCurrentState().find("."+s.prefix+"defaultbutton"),a=t(e.target);a.is("textarea,."+s.prefix+"button")===!1&&n.length>0&&(e.preventDefault(),n.click())}if(9===i){var r=t("input,select,textarea,button",o.getCurrentState()),p=!e.shiftKey&&e.target===r[r.length-1],u=e.shiftKey&&e.target===r[0];if(p||u)return setTimeout(function(){if(r){var t=r[u===!0?r.length-1:0];t&&t.focus()}},10),!1}};return o.position(),o.style(),o._windowResize=function(t){o.position(t)},r.resize({animate:!1},o._windowResize),o.jqif.click(l),o.jqi.find("."+s.prefix+"close").click(function(){o.close()}),o.jqib.on("keydown",d).on("impromptu:loaded",s.loaded).on("impromptu:close",s.close).on("impromptu:statechanging",s.statechanging).on("impromptu:statechanged",s.statechanged),o.jqif[s.show](s.overlayspeed),o.jqi[s.show](s.promptspeed,function(){var t=o.jqi.find("."+s.prefix+"states ."+s.prefix+"state").eq(0);o.goToState(t.data("jqi-name")),o.jqib.trigger("impromptu:loaded")}),s.timeout>0&&(o.timeout=setTimeout(function(){o.close(!0)},s.timeout)),o},close:function(e,i,n,o){var s=this;return s.timeout&&(clearTimeout(s.timeout),s.timeout=!1),s.jqib&&s.jqib.fadeOut("fast",function(){s.jqib.trigger("impromptu:close",[i,n,o]),s.jqib.remove(),t(window).off("resize",s._windowResize),"function"==typeof e&&e()}),s.currentStateName="",s},addState:function(i,n,o){var s,a,r,p,u,f=this,l="",d=null,c="",m="",h=f.options,v=t("."+h.prefix+"states"),g=[],b=0;if(n=t.extend({},e.defaults.state,{name:i},n),null!==n.position.arrow&&(c='<div class="'+h.prefix+"arrow "+h.prefix+"arrow"+n.position.arrow+'"></div>'),n.title&&""!==n.title&&(m='<div class="lead '+h.prefix+"title "+h.classes.title+'">'+n.title+"</div>"),s=n.html,"function"==typeof n.html&&(s="Error: html function must return text"),l+='<div class="'+h.prefix+'state" data-jqi-name="'+i+'" style="display:none;">'+c+m+'<div class="'+h.prefix+"message "+h.classes.message+'">'+s+"</div>"+'<div class="'+h.prefix+"buttons "+h.classes.buttons+'"'+(t.isEmptyObject(n.buttons)?'style="display:none;"':"")+">",t.isArray(n.buttons))g=n.buttons;else if(t.isPlainObject(n.buttons))for(r in n.buttons)n.buttons.hasOwnProperty(r)&&g.push({title:r,value:n.buttons[r]});for(b=0,u=g.length;u>b;b++)p=g[b],a=n.focus===b||isNaN(n.focus)&&n.defaultButton===b?h.prefix+"defaultbutton "+h.classes.defaultButton:"",l+='<button class="'+h.classes.button+" "+h.prefix+"button "+a,p.classes!==void 0&&(l+=" "+(t.isArray(p.classes)?p.classes.join(" "):p.classes)+" "),l+='" name="'+h.prefix+"_"+i+"_button"+p.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+p.value+'">'+p.title+"</button>";return l+="</div></div>",d=t(l),d.on("impromptu:submit",n.submit),void 0!==o?v.find('[data-jqi-name="'+o+'"]').after(d):v.append(d),f.options.states[i]=n,d},removeState:function(t,e){var i=this,n=i.getState(t),o=function(){n.remove()};return 0===n.length?!1:("none"!==n.css("display")?void 0!==e&&i.getState(e).length>0?i.goToState(e,!1,o):n.next().length>0?i.nextState(o):n.prev().length>0?i.prevState(o):i.close():n.slideUp("slow",o),!0)},getBox:function(){return this.jqib},getPrompt:function(){return this.jqi},getState:function(t){return this.jqi.find('[data-jqi-name="'+t+'"]')},getCurrentState:function(){return this.getState(this.getCurrentStateName())},getCurrentStateName:function(){return this.currentStateName},position:function(e){var i=this,n=t.fx.off,o=i.getCurrentState(),s=i.options.states[o.data("jqi-name")],a=s?s.position:void 0,r=t(window),p=document.body.scrollHeight,u=t(window).height(),f=(t(document).height(),p>u?p:u),l=parseInt(r.scrollTop(),10)+((""+i.options.top).indexOf("%")>=0?u*(parseInt(i.options.top,10)/100):parseInt(i.options.top,10));if(void 0!==e&&e.data.animate===!1&&(t.fx.off=!0),i.jqib.css({position:"absolute",height:f,width:"100%",top:0,left:0,right:0,bottom:0}),i.jqif.css({position:"fixed",height:f,width:"100%",top:0,left:0,right:0,bottom:0}),a&&a.container){var d=t(a.container).offset();t.isPlainObject(d)&&void 0!==d.top&&(i.jqi.css({position:"absolute"}),i.jqi.animate({top:d.top+a.y,left:d.left+a.x,marginLeft:0,width:void 0!==a.width?a.width:null}),l=d.top+a.y-((""+i.options.top).indexOf("%")>=0?u*(parseInt(i.options.top,10)/100):parseInt(i.options.top,10)),t("html,body").animate({scrollTop:l},"slow","swing",function(){}))}else a&&a.width?(i.jqi.css({position:"absolute",left:"50%"}),i.jqi.animate({top:a.y||l,left:a.x||"50%",marginLeft:-1*(a.width/2),width:a.width})):i.jqi.css({position:"absolute",top:l,left:"50%",marginLeft:-1*(i.jqi.outerWidth(!1)/2)});void 0!==e&&e.data.animate===!1&&(t.fx.off=n)},style:function(){var t=this;t.jqif.css({zIndex:t.options.zIndex,display:"none",opacity:t.options.opacity}),t.jqi.css({zIndex:t.options.zIndex+1,display:"none"}),t.jqib.css({zIndex:t.options.zIndex})},goToState:function(e,i,n){var o=this,s=(o.jqi,o.options),a=o.getState(e),r=s.states[a.data("jqi-name")],p=new t.Event("impromptu:statechanging"),u=o.options;if(void 0!==r){if("function"==typeof r.html){var f=r.html;a.find("."+u.prefix+"message ").html(f())}"function"==typeof i&&(n=i,i=!1),o.jqib.trigger(p,[o.getCurrentStateName(),e]),!p.isDefaultPrevented()&&a.length>0&&(o.jqi.find("."+u.prefix+"parentstate").removeClass(u.prefix+"parentstate"),i?(o.jqi.find("."+u.prefix+"substate").not(a).slideUp(s.promptspeed).removeClass("."+u.prefix+"substate").find("."+u.prefix+"arrow").hide(),o.jqi.find("."+u.prefix+"state:visible").addClass(u.prefix+"parentstate"),a.addClass(u.prefix+"substate")):o.jqi.find("."+u.prefix+"state").not(a).slideUp(s.promptspeed).find("."+u.prefix+"arrow").hide(),o.currentStateName=r.name,a.slideDown(s.promptspeed,function(){var i=t(this);"string"==typeof r.focus?i.find(r.focus).eq(0).focus():i.find("."+u.prefix+"defaultbutton").focus(),i.find("."+u.prefix+"arrow").show(s.promptspeed),"function"==typeof n&&o.jqib.on("impromptu:statechanged",n),o.jqib.trigger("impromptu:statechanged",[e]),"function"==typeof n&&o.jqib.off("impromptu:statechanged",n)}),i||o.position())}return a},nextState:function(t){var e=this,i=e.getCurrentState().next();return i.length>0&&e.goToState(i.data("jqi-name"),t),i},prevState:function(t){var e=this,i=e.getCurrentState().prev();return i.length>0&&e.goToState(i.data("jqi-name"),t),i}},t.prompt=function(){var i=new e;return t.prompt.lifo.push(i),i.open.apply(i,arguments),i.jqi},t.prompt.lifo=[],t.prompt.getLast=function(){var e=t.prompt.lifo.length;return e>0?t.prompt.lifo[e-1]:!1},t.each(e,function(e,i){t.prompt[e]=i}),t.each(e.prototype,function(e){t.prompt[e]=function(){var i=t.prompt.getLast();return i&&"function"==typeof i[e]?("close"===e&&t.prompt.lifo.pop(),i[e].apply(i,arguments)):void 0}}),t.fn.prompt=function(i){void 0===i&&(i={}),void 0===i.withDataAndEvents&&(i.withDataAndEvents=!1),new e(t(this).clone(i.withDataAndEvents).html(),i)},window.Impromptu=e});
\ No newline at end of file diff --git a/src/index.html b/src/index.html index 6444650..445924b 100644 --- a/src/index.html +++ b/src/index.html @@ -128,7 +128,20 @@ <!-- ---------------------------------------------- --> <div id="Options" class="section"> <h2>Options</h2> - <pre><code>$.prompt.open( msg , options )</code></pre> + + <h3>Usage</h3> + <pre><code>var jqPromptEl = $.prompt( msg , options ); + +// OR + +var api = new Impromptu( msg , options );</code></pre> + + <p>Impromptu can be called through $.prompt() or by creating a new instance of the Impromptu object. Whats the difference?</p> + <p>An Impromptu instance is a single prompt. The constructor returns it's api so you can manipulate it.</p> + <p>$.prompt is an object that manages a stack of Impromptu instances. What does this mean? You can continuously call $.prompt without closing the previous prompt, and $.prompt will always manage the newest prompt on the stack by acting as a proxy to the latest Impromptu instance. $.prompt() will return a jQuery object of the latests prompt.</p> + + <p>Since $.prompt acts as a simple proxy to Impromptu, they accept the same options.</p> + <h3>msg</h3> <p>The message can either be an html string, or an object of "states". Each state has the following properties:</p> <dl> @@ -247,19 +260,19 @@ <div id="Methods" class="section"> <h2>Methods</h2> <dl class="methoddl"> - <dt>Impromptu.setDefaults(options)</dt> + <dt>$.prompt.setDefaults(options)</dt> <dd> Sets the defaults for prompts.<br /> -<pre><code>Impromptu.setDefaults({ +<pre><code>$.prompt.setDefaults({ prefix: 'myPrompt', show: 'slideDown' });</pre></code> </dd> - <dt>Impromptu.setStateDefaults(options)</dt> + <dt>$.prompt.setStateDefaults(options)</dt> <dd> Sets the defaults for states.<br /> -<pre><code>Impromptu.setStateDefaults({ +<pre><code>$.prompt.setStateDefaults({ buttons: { Ok:true, Cancel:false }, focus: 1 });</pre></code> @@ -338,7 +351,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>A prompt in the simplest of fashion.</p> -<pre class="code">$.prompt.open("Hello World!");</pre> +<pre class="code">$.prompt("Hello World!");</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -346,7 +359,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>Lets add some buttons and a title.</p> -<pre class="code">$.prompt.open("Proceeding may be good for your site..", { +<pre class="code">$.prompt("Proceeding may be good for your site..", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false } });</pre> @@ -357,7 +370,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>Use the submit function to get the answer.</p> -<pre class="code">$.prompt.open("Open your javascript console to see the answer.", { +<pre class="code">$.prompt("Open your javascript console to see the answer.", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false }, submit: function(e,v,m,f){ @@ -404,7 +417,7 @@ $.prompt.getState('state2') } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -448,7 +461,7 @@ $.prompt.open(statesdemo);</pre> } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -517,7 +530,7 @@ tourStates = [ submit: tourSubmitFunc } ]; -$.prompt.open(tourStates);</pre> +$.prompt(tourStates);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -575,7 +588,7 @@ $.prompt.open(tourStates);</pre> }, }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js index 803b920..34d07b6 100644 --- a/src/jquery-impromptu.js +++ b/src/jquery-impromptu.js @@ -480,6 +480,14 @@ },
/**
+ * get - Get the box containing fade and prompt
+ * @return jQuery - the prompt
+ */
+ getBox: function() {
+ return this.jqib;
+ },
+
+ /**
* get - Get the prompt
* @return jQuery - the prompt
*/
@@ -738,6 +746,61 @@ };
// ########################################################################
+ // $.prompt will manage a queue of Impromptu instances
+ // ########################################################################
+
+ /**
+ * $.prompt create a new Impromptu instance and push it on the stack of instances
+ * @param message String/Object - String of html or Object of states
+ * @param options Object - Options to set the prompt
+ * @return jQuery - the jQuery object of the prompt within the modal
+ */
+ $.prompt = function(message, options){
+ var api = new Imp();
+ $.prompt.lifo.push(api);
+
+ api.open.apply(api, arguments);
+ return api.jqi;
+ };
+
+ /**
+ * @var Array - An array of Impromptu intances in a LIFO queue (last in first out)
+ */
+ $.prompt.lifo = [];
+
+ /**
+ * $.prompt.getLast - get the last element from the queue (doesn't pop, just returns)
+ * @return Imp - the instance of this Impromptu object or false if queue is empty
+ */
+ $.prompt.getLast = function(){
+ var l = $.prompt.lifo.length;
+ return (l > 0)? $.prompt.lifo[l-1] : false;
+ };
+
+ /**
+ * Copy over static methods
+ */
+ $.each(Imp, function(k,v){
+ $.prompt[k] = v;
+ });
+
+ /**
+ * Create a proxy for accessing all instance methods. The close method pops from queue.
+ */
+ $.each(Imp.prototype, function(k,v){
+ $.prompt[k] = function(){
+ var api = $.prompt.getLast();
+
+ if(api && typeof api[k] === "function"){
+ if(k === 'close'){
+ $.prompt.lifo.pop();
+ }
+ return api[k].apply(api, arguments);
+ }
+ };
+ });
+
+ // ########################################################################
// jQuery Plugin and public access
// ########################################################################
@@ -762,10 +825,4 @@ */
window.Impromptu = Imp;
- /**
- * Set $.prompt as a single instance
- * Can be used from here forth as $.prompt.open(state, opts)
- */
- $.prompt = new Imp();
-
}));
diff --git a/test/jquery-impromptu_spec.js b/test/jquery-impromptu_spec.js index 08e231b..640fdfd 100644 --- a/test/jquery-impromptu_spec.js +++ b/test/jquery-impromptu_spec.js @@ -24,7 +24,7 @@ describe('jquery-impromptu', function() { var expectedTitle = 'This is a title', expectedText = 'This is a test'; - $.prompt.open(expectedText, { title: expectedTitle }); + $.prompt(expectedText, { title: expectedTitle }); expect($('.jqibox')).toExist(); expect($('.jqifade')).toExist(); @@ -82,7 +82,7 @@ describe('jquery-impromptu', function() { it('should generate buttons from hash', function() { - $.prompt.open('This is a test', { + $.prompt('This is a test', { buttons: { Ok:true, Cancel:false } }); var okBtn = $('button[name="jqi_state0_buttonOk"]'), @@ -102,7 +102,7 @@ describe('jquery-impromptu', function() { it('should generate buttons from array', function() { - $.prompt.open('This is a test', { + $.prompt('This is a test', { buttons: [ { title: 'Ok', value: true }, { title: 'Cancel', value: false } @@ -125,7 +125,7 @@ describe('jquery-impromptu', function() { it('should add classes to buttons', function() { - $.prompt.open('This is a test', { + $.prompt('This is a test', { buttons: [ { title: 'Ok', value: true, classes: ['ok1','ok2'] }, { title: 'Cancel', value: false, classes: 'cancel1 cancel2' } @@ -143,7 +143,7 @@ describe('jquery-impromptu', function() { it('should add classes to buttons from classes obj', function() { - $.prompt.open('This is a test', { + $.prompt('This is a test', { buttons: [ { title: 'Ok', value: true, classes: ['ok1','ok2'] }, { title: 'Cancel', value: false, classes: 'cancel1 cancel2' } @@ -159,7 +159,7 @@ describe('jquery-impromptu', function() { it('should default correct button', function() { - $.prompt.open('This is a test', { + $.prompt('This is a test', { buttons: [ { title: 'Ok', value: 1 }, { title: 'Cancel', value: 2 }, @@ -178,7 +178,7 @@ describe('jquery-impromptu', function() { it('should default correct button when focus on an input', function() { - $.prompt.open('This is a test <input type="text" id="testInput" />', { + $.prompt('This is a test <input type="text" id="testInput" />', { buttons: [ { title: 'Ok', value: 1 }, { title: 'Cancel', value: 2 }, @@ -211,7 +211,7 @@ describe('jquery-impromptu', function() { it('should create a single state from string', function() { - $.prompt.open('This is a test'); + $.prompt('This is a test'); expect($('.jqistate')).toExist(); }); @@ -223,7 +223,7 @@ describe('jquery-impromptu', function() { s3: { html: 'state 3' } }; - $.prompt.open(states); + $.prompt(states); expect($('.jqistate')).toHaveLength(3); @@ -239,7 +239,7 @@ describe('jquery-impromptu', function() { { html: 'state 3' } ]; - $.prompt.open(states); + $.prompt(states); expect($('.jqistate')).toHaveLength(3); @@ -257,7 +257,7 @@ describe('jquery-impromptu', function() { { html: 'state 3' } ]; - $.prompt.open(states); + $.prompt(states); expect($('.jqistate[data-jqi-name="0"]')).toHaveCss({display:'block'}); expect($('.jqistate[data-jqi-name="1"]')).toHaveCss({display:'none'}); @@ -271,7 +271,7 @@ describe('jquery-impromptu', function() { { name: 's3', html: 'state 3' } ]; - $.prompt.open(states); + $.prompt(states); expect($('.jqistate[data-jqi-name="s1"]')).toExist(); expect($('.jqistate[data-jqi-name="s2"]')).toExist(); @@ -301,12 +301,12 @@ describe('jquery-impromptu', function() { describe('static methods', function() { // ==================================================================================== - describe('Impromptu.setDefaults()', function() { + describe('$.prompt.setDefaults()', function() { it('should change the default values', function() { var origDefs = $.extend(true, {}, Impromptu.defaults), overrides = { prefix: 'myjqi', classes: { box: 'boxclass' } }; - Impromptu.setDefaults(overrides); + $.prompt.setDefaults(overrides); expect(Impromptu.defaults.prefix).toBe(overrides.prefix); expect(Impromptu.defaults.classes.box).toBe(overrides.classes.box); @@ -317,12 +317,12 @@ describe('jquery-impromptu', function() { }); // ==================================================================================== - describe('Impromptu.setStateDefaults()', function() { + describe('$.prompt.setStateDefaults()', function() { it('should change the default state values', function() { var origDefs = $.extend(true, {}, Impromptu.defaults), overrides = { title: 'My Title', position: { width: 123 } }; - Impromptu.setStateDefaults(overrides); + $.prompt.setStateDefaults(overrides); expect(Impromptu.defaults.state.title).toBe(overrides.title); expect(Impromptu.defaults.state.position.width).toBe(overrides.position.width); @@ -335,10 +335,23 @@ describe('jquery-impromptu', function() { describe('instance methods', function() { // ==================================================================================== + describe('$.prompt.getBox()', function() { + it('should return the box jquery object', function() { + + $.prompt('This is a test'); + + var actualResult = $.prompt.getBox(), + expectedResult = $('.jqibox'); + + expect(actualResult[0]).toBe(expectedResult[0]); + }); + }); + + // ==================================================================================== describe('$.prompt.getPrompt()', function() { it('should return the prompt jquery object', function() { - $.prompt.open('This is a test'); + $.prompt('This is a test'); var actualResult = $.prompt.getPrompt(), expectedResult = $('.jqi'); @@ -351,7 +364,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.getState()', function() { it('should return the state jquery object', function() { - $.prompt.open(states); + $.prompt(states); var actualResult = $.prompt.getState('s2'), expectedResult = $('.jqistate[data-jqi-name="s2"]'); @@ -364,7 +377,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.getCurrentState()', function() { it('should return the current state jquery object', function() { - $.prompt.open(states); + $.prompt(states); var actualResult = $.prompt.getCurrentState(), expectedResult = $('.jqistate[data-jqi-name="s1"]'); @@ -374,7 +387,7 @@ describe('jquery-impromptu', function() { it('should return the current state jquery object after a state change', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s2'); var actualResult = $.prompt.getCurrentState(), expectedResult = $('.jqistate[data-jqi-name="s2"]'); @@ -387,7 +400,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.getCurrentStateName()', function() { it('should return the current state name', function() { - $.prompt.open(states); + $.prompt(states); var actualResult = $.prompt.getCurrentStateName(), expectedResult = 's1'; @@ -397,7 +410,7 @@ describe('jquery-impromptu', function() { it('should return the current state name after a state change', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s2'); var actualResult = $.prompt.getCurrentStateName(), expectedResult = 's2'; @@ -410,7 +423,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.goToState()', function() { it('should make the requested state visible', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s3'); @@ -421,7 +434,7 @@ describe('jquery-impromptu', function() { it('should do nothing if the state is not available', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s4'); @@ -432,7 +445,7 @@ describe('jquery-impromptu', function() { it('should handle substate option', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s2',true); @@ -448,7 +461,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.nextState()', function() { it('should make the next state visible', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.nextState(); @@ -459,7 +472,7 @@ describe('jquery-impromptu', function() { it('should do nothing if the state is not available', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s3'); $.prompt.nextState(); @@ -474,7 +487,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.prevState()', function() { it('should make the previous state visible', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s3'); $.prompt.prevState(); @@ -486,7 +499,7 @@ describe('jquery-impromptu', function() { it('should do nothing if the state is not available', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.prevState(); @@ -506,7 +519,7 @@ describe('jquery-impromptu', function() { buttons: { Ok:true,Cancel:false} }; - $.prompt.open(states); + $.prompt(states); var $stateobj = $.prompt.addState(newState.name, newState); @@ -535,7 +548,7 @@ describe('jquery-impromptu', function() { }, afterState = 's2'; - $.prompt.open(states); + $.prompt(states); var $stateobj = $.prompt.addState(newState.name, newState, afterState); @@ -547,7 +560,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.removeState()', function() { it('should remove the specified state', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.removeState('s2'); @@ -556,7 +569,7 @@ describe('jquery-impromptu', function() { it('should display requested state', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.removeState('s1','s3'); @@ -566,7 +579,7 @@ describe('jquery-impromptu', function() { it('should display next state', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.removeState('s1'); @@ -576,7 +589,7 @@ describe('jquery-impromptu', function() { it('should display previous state', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.goToState('s3'); $.prompt.removeState('s3'); @@ -590,7 +603,7 @@ describe('jquery-impromptu', function() { describe('$.prompt.close()', function() { it('should close the prompt', function() { - $.prompt.open(states); + $.prompt(states); $.prompt.close(); @@ -627,7 +640,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; $('body').on('impromptu:loaded', '.jqibox', function(){ spyEventCalled=true; done(); }); - $.prompt.open(states); + $.prompt(states); }); it('should fire event', function(){ @@ -640,7 +653,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; - $.prompt.open(states, { loaded: function(){ spyEventCalled = true; done(); } }); + $.prompt(states, { loaded: function(){ spyEventCalled = true; done(); } }); }); it('should allow event function as option parameter', function(){ @@ -658,7 +671,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; $('body').on('impromptu:close', '.jqibox', function(){ spyEventCalled=true; done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.close(); } @@ -675,7 +688,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.close(); }, close: function(){ spyEventCalled = true; done(); } }); @@ -698,7 +711,7 @@ describe('jquery-impromptu', function() { spyEventCalled = false; $('body').on('impromptu:statechanging', '.jqibox', function(){ spyEventCalled = true; done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.goToState('s2'); } @@ -716,7 +729,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.goToState('s2'); }, @@ -733,7 +746,7 @@ describe('jquery-impromptu', function() { it('should allow preventDefault', function(){ var spyEvent = spyOnEvent('body', 'impromptu:statechanging'); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.goToState('s2'); }, @@ -758,7 +771,7 @@ describe('jquery-impromptu', function() { spyEventCalled = false; $('body').on('impromptu:statechanged', '.jqibox', function(){ spyEventCalled = true; done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.goToState('s2'); } @@ -776,7 +789,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.goToState('s2'); }, @@ -801,7 +814,7 @@ describe('jquery-impromptu', function() { spyEventCalled = false; $('body').on('impromptu:submit', '.jqibox', function(){ spyEventCalled = true; done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.getState('s1').find('.jqibutton:first').click(); } @@ -821,7 +834,7 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ spyEventCalled = false; - $.prompt.open('Test message', { + $.prompt('Test message', { loaded: function(){ $('.jqibutton:first').click(); }, @@ -849,7 +862,7 @@ describe('jquery-impromptu', function() { done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ $.prompt.getState('s1').find('button[value="false"]').click(); } @@ -901,7 +914,7 @@ describe('jquery-impromptu', function() { done(); }); - $.prompt.open(tmpStates, { + $.prompt(tmpStates, { loaded: function(){ $.prompt.getState('s1').find('button[value="true"]').click(); } @@ -943,11 +956,11 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ var e = $.Event('keydown'); e.keyCode = 27; - $.prompt.jqib.trigger(e); + $.prompt.getBox().trigger(e); done(); }, persistent: true @@ -964,11 +977,11 @@ describe('jquery-impromptu', function() { beforeEach(function(done){ - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ var e = $.Event('keydown'); e.keyCode = 27; - $.prompt.jqib.trigger(e); + $.prompt.getBox().trigger(e); done(); }, persistent: false @@ -991,11 +1004,11 @@ describe('jquery-impromptu', function() { done(); }); - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ var e = $.Event('keydown'); e.keyCode = 13; - $.prompt.jqi.trigger(e); + $.prompt.getPrompt().trigger(e); } }); }); @@ -1013,10 +1026,10 @@ describe('jquery-impromptu', function() { describe('fade click', function(){ beforeEach(function(done){ - $.prompt.open(states, { + $.prompt(states, { loaded: function(){ var e = $.Event('click'); - $.prompt.jqib.trigger(e); + $.prompt.getBox().trigger(e); done(); }, |