2 * jQuery arrowSteps plugin
3 * Copyright Neil Kandalgaonkar, 2010
5 * This work is licensed under the terms of the GNU General Public License,
7 * (see http://www.fsf.org/licensing/licenses/gpl.html).
8 * Derivative works and later versions of the code must be free software
9 * licensed under the same or a compatible license.
14 * Show users their progress through a series of steps, via a row of items that fit
15 * together like arrows. One item can be highlighted at a time.
20 * <ul id="robin-hood-daffy">
21 * <li id="guard"><div>Guard!</div></li>
22 * <li id="turn"><div>Turn!</div></li>
23 * <li id="parry"><div>Parry!</div></li>
24 * <li id="dodge"><div>Dodge!</div></li>
25 * <li id="spin"><div>Spin!</div></li>
26 * <li id="ha"><div>Ha!</div></li>
27 * <li id="thrust"><div>Thrust!</div></li>
31 * $( '#robin-hood-daffy' ).arrowSteps();
33 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#guard' );
34 * // 'Guard!' is highlighted.
36 * // ... user completes the 'guard' step ...
38 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#turn' );
39 * // 'Turn!' is highlighted.
45 $.fn
.arrowSteps = function () {
46 this.addClass( 'arrowSteps' );
47 var $steps
= this.find( 'li' );
49 var width
= parseInt( 100 / $steps
.length
, 10 );
50 $steps
.css( 'width', width
+ '%' );
52 // every step except the last one has an arrow at the right hand side. Also add in the padding
53 // for the calculated arrow width.
54 var arrowWidth
= parseInt( this.outerHeight(), 10 );
55 $steps
.filter( ':not(:last-child)' ).addClass( 'arrow' )
56 .find( 'div' ).css( 'padding-right', arrowWidth
.toString() + 'px' );
58 this.data( 'arrowSteps', $steps
);
62 $.fn
.arrowStepsHighlight = function ( selector
) {
63 var $steps
= this.data( 'arrowSteps' );
65 $.each( $steps
, function ( i
, step
) {
66 var $step
= $( step
);
67 if ( $step
.is( selector
) ) {
69 $previous
.addClass( 'tail' );
71 $step
.addClass( 'head' );
73 $step
.removeClass( 'head tail lasthead' );