@@ -200,6 +200,19 @@ function analyzeData(wizard, options, state)
200200 } ) ;
201201}
202202
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+
203216function decreaseCurrentIndexBy ( state , decreaseBy )
204217{
205218 return state . currentIndex - decreaseBy ;
@@ -765,17 +778,21 @@ function paginationClickHandler(event)
765778 state = getState ( wizard ) ,
766779 href = anchor . attr ( "href" ) ;
767780
768- switch ( href . substring ( href . lastIndexOf ( "#" ) ) )
781+ switch ( href . substring ( href . lastIndexOf ( "#" ) + 1 ) )
769782 {
770- case "#finish" :
783+ case "cancel" :
784+ cancel ( wizard ) ;
785+ break ;
786+
787+ case "finish" :
771788 finishStep ( wizard , state ) ;
772789 break ;
773790
774- case "# next" :
791+ case "next" :
775792 goToNextStep ( wizard , options , state ) ;
776793 break ;
777794
778- case "# previous" :
795+ case "previous" :
779796 goToPreviousStep ( wizard , options , state ) ;
780797 break ;
781798 }
@@ -811,7 +828,7 @@ function refreshPagination(wizard, options, state)
811828 }
812829 else
813830 {
814- finish . _showAria ( options . enableFinishButton && state . stepCount > ( state . currentIndex + 1 ) ) ;
831+ finish . _showAria ( options . enableFinishButton && state . stepCount >= ( state . currentIndex + 1 ) ) ;
815832 next . _showAria ( state . stepCount === 0 || state . stepCount > ( state . currentIndex + 1 ) ) .
816833 _enableAria ( state . stepCount > ( state . currentIndex + 1 ) || ! options . enableFinishButton ) ;
817834 }
@@ -882,6 +899,7 @@ function registerEvents(wizard, options)
882899{
883900 var eventNamespace = getEventNamespace ( wizard ) ;
884901
902+ wizard . bind ( "canceled" + eventNamespace , options . onCanceled ) ;
885903 wizard . bind ( "finishing" + eventNamespace , options . onFinishing ) ;
886904 wizard . bind ( "finished" + eventNamespace , options . onFinished ) ;
887905 wizard . bind ( "stepChanging" + eventNamespace , options . onStepChanging ) ;
@@ -1044,6 +1062,11 @@ function renderPagination(wizard, options, state)
10441062 buttons += buttonTemplate . format ( "finish" , options . labels . finish ) ;
10451063 }
10461064
1065+ if ( options . enableCancelButton )
1066+ {
1067+ buttons += buttonTemplate . format ( "cancel" , options . labels . cancel ) ;
1068+ }
1069+
10471070 wizard . append ( pagination . format ( options . actionContainerTag , options . clearFixCssClass ,
10481071 options . labels . pagination , buttons ) ) ;
10491072
@@ -1305,10 +1328,8 @@ $.fn.steps = function (method)
13051328 **/
13061329$ . fn . steps . add = function ( step )
13071330{
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 ) ;
13121333} ;
13131334
13141335/**
@@ -1319,9 +1340,7 @@ $.fn.steps.add = function (step)
13191340 **/
13201341$ . fn . steps . destroy = function ( )
13211342{
1322- var options = getOptions ( this ) ;
1323-
1324- return destroy ( this , options ) ;
1343+ return destroy ( this , getOptions ( this ) ) ;
13251344} ;
13261345
13271346/**
@@ -1331,9 +1350,7 @@ $.fn.steps.destroy = function ()
13311350 **/
13321351$ . fn . steps . finish = function ( )
13331352{
1334- var state = getState ( this ) ;
1335-
1336- finishStep ( this , state ) ;
1353+ finishStep ( this , getState ( this ) ) ;
13371354} ;
13381355
13391356/**
@@ -1388,10 +1405,7 @@ $.fn.steps.getStep = function (index)
13881405 **/
13891406$ . fn . steps . insert = function ( index , step )
13901407{
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 ) ;
13951409} ;
13961410
13971411/**
@@ -1402,11 +1416,7 @@ $.fn.steps.insert = function (index, step)
14021416 **/
14031417$ . fn . steps . next = function ( )
14041418{
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 ) ) ;
14101420} ;
14111421
14121422/**
@@ -1417,10 +1427,7 @@ $.fn.steps.next = function ()
14171427 **/
14181428$ . fn . steps . previous = function ( )
14191429{
1420- var options = getOptions ( this ) ,
1421- state = getState ( this ) ;
1422-
1423- return goToPreviousStep ( this , options , state ) ;
1430+ return goToPreviousStep ( this , getOptions ( this ) , getState ( this ) ) ;
14241431} ;
14251432
14261433/**
@@ -1432,10 +1439,7 @@ $.fn.steps.previous = function ()
14321439 **/
14331440$ . fn . steps . remove = function ( index )
14341441{
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 ) ;
14391443} ;
14401444
14411445/**
@@ -1774,6 +1778,16 @@ var defaults = $.fn.steps.defaults = {
17741778 **/
17751779 enableContentCache : true ,
17761780
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+
17771791 /**
17781792 * Shows the finish button if enabled.
17791793 *
@@ -1885,6 +1899,16 @@ var defaults = $.fn.steps.defaults = {
18851899 **/
18861900 onStepChanged : function ( event , currentIndex , priorIndex ) { } ,
18871901
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+
18881912 /**
18891913 * Fires before finishing and can be used to prevent completion by returning `false`.
18901914 * Very useful for form validation.
@@ -1914,6 +1938,16 @@ var defaults = $.fn.steps.defaults = {
19141938 * @for defaults
19151939 **/
19161940 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+
19171951 /**
19181952 * This label is important for accessability reasons.
19191953 * Indicates which step is activated.
0 commit comments