Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: option to go to a specific step #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions build/jquery.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,16 @@ function getValidEnumValue(enumType, keyOrValue)
**/
function goToNextStep(wizard, options, state)
{
return paginationClick(wizard, options, state, increaseCurrentIndexBy(state, 1));
// Determine next active step
var newIndex = increaseCurrentIndexBy(state, 1);
do {
if (typeof state.disabledSteps == 'undefined' || $.inArray(newIndex, state.disabledSteps) == -1) {
break; //found an index that is not disabled => stop the loop
}
newIndex++;
} while (true);

return paginationClick(wizard, options, state, newIndex);
}

/**
Expand All @@ -472,7 +481,16 @@ function goToNextStep(wizard, options, state)
**/
function goToPreviousStep(wizard, options, state)
{
return paginationClick(wizard, options, state, decreaseCurrentIndexBy(state, 1));
// Determine previous active step
var newIndex = decreaseCurrentIndexBy(state, 1);
do {
if (typeof state.disabledSteps == 'undefined' || $.inArray(newIndex, state.disabledSteps) == -1) {
break; //found an index that is not disabled => stop the loop
}
newIndex--;
} while (true);

return paginationClick(wizard, options, state, newIndex);
}

/**
Expand Down Expand Up @@ -1467,6 +1485,63 @@ $.fn.steps.skip = function (count)
throw new Error("Not yet implemented!");
};

/**
* Sets the current step index.
*
* @method setCurrentIndex
* @param index {Integer} The new step index (zero-based)
* @return {Boolean} Indicates whether the action executed
**/
$.fn.steps.setCurrentIndex = function (index)
{
var options = getOptions(this),
state = getState(this);

return goToStep(this, options, state, index);
};

/**
* Disable a step so that it will be skipped on going to Next and Previous
*
* @method disableStep
* @param index {Integer} Index number of the step to disable
* @return {Boolean} Indicates whether the action executed
**/
$.fn.steps.disableStep = function (index)
{
var state = getState(this);

if (typeof state.disabledSteps == 'undefined') {
state.disabledSteps = [];
}
if ($.inArray(index, state.disabledSteps) == -1) {
state.disabledSteps.push(index);
return true;
}
return false;
};

/**
* Enable a step that was previously disabled
*
* @method enableStep
* @param index {Integer} Index number of the step to re-enable
* @return {Boolean} Indicates whether the action executed
**/
$.fn.steps.enableStep = function (index)
{
var state = getState(this);

if (typeof state.disabledSteps != 'undefined') {
var arrayIndex = $.inArray(index, state.disabledSteps);
if (arrayIndex > -1) {
state.disabledSteps.splice(arrayIndex, 1);
return true;
}
}
return false;
};

/**
* An enum represents the different content types of a step and their loading mechanisms.
*
Expand Down