diff options
author | Trent Richardson <trentdrichardson@gmail.com> | 2013-05-07 11:59:58 -0400 |
---|---|---|
committer | Trent Richardson <trentdrichardson@gmail.com> | 2013-05-07 11:59:58 -0400 |
commit | d558c4758424a05419fb2a2a1ff393cd6b106467 (patch) | |
tree | 3b851fb60266f64ecdd0eb4783c3b6a1037810ea | |
parent | 54154e93eff42ec118719b4ba59728b52063d632 (diff) | |
download | jQuery-Impromptu-d558c4758424a05419fb2a2a1ff393cd6b106467.zip jQuery-Impromptu-d558c4758424a05419fb2a2a1ff393cd6b106467.tar.gz jQuery-Impromptu-d558c4758424a05419fb2a2a1ff393cd6b106467.tar.bz2 |
Fixes state name, updates docs
-rw-r--r-- | index.html | 10 | ||||
-rw-r--r-- | jquery-impromptu.js | 26 |
2 files changed, 24 insertions, 12 deletions
@@ -177,7 +177,7 @@ <dd>An object containing the text and values of each button the user may click. <em>Default: { Ok : true }</em></dd> <dt>focus</dt> - <dd>Index of the button to focus(0,1,2..). <em>Default: 0</em></dd> + <dd>Index of the button to focus or selector to element to focus. <em>Default: 0</em></dd> <dt>submit</dt> <dd>A function to be called when the prompt is submitted. <em>Default: function(event, value, message, formVals){}</em> Return false or event.preventDefault() to keep the prompt open. Event object also has properties event.state and event.stateName.</dd> @@ -211,7 +211,7 @@ <dd>A function to be called when the prompt is closed and just before being removed from the DOM. <em>Default: function(event[, value, message, formVals]){}</em> Last three paremeters available only when button was clicked.</dd> <dt>focus</dt> - <dd>Index of the button to focus(0,1,2..). <em>Default: 0</em></dd> + <dd>Index of the button to focus or selector to element to focus. <em>Default: 0</em></dd> <dt>loaded</dt> <dd>A function to be called when the prompt is fully loaded <em>Default: function(event){}</em></dd> @@ -418,12 +418,12 @@ $.prompt(statesdemo);</pre> <div class="example-container" id="TourExample"> <p>To use states pass in a collection (array or object) of objects with common properties (html, buttons, focus, submit, position..).</p> -<pre class="code" id="TourCode">var tourSubmitFunc = function(e,v,m,f){console.log(v); - if(v === -1){console.log('prev'); +<pre class="code" id="TourCode">var tourSubmitFunc = function(e,v,m,f){ + if(v === -1){ $.prompt.prevState(); return false; } - else if(v === 1){console.log('next'); + else if(v === 1){ $.prompt.nextState(); return false; } diff --git a/jquery-impromptu.js b/jquery-impromptu.js index 6b33ee0..ffa8f8e 100644 --- a/jquery-impromptu.js +++ b/jquery-impromptu.js @@ -64,6 +64,9 @@ for(k in message){
v = $.extend({},$.prompt.defaults.state,{name:k},message[k]);
$.prompt.addState(v.name, v);
+
+ if($.prompt.currentStateName === '')
+ $.prompt.currentStateName = v.name;
}
// Go ahead and transition to the first state. It won't be visible just yet though until we show the prompt
@@ -241,6 +244,12 @@ * 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
@@ -266,15 +275,15 @@ */
$.prompt.position = function(e){
var restoreFx = $.fx.off,
+ $state = $.prompt.getCurrentState(),
+ pos = $state.data('jqi').position,
$window = $(window),
bodyHeight = $(document.body).outerHeight(true),
windowHeight = $(window).height(),
documentHeight = $(document).height(),
height = bodyHeight > windowHeight ? bodyHeight : windowHeight,
top = parseInt($window.scrollTop(),10) + ($.prompt.options.top.toString().indexOf('%') >= 0?
- (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10)),
- $state = $.prompt.getCurrentState(),
- pos = $state.data('jqi').position;
+ (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10));
// This fixes the whitespace at the bottom of the fade, but it is
// inconsistant and can cause an unneeded scrollbar, making the page jump
@@ -391,7 +400,7 @@ $jqistates = $('.'+ $.prompt.currentPrefix +'states'),
k,v,i=0;
- stateobj = $.extend({},$.prompt.defaults.state, stateobj);
+ stateobj = $.extend({},$.prompt.defaults.state, {name:statename}, stateobj);
if(stateobj.position.arrow !== null)
arrow = '<div class="'+ $.prompt.options.prefix + 'arrow '+ $.prompt.options.prefix + 'arrow'+ stateobj.position.arrow +'"></div>';
@@ -428,7 +437,7 @@ $state.data('jqi',stateobj).bind('promptsubmit', stateobj.submit);
if(afterState !== undefined){
- $jqistates.find('#'+ $.prompt.currentPrefix +'state_'+ afterState).after(state);
+ $jqistates.find('#'+ $.prompt.currentPrefix +'state_'+ afterState).after($state);
}
else{
$jqistates.append($state);
@@ -483,7 +492,7 @@ * @return jQuery - the current visible state
*/
$.prompt.getCurrentState = function() {
- return $('.'+ $.prompt.currentPrefix +'state:visible');
+ return $.prompt.getState($.prompt.getCurrentStateName());
};
/**
@@ -491,7 +500,7 @@ * @return String - the current visible state's name
*/
$.prompt.getCurrentStateName = function() {
- return $.prompt.getCurrentState().data('jqi-name');
+ return $.prompt.currentStateName;
};
/**
@@ -506,6 +515,7 @@ $state = $.prompt.getState(state),
stateobj = $state.data('jqi'),
promptstatechanginge = new $.Event('promptstatechanging');
+
$.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
@@ -513,6 +523,8 @@ $('.'+ $.prompt.currentPrefix +'state').not($state).slideUp(jqiopts.promptspeed)
.find('.'+ $.prompt.currentPrefix +'arrow').fadeOut();
+ $.prompt.currentStateName = stateobj.name;
+
$state.slideDown(jqiopts.promptspeed,function(){
var $t = $(this);
|