@@ -200,6 +200,19 @@ function analyzeData(wizard, options, state)
200
200
} ) ;
201
201
}
202
202
203
+ /**
204
+ * Triggers the onCanceled event.
205
+ *
206
+ * @static
207
+ * @private
208
+ * @method cancel
209
+ * @param wizard {Object} The jQuery wizard object
210
+ **/
211
+ function cancel ( wizard )
212
+ {
213
+ wizard . triggerHandler ( "canceled" ) ;
214
+ }
215
+
203
216
function decreaseCurrentIndexBy ( state , decreaseBy )
204
217
{
205
218
return state . currentIndex - decreaseBy ;
@@ -765,17 +778,21 @@ function paginationClickHandler(event)
765
778
state = getState ( wizard ) ,
766
779
href = anchor . attr ( "href" ) ;
767
780
768
- switch ( href . substring ( href . lastIndexOf ( "#" ) ) )
781
+ switch ( href . substring ( href . lastIndexOf ( "#" ) + 1 ) )
769
782
{
770
- case "#finish" :
783
+ case "cancel" :
784
+ cancel ( wizard ) ;
785
+ break ;
786
+
787
+ case "finish" :
771
788
finishStep ( wizard , state ) ;
772
789
break ;
773
790
774
- case "# next" :
791
+ case "next" :
775
792
goToNextStep ( wizard , options , state ) ;
776
793
break ;
777
794
778
- case "# previous" :
795
+ case "previous" :
779
796
goToPreviousStep ( wizard , options , state ) ;
780
797
break ;
781
798
}
@@ -811,7 +828,7 @@ function refreshPagination(wizard, options, state)
811
828
}
812
829
else
813
830
{
814
- finish . _showAria ( options . enableFinishButton && state . stepCount > ( state . currentIndex + 1 ) ) ;
831
+ finish . _showAria ( options . enableFinishButton && state . stepCount >= ( state . currentIndex + 1 ) ) ;
815
832
next . _showAria ( state . stepCount === 0 || state . stepCount > ( state . currentIndex + 1 ) ) .
816
833
_enableAria ( state . stepCount > ( state . currentIndex + 1 ) || ! options . enableFinishButton ) ;
817
834
}
@@ -882,6 +899,7 @@ function registerEvents(wizard, options)
882
899
{
883
900
var eventNamespace = getEventNamespace ( wizard ) ;
884
901
902
+ wizard . bind ( "canceled" + eventNamespace , options . onCanceled ) ;
885
903
wizard . bind ( "finishing" + eventNamespace , options . onFinishing ) ;
886
904
wizard . bind ( "finished" + eventNamespace , options . onFinished ) ;
887
905
wizard . bind ( "stepChanging" + eventNamespace , options . onStepChanging ) ;
@@ -1044,6 +1062,11 @@ function renderPagination(wizard, options, state)
1044
1062
buttons += buttonTemplate . format ( "finish" , options . labels . finish ) ;
1045
1063
}
1046
1064
1065
+ if ( options . enableCancelButton )
1066
+ {
1067
+ buttons += buttonTemplate . format ( "cancel" , options . labels . cancel ) ;
1068
+ }
1069
+
1047
1070
wizard . append ( pagination . format ( options . actionContainerTag , options . clearFixCssClass ,
1048
1071
options . labels . pagination , buttons ) ) ;
1049
1072
@@ -1305,10 +1328,8 @@ $.fn.steps = function (method)
1305
1328
**/
1306
1329
$ . fn . steps . add = function ( step )
1307
1330
{
1308
- var options = getOptions ( this ) ,
1309
- state = getState ( this ) ;
1310
-
1311
- return insertStep ( this , options , state , state . stepCount , step ) ;
1331
+ var state = getState ( this ) ;
1332
+ return insertStep ( this , getOptions ( this ) , state , state . stepCount , step ) ;
1312
1333
} ;
1313
1334
1314
1335
/**
@@ -1319,9 +1340,7 @@ $.fn.steps.add = function (step)
1319
1340
**/
1320
1341
$ . fn . steps . destroy = function ( )
1321
1342
{
1322
- var options = getOptions ( this ) ;
1323
-
1324
- return destroy ( this , options ) ;
1343
+ return destroy ( this , getOptions ( this ) ) ;
1325
1344
} ;
1326
1345
1327
1346
/**
@@ -1331,9 +1350,7 @@ $.fn.steps.destroy = function ()
1331
1350
**/
1332
1351
$ . fn . steps . finish = function ( )
1333
1352
{
1334
- var state = getState ( this ) ;
1335
-
1336
- finishStep ( this , state ) ;
1353
+ finishStep ( this , getState ( this ) ) ;
1337
1354
} ;
1338
1355
1339
1356
/**
@@ -1388,10 +1405,7 @@ $.fn.steps.getStep = function (index)
1388
1405
**/
1389
1406
$ . fn . steps . insert = function ( index , step )
1390
1407
{
1391
- var options = getOptions ( this ) ,
1392
- state = getState ( this ) ;
1393
-
1394
- return insertStep ( this , options , state , index , step ) ;
1408
+ return insertStep ( this , getOptions ( this ) , getState ( this ) , index , step ) ;
1395
1409
} ;
1396
1410
1397
1411
/**
@@ -1402,11 +1416,7 @@ $.fn.steps.insert = function (index, step)
1402
1416
**/
1403
1417
$ . fn . steps . next = function ( )
1404
1418
{
1405
- var options = getOptions ( this ) ,
1406
- state = getState ( this ) ;
1407
-
1408
-
1409
- return goToNextStep ( this , options , state ) ;
1419
+ return goToNextStep ( this , getOptions ( this ) , getState ( this ) ) ;
1410
1420
} ;
1411
1421
1412
1422
/**
@@ -1417,10 +1427,7 @@ $.fn.steps.next = function ()
1417
1427
**/
1418
1428
$ . fn . steps . previous = function ( )
1419
1429
{
1420
- var options = getOptions ( this ) ,
1421
- state = getState ( this ) ;
1422
-
1423
- return goToPreviousStep ( this , options , state ) ;
1430
+ return goToPreviousStep ( this , getOptions ( this ) , getState ( this ) ) ;
1424
1431
} ;
1425
1432
1426
1433
/**
@@ -1432,10 +1439,7 @@ $.fn.steps.previous = function ()
1432
1439
**/
1433
1440
$ . fn . steps . remove = function ( index )
1434
1441
{
1435
- var options = getOptions ( this ) ,
1436
- state = getState ( this ) ;
1437
-
1438
- return removeStep ( this , options , state , index ) ;
1442
+ return removeStep ( this , getOptions ( this ) , getState ( this ) , index ) ;
1439
1443
} ;
1440
1444
1441
1445
/**
@@ -1774,6 +1778,16 @@ var defaults = $.fn.steps.defaults = {
1774
1778
**/
1775
1779
enableContentCache : true ,
1776
1780
1781
+ /**
1782
+ * Shows the cancel button if enabled.
1783
+ *
1784
+ * @property enableCancelButton
1785
+ * @type Boolean
1786
+ * @default true
1787
+ * @for defaults
1788
+ **/
1789
+ enableCancelButton : true ,
1790
+
1777
1791
/**
1778
1792
* Shows the finish button if enabled.
1779
1793
*
@@ -1885,6 +1899,16 @@ var defaults = $.fn.steps.defaults = {
1885
1899
**/
1886
1900
onStepChanged : function ( event , currentIndex , priorIndex ) { } ,
1887
1901
1902
+ /**
1903
+ * Fires after cancelation.
1904
+ *
1905
+ * @property onCanceled
1906
+ * @type Event
1907
+ * @default function (event) { }
1908
+ * @for defaults
1909
+ **/
1910
+ onCanceled : function ( event ) { } ,
1911
+
1888
1912
/**
1889
1913
* Fires before finishing and can be used to prevent completion by returning `false`.
1890
1914
* Very useful for form validation.
@@ -1914,6 +1938,16 @@ var defaults = $.fn.steps.defaults = {
1914
1938
* @for defaults
1915
1939
**/
1916
1940
labels : {
1941
+ /**
1942
+ * Label for the cancel button.
1943
+ *
1944
+ * @property cancel
1945
+ * @type String
1946
+ * @default "Cancel"
1947
+ * @for defaults
1948
+ **/
1949
+ cancel : "Cancel" ,
1950
+
1917
1951
/**
1918
1952
* This label is important for accessability reasons.
1919
1953
* Indicates which step is activated.
0 commit comments