Localisation updates from http://translatewiki.net.
[mediawiki.git] / resources / jquery / jquery.arrowSteps.js
bloba1fd679d42f87659336d7b6f83d37e24505944d8
1 /**
2  * jQuery arrowSteps plugin
3  * Copyright Neil Kandalgaonkar, 2010
4  *
5  * This work is licensed under the terms of the GNU General Public License,
6  * version 2 or later.
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.
10  *
11  *
12  * DESCRIPTION
13  *
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.
16  *
17  *
18  * SYNOPSIS
19  *
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>
28  * </ul>
29  *
30  * <script>
31  *   $( '#robin-hood-daffy' ).arrowSteps();
32  *
33  *   $( '#robin-hood-daffy' ).arrowStepsHighlight( '#guard' );
34  *   // 'Guard!' is highlighted.
35  *
36  *   // ... user completes the 'guard' step ...
37  *
38  *   $( '#robin-hood-daffy' ).arrowStepsHighlight( '#turn' );
39  *   // 'Turn!' is highlighted.
40  * </script>
41  *
42  */
43 ( function ( $ ) {
44         $.fn.arrowSteps = function () {
45                 var $steps, width, arrowWidth,
46                         paddingSide = $( 'body' ).hasClass( 'rtl' ) ? 'padding-left' : 'padding-right';
48                 this.addClass( 'arrowSteps' );
49                 $steps = this.find( 'li' );
51                 width = parseInt( 100 / $steps.length, 10 );
52                 $steps.css( 'width', width + '%' );
54                 // Every step except the last one has an arrow pointing forward:
55                 // at the right hand side in LTR languages, and at the left hand side in RTL.
56                 // Also add in the padding for the calculated arrow width.
57                 arrowWidth = parseInt( this.outerHeight(), 10 );
58                 $steps.filter( ':not(:last-child)' ).addClass( 'arrow' )
59                       .find( 'div' ).css( paddingSide, arrowWidth.toString() + 'px' );
61                 this.data( 'arrowSteps', $steps );
62                 return this;
63         };
65         $.fn.arrowStepsHighlight = function ( selector ) {
66                 var $previous,
67                         $steps = this.data( 'arrowSteps' );
68                 $.each( $steps, function ( i, step ) {
69                         var $step = $( step );
70                         if ( $step.is( selector ) ) {
71                                 if ($previous) {
72                                         $previous.addClass( 'tail' );
73                                 }
74                                 $step.addClass( 'head' );
75                         } else {
76                                 $step.removeClass( 'head tail lasthead' );
77                         }
78                         $previous = $step;
79                 } );
80         };
82 }( jQuery ) );