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
, $stepDiv
,
40 paddingSide
= $( 'body' ).hasClass( 'rtl' ) ? 'padding-left' : 'padding-right';
42 $el
.addClass( 'arrowSteps' );
43 $steps
= $el
.find( 'li' );
45 width
= parseInt( 100 / $steps
.length
, 10 );
46 $steps
.css( 'width', width
+ '%' );
48 // Every step except the last one has an arrow pointing forward:
49 // at the right hand side in LTR languages, and at the left hand side in RTL.
50 // Also add in the padding for the calculated arrow width.
51 $stepDiv
= $steps
.filter( ':not(:last-child)' ).addClass( 'arrow' ).find( 'div' );
53 // Execute when complete page is fully loaded, including all frames, objects and images
54 $( window
).load( function () {
55 arrowWidth
= parseInt( $el
.outerHeight(), 10 );
56 $stepDiv
.css( paddingSide
, arrowWidth
.toString() + 'px' );
59 $el
.data( 'arrowSteps', $steps
);
65 * Highlights the element selected by the selector.
67 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#guard' );
68 * // 'Guard!' is highlighted.
70 * // ... user completes the 'guard' step ...
72 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#turn' );
73 * // 'Turn!' is highlighted.
75 * @param {string} selector
77 $.fn
.arrowStepsHighlight = function ( selector
) {
79 $steps
= this.data( 'arrowSteps' );
80 $.each( $steps
, function ( i
, step
) {
81 var $step
= $( step
);
82 if ( $step
.is( selector
) ) {
84 $previous
.addClass( 'tail' );
86 $step
.addClass( 'head' );
88 $step
.removeClass( 'head tail lasthead' );
96 * @mixins jQuery.plugin.arrowSteps