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.
13 * @class jQuery.plugin.arrowSteps
17 * Show users their progress through a series of steps, via a row of items that fit
18 * 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();
37 $.fn
.arrowSteps = function () {
38 var $steps
, width
, arrowWidth
,
39 paddingSide
= $( 'body' ).hasClass( 'rtl' ) ? 'padding-left' : 'padding-right';
41 this.addClass( 'arrowSteps' );
42 $steps
= this.find( 'li' );
44 width
= parseInt( 100 / $steps
.length
, 10 );
45 $steps
.css( 'width', width
+ '%' );
47 // Every step except the last one has an arrow pointing forward:
48 // at the right hand side in LTR languages, and at the left hand side in RTL.
49 // Also add in the padding for the calculated arrow width.
50 arrowWidth
= parseInt( this.outerHeight(), 10 );
51 $steps
.filter( ':not(:last-child)' ).addClass( 'arrow' )
52 .find( 'div' ).css( paddingSide
, arrowWidth
.toString() + 'px' );
54 this.data( 'arrowSteps', $steps
);
59 * Highlights the element selected by the selector.
61 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#guard' );
62 * // 'Guard!' is highlighted.
64 * // ... user completes the 'guard' step ...
66 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#turn' );
67 * // 'Turn!' is highlighted.
69 * @param {string} selector
71 $.fn
.arrowStepsHighlight = function ( selector
) {
73 $steps
= this.data( 'arrowSteps' );
74 $.each( $steps
, function ( i
, step
) {
75 var $step
= $( step
);
76 if ( $step
.is( selector
) ) {
78 $previous
.addClass( 'tail' );
80 $step
.addClass( 'head' );
82 $step
.removeClass( 'head tail lasthead' );
90 * @mixins jQuery.plugin.arrowSteps