@@ -71,6 +71,8 @@ var _indexOutOfRangeErrorMessage = "Index out of range.";
71
71
**/
72
72
var _missingCorrespondingElementErrorMessage = "One or more corresponding step {0} are missing." ;
73
73
74
+ var _javascriptVoid = "javascript:void(0);" ;
75
+
74
76
/**
75
77
* Adds a step to the cache.
76
78
*
@@ -181,42 +183,65 @@ function format(format)
181
183
return format ;
182
184
}
183
185
184
- function getStepAnchor ( wizard , index )
186
+ function getNextHref ( wizard , options , state )
185
187
{
186
- var uniqueId = getUniqueId ( wizard ) ;
188
+ var currentIndex = state . currentIndex ;
187
189
188
- return wizard . find ( "#" + uniqueId + _tabSuffix + index ) ;
190
+ return ( currentIndex < ( state . stepCount - 1 ) ) ? "#" + getStepTitleId ( wizard , currentIndex + 1 ) : _javascriptVoid ;
189
191
}
190
192
191
- function getStepPanel ( wizard , index )
193
+ function getOptions ( wizard )
192
194
{
193
- var uniqueId = getUniqueId ( wizard ) ;
195
+ return wizard . data ( "options" ) ;
196
+ }
194
197
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 ;
196
203
}
197
204
198
- function getStepTitle ( wizard , index )
205
+ function getState ( wizard )
206
+ {
207
+ return wizard . data ( "state" ) ;
208
+ }
209
+
210
+ function getStepAnchor ( wizard , index )
199
211
{
200
- var uniqueId = getUniqueId ( wizard ) ;
212
+ return wizard . find ( "#" + getStepAnchorId ( wizard , index ) ) ;
213
+ }
201
214
202
- return wizard . find ( "#" + uniqueId + _titleSuffix + index ) ;
215
+ function getStepAnchorId ( wizard , index )
216
+ {
217
+ return getUniqueId ( wizard ) + _tabSuffix + index ;
203
218
}
204
219
205
- function getOptions ( wizard )
220
+ function getStepPanel ( wizard , index )
206
221
{
207
- return wizard . data ( "options" ) ;
222
+ return wizard . find ( "#" + getStepPanelId ( wizard , index ) ) ;
208
223
}
209
224
210
- function getState ( wizard )
225
+ function getStepPanelId ( wizard , index )
211
226
{
212
- return wizard . data ( "state" ) ;
227
+ return getUniqueId ( wizard ) + _tabpanelSuffix + index ;
213
228
}
214
229
215
230
function getSteps ( wizard )
216
231
{
217
232
return wizard . data ( "steps" ) ;
218
233
}
219
234
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
+
220
245
/**
221
246
* Gets a specific step object by index.
222
247
*
@@ -632,27 +657,23 @@ function paginationClick(wizard, options, state, index)
632
657
*/
633
658
function paginationClickHandler ( event )
634
659
{
635
- event . preventDefault ( ) ;
636
-
637
660
var anchor = $ ( this ) ,
638
661
wizard = anchor . parents ( ":has(.steps)" ) ,
639
662
options = getOptions ( wizard ) ,
640
663
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" )
644
668
{
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 ) ;
652
675
653
- case "#previous" :
654
- goToPreviousStep ( wizard , options , state )
655
- break ;
676
+ goToStep ( wizard , options , state , position ) ;
656
677
}
657
678
}
658
679
@@ -670,12 +691,15 @@ function refreshPagination(wizard, options, state)
670
691
{
671
692
if ( options . enablePagination )
672
693
{
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 ( ) ;
675
698
676
699
if ( ! options . forceMoveForward )
677
700
{
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 ( ) ;
679
703
if ( state . currentIndex > 0 )
680
704
{
681
705
previous . enableAria ( ) ;
@@ -772,13 +796,11 @@ function refreshStepNavigation(wizard, options, state, oldIndex)
772
796
*/
773
797
function refreshSteps ( wizard , options , state , index )
774
798
{
775
- var uniqueId = getUniqueId ( wizard ) ;
776
-
777
799
for ( var i = index ; i < state . stepCount ; i ++ )
778
800
{
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 ) ,
782
804
title = wizard . find ( ".title" ) . eq ( i ) . setId ( uniqueHeaderId ) ;
783
805
784
806
wizard . find ( ".steps a" ) . eq ( i ) . setId ( uniqueStepId )
@@ -915,9 +937,8 @@ function render(wizard, options, state)
915
937
*/
916
938
function renderBody ( wizard , body , index )
917
939
{
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 ) ;
921
942
922
943
body . setId ( uniqueBodyId ) . attr ( "role" , "tabpanel" ) . aria ( "labelledby" , uniqueHeaderId )
923
944
. addClass ( "body" ) . hideAria ( ) ;
@@ -937,20 +958,23 @@ function renderPagination(wizard, options, state)
937
958
{
938
959
if ( options . enablePagination )
939
960
{
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>" ,
942
964
buttons = "" ;
943
965
944
966
if ( ! options . forceMoveForward )
945
967
{
946
- buttons += format ( buttonTemplate , "previous" , options . labels . previous ) ;
968
+ buttons += format ( buttonTemplate , uniqueId , "p-p" ,
969
+ getPreviousHref ( wizard , options , state ) , options . labels . previous ) ;
947
970
}
948
971
949
- buttons += format ( buttonTemplate , "next" , options . labels . next ) ;
972
+ buttons += format ( buttonTemplate , uniqueId , "p-n" ,
973
+ getNextHref ( wizard , options , state ) , options . labels . next ) ;
950
974
951
975
if ( options . enableFinishButton )
952
976
{
953
- buttons += format ( buttonTemplate , " finish", options . labels . finish ) ;
977
+ buttons += format ( buttonTemplate , uniqueId , "p-f" , "# finish", options . labels . finish ) ;
954
978
}
955
979
956
980
wizard . append ( format ( pagination , options . actionContainerTag , options . labels . pagination , buttons ) ) ;
@@ -1004,17 +1028,16 @@ function renderTemplate(template, substitutes)
1004
1028
*/
1005
1029
function renderTitle ( wizard , options , state , header , index )
1006
1030
{
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 ) ,
1011
1034
stepCollection = wizard . find ( ".steps > ul" ) ,
1012
1035
title = renderTemplate ( options . titleTemplate , {
1013
1036
index : index + 1 ,
1014
1037
title : header . html ( )
1015
1038
} ) ,
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 ) ) ;
1018
1041
1019
1042
if ( ! options . enableAllSteps )
1020
1043
{
@@ -1132,9 +1155,6 @@ function startTransitionEffect(wizard, options, state, index, oldIndex)
1132
1155
*/
1133
1156
function stepClickHandler ( event )
1134
1157
{
1135
- // Uncoment this line in order to allow hashtag in the url for plugins like jquery-hashchange (#5)
1136
- //event.preventDefault();
1137
-
1138
1158
var anchor = $ ( this ) ,
1139
1159
wizard = anchor . parents ( ":has(.steps)" ) ,
1140
1160
options = getOptions ( wizard ) ,
@@ -1152,6 +1172,7 @@ function stepClickHandler(event)
1152
1172
// If nothing has changed
1153
1173
if ( oldIndex === state . currentIndex )
1154
1174
{
1175
+ event . preventDefault ( ) ;
1155
1176
getStepAnchor ( wizard , oldIndex ) . focus ( ) ;
1156
1177
return false ;
1157
1178
}
0 commit comments