Merge "Update set of files cleaned up after parserTests"
[lhc/web/wiklou.git] / resources / jquery / jquery.arrowSteps.js
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 /**
13 * @class jQuery.plugin.arrowSteps
14 */
15 ( function ( $ ) {
16 /**
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.
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 * </script>
33 *
34 * @chainable
35 */
36 $.fn.arrowSteps = function () {
37 var $steps, width, arrowWidth,
38 paddingSide = $( 'body' ).hasClass( 'rtl' ) ? 'padding-left' : 'padding-right';
39
40 this.addClass( 'arrowSteps' );
41 $steps = this.find( 'li' );
42
43 width = parseInt( 100 / $steps.length, 10 );
44 $steps.css( 'width', width + '%' );
45
46 // Every step except the last one has an arrow pointing forward:
47 // at the right hand side in LTR languages, and at the left hand side in RTL.
48 // Also add in the padding for the calculated arrow width.
49 arrowWidth = parseInt( this.outerHeight(), 10 );
50 $steps.filter( ':not(:last-child)' ).addClass( 'arrow' )
51 .find( 'div' ).css( paddingSide, arrowWidth.toString() + 'px' );
52
53 this.data( 'arrowSteps', $steps );
54 return this;
55 };
56
57 /**
58 * Highlights the element selected by the selector.
59 *
60 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#guard' );
61 * // 'Guard!' is highlighted.
62 *
63 * // ... user completes the 'guard' step ...
64 *
65 * $( '#robin-hood-daffy' ).arrowStepsHighlight( '#turn' );
66 * // 'Turn!' is highlighted.
67 *
68 * @param {string} selector
69 */
70 $.fn.arrowStepsHighlight = function ( selector ) {
71 var $previous,
72 $steps = this.data( 'arrowSteps' );
73 $.each( $steps, function ( i, step ) {
74 var $step = $( step );
75 if ( $step.is( selector ) ) {
76 if ($previous) {
77 $previous.addClass( 'tail' );
78 }
79 $step.addClass( 'head' );
80 } else {
81 $step.removeClass( 'head tail lasthead' );
82 }
83 $previous = $step;
84 } );
85 };
86
87 /**
88 * @class jQuery
89 * @mixins jQuery.plugin.arrowSteps
90 */
91 }( jQuery ) );