Skip to content

Commit 7036956

Browse files
author
Rafael J. Staib
committed
Add some changes
1 parent e126ec6 commit 7036956

File tree

1 file changed

+74
-53
lines changed

1 file changed

+74
-53
lines changed

src/privates.js

Lines changed: 74 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ var _indexOutOfRangeErrorMessage = "Index out of range.";
7171
**/
7272
var _missingCorrespondingElementErrorMessage = "One or more corresponding step {0} are missing.";
7373

74+
var _javascriptVoid = "javascript:void(0);";
75+
7476
/**
7577
* Adds a step to the cache.
7678
*
@@ -181,42 +183,65 @@ function format(format)
181183
return format;
182184
}
183185

184-
function getStepAnchor(wizard, index)
186+
function getNextHref(wizard, options, state)
185187
{
186-
var uniqueId = getUniqueId(wizard);
188+
var currentIndex = state.currentIndex;
187189

188-
return wizard.find("#" + uniqueId + _tabSuffix + index);
190+
return (currentIndex < (state.stepCount - 1)) ? "#" + getStepTitleId(wizard, currentIndex + 1) : _javascriptVoid;
189191
}
190192

191-
function getStepPanel(wizard, index)
193+
function getOptions(wizard)
192194
{
193-
var uniqueId = getUniqueId(wizard);
195+
return wizard.data("options");
196+
}
194197

195-
return wizard.find("#" + uniqueId + _tabpanelSuffix + index);
198+
function getPreviousHref(wizard, options, state)
199+
{
200+
var currentIndex = state.currentIndex;
201+
202+
return (currentIndex > 0 && state.stepCount > 1) ? "#" + getStepTitleId(wizard, currentIndex - 1) : _javascriptVoid;
196203
}
197204

198-
function getStepTitle(wizard, index)
205+
function getState(wizard)
206+
{
207+
return wizard.data("state");
208+
}
209+
210+
function getStepAnchor(wizard, index)
199211
{
200-
var uniqueId = getUniqueId(wizard);
212+
return wizard.find("#" + getStepAnchorId(wizard, index));
213+
}
201214

202-
return wizard.find("#" + uniqueId + _titleSuffix + index);
215+
function getStepAnchorId(wizard, index)
216+
{
217+
return getUniqueId(wizard) + _tabSuffix + index;
203218
}
204219

205-
function getOptions(wizard)
220+
function getStepPanel(wizard, index)
206221
{
207-
return wizard.data("options");
222+
return wizard.find("#" + getStepPanelId(wizard, index));
208223
}
209224

210-
function getState(wizard)
225+
function getStepPanelId(wizard, index)
211226
{
212-
return wizard.data("state");
227+
return getUniqueId(wizard) + _tabpanelSuffix + index;
213228
}
214229

215230
function getSteps(wizard)
216231
{
217232
return wizard.data("steps");
218233
}
219234

235+
function getStepTitle(wizard, index)
236+
{
237+
return wizard.find("#" + getStepTitleId(wizard, index));
238+
}
239+
240+
function getStepTitleId(wizard, index)
241+
{
242+
return getUniqueId(wizard) + _titleSuffix + index;
243+
}
244+
220245
/**
221246
* Gets a specific step object by index.
222247
*
@@ -632,27 +657,23 @@ function paginationClick(wizard, options, state, index)
632657
*/
633658
function paginationClickHandler(event)
634659
{
635-
event.preventDefault();
636-
637660
var anchor = $(this),
638661
wizard = anchor.parents(":has(.steps)"),
639662
options = getOptions(wizard),
640663
state = getState(wizard),
641-
href = anchor.attr("href");
642-
643-
switch (href.substring(href.lastIndexOf("#")))
664+
href = anchor.attr("href"),
665+
hashtag = href.substring(href.lastIndexOf("#"));
666+
667+
if (hashtag === "#finish")
644668
{
645-
case "#finish":
646-
finishStep(wizard, options, state);
647-
break;
648-
649-
case "#next":
650-
goToNextStep(wizard, options, state);
651-
break;
669+
event.preventDefault();
670+
finishStep(wizard, options, state);
671+
}
672+
else
673+
{
674+
var position = parseInt(hashtag.substring(hashtag.lastIndexOf("-") + 1), 0);
652675

653-
case "#previous":
654-
goToPreviousStep(wizard, options, state)
655-
break;
676+
goToStep(wizard, options, state, position);
656677
}
657678
}
658679

@@ -670,12 +691,15 @@ function refreshPagination(wizard, options, state)
670691
{
671692
if (options.enablePagination)
672693
{
673-
var finish = wizard.find(".actions a[href$='#finish']").parent(),
674-
next = wizard.find(".actions a[href$='#next']").parent();
694+
var uniqueId = getUniqueId(wizard),
695+
finish = wizard.find("#" + uniqueId + "-p-f").parent(),
696+
next = wizard.find("#" + uniqueId + "-p-n")
697+
.attr("href", getNextHref(wizard, options, state)).parent();
675698

676699
if (!options.forceMoveForward)
677700
{
678-
var previous = wizard.find(".actions a[href$='#previous']").parent();
701+
var previous = wizard.find("#" + uniqueId + "-p-p")
702+
.attr("href", getPreviousHref(wizard, options, state)).parent();
679703
if (state.currentIndex > 0)
680704
{
681705
previous.enableAria();
@@ -772,13 +796,11 @@ function refreshStepNavigation(wizard, options, state, oldIndex)
772796
*/
773797
function refreshSteps(wizard, options, state, index)
774798
{
775-
var uniqueId = getUniqueId(wizard);
776-
777799
for (var i = index; i < state.stepCount; i++)
778800
{
779-
var uniqueStepId = uniqueId + _tabSuffix + i,
780-
uniqueBodyId = uniqueId + _tabpanelSuffix + i,
781-
uniqueHeaderId = uniqueId + _titleSuffix + i,
801+
var uniqueStepId = getStepAnchorId(wizard, i),
802+
uniqueBodyId = getStepPanelId(wizard, i),
803+
uniqueHeaderId = getStepTitleId(wizard, i),
782804
title = wizard.find(".title").eq(i).setId(uniqueHeaderId);
783805

784806
wizard.find(".steps a").eq(i).setId(uniqueStepId)
@@ -915,9 +937,8 @@ function render(wizard, options, state)
915937
*/
916938
function renderBody(wizard, body, index)
917939
{
918-
var uniqueId = getUniqueId(wizard),
919-
uniqueBodyId = uniqueId + _tabpanelSuffix + index,
920-
uniqueHeaderId = uniqueId + _titleSuffix + index;
940+
var uniqueBodyId = getStepPanelId(wizard, index),
941+
uniqueHeaderId = getStepTitleId(wizard, index);
921942

922943
body.setId(uniqueBodyId).attr("role", "tabpanel").aria("labelledby", uniqueHeaderId)
923944
.addClass("body").hideAria();
@@ -937,20 +958,23 @@ function renderPagination(wizard, options, state)
937958
{
938959
if (options.enablePagination)
939960
{
940-
var pagination = "<{0} class=\"actions\"><ul role=\"menu\" aria-label=\"{1}\">{2}</ul></{0}>",
941-
buttonTemplate = "<li><a href=\"#{0}\" role=\"menuitem\">{1}</a></li>",
961+
var uniqueId = getUniqueId(wizard),
962+
pagination = "<{0} class=\"actions\"><ul role=\"menu\" aria-label=\"{1}\">{2}</ul></{0}>",
963+
buttonTemplate = "<li><a id=\"{0}-{1}\" href=\"{2}\" role=\"menuitem\">{3}</a></li>",
942964
buttons = "";
943965

944966
if (!options.forceMoveForward)
945967
{
946-
buttons += format(buttonTemplate, "previous", options.labels.previous);
968+
buttons += format(buttonTemplate, uniqueId, "p-p",
969+
getPreviousHref(wizard, options, state), options.labels.previous);
947970
}
948971

949-
buttons += format(buttonTemplate, "next", options.labels.next);
972+
buttons += format(buttonTemplate, uniqueId, "p-n",
973+
getNextHref(wizard, options, state), options.labels.next);
950974

951975
if (options.enableFinishButton)
952976
{
953-
buttons += format(buttonTemplate, "finish", options.labels.finish);
977+
buttons += format(buttonTemplate, uniqueId, "p-f", "#finish", options.labels.finish);
954978
}
955979

956980
wizard.append(format(pagination, options.actionContainerTag, options.labels.pagination, buttons));
@@ -1004,17 +1028,16 @@ function renderTemplate(template, substitutes)
10041028
*/
10051029
function renderTitle(wizard, options, state, header, index)
10061030
{
1007-
var uniqueId = getUniqueId(wizard),
1008-
uniqueStepId = uniqueId + _tabSuffix + index,
1009-
uniqueBodyId = uniqueId + _tabpanelSuffix + index,
1010-
uniqueHeaderId = uniqueId + _titleSuffix + index,
1031+
var uniqueStepId = getStepAnchorId(wizard, index),
1032+
uniqueBodyId = getStepPanelId(wizard, index),
1033+
uniqueHeaderId = getStepTitleId(wizard, index),
10111034
stepCollection = wizard.find(".steps > ul"),
10121035
title = renderTemplate(options.titleTemplate, {
10131036
index: index + 1,
10141037
title: header.html()
10151038
}),
1016-
stepItem = $("<li role=\"tab\"><a id=\"" + uniqueStepId + "\" href=\"#" + uniqueHeaderId +
1017-
"\" aria-controls=\"" + uniqueBodyId + "\">" + title + "</a></li>");
1039+
stepItem = $(format("<li role=\"tab\"><a id=\"{0}\" href=\"#{1}\" aria-controls=\"{2}\">{3}</a></li>",
1040+
uniqueStepId, uniqueHeaderId, uniqueBodyId, title));
10181041

10191042
if (!options.enableAllSteps)
10201043
{
@@ -1132,9 +1155,6 @@ function startTransitionEffect(wizard, options, state, index, oldIndex)
11321155
*/
11331156
function stepClickHandler(event)
11341157
{
1135-
// Uncoment this line in order to allow hashtag in the url for plugins like jquery-hashchange (#5)
1136-
//event.preventDefault();
1137-
11381158
var anchor = $(this),
11391159
wizard = anchor.parents(":has(.steps)"),
11401160
options = getOptions(wizard),
@@ -1152,6 +1172,7 @@ function stepClickHandler(event)
11521172
// If nothing has changed
11531173
if (oldIndex === state.currentIndex)
11541174
{
1175+
event.preventDefault();
11551176
getStepAnchor(wizard, oldIndex).focus();
11561177
return false;
11571178
}

0 commit comments

Comments
 (0)