2 * Vector-specific scripts
4 jQuery( function ( $ ) {
5 $( '#searchInput' ).attr( 'tabindex', $( document
).lastTabIndex() + 1 );
7 $( 'div.vectorMenu' ).each( function () {
9 $el
.find( '> h3 > a' ).parent()
10 .attr( 'tabindex', '0' )
11 // For accessibility, show the menu when the h3 is clicked (bug 24298/46486)
12 .on( 'click keypress', function ( e
) {
13 if ( e
.type
=== 'click' || e
.which
=== 13 ) {
14 $el
.toggleClass( 'menuForceShow' );
18 // When the heading has focus, also set a class that will change the arrow icon
20 $el
.find( '> a' ).addClass( 'vectorMenuFocus' );
23 $el
.find( '> a' ).removeClass( 'vectorMenuFocus' );
26 // As the h3 can already be focused there's no need for the link to be focusable
27 .attr( 'tabindex', '-1' );
33 $( '#mw-panel > .portal:first' ).addClass( 'first' );
36 * Collapsible tabs for Vector
38 var $cactions
= $( '#p-cactions' ),
39 $tabContainer
= $( '#p-views ul' ),
40 originalDropdownWidth
= $cactions
.width();
42 // Bind callback functions to animate our drop down menu in and out
43 // and then call the collapsibleTabs function on the menu
45 .bind( 'beforeTabCollapse', function () {
46 // If the dropdown was hidden, show it
47 if ( $cactions
.hasClass( 'emptyPortlet' ) ) {
49 .removeClass( 'emptyPortlet' )
51 .css( 'width', '1px' ).animate( { 'width': originalDropdownWidth
}, 'normal' );
54 .bind( 'beforeTabExpand', function () {
55 // If we're removing the last child node right now, hide the dropdown
56 if ( $cactions
.find( 'li' ).length
=== 1 ) {
57 $cactions
.find( 'h3' ).animate( { 'width': '1px' }, 'normal', function () {
58 $( this ).attr( 'style', '' )
59 .parent().addClass( 'emptyPortlet' );
64 expandCondition: function ( eleWidth
) {
65 // (This looks a bit awkward because we're doing expensive queries as late as possible.)
67 var distance
= $.collapsibleTabs
.calculateTabDistance();
68 // If there are at least eleWidth + 1 pixels of free space, expand.
69 // We add 1 because .width() will truncate fractional values but .offset() will not.
70 if ( distance
>= eleWidth
+ 1 ) {
73 // Maybe we can still expand? Account for the width of the "Actions" dropdown if the
74 // expansion would hide it.
75 if ( $cactions
.find( 'li' ).length
=== 1 ) {
76 return distance
>= eleWidth
+ 1 - originalDropdownWidth
;
82 collapseCondition: function () {
83 // (This looks a bit awkward because we're doing expensive queries as late as possible.)
84 // TODO The dropdown itself should probably "fold" to just the down-arrow (hiding the text)
85 // if it can't fit on the line?
87 // If there's an overlap, collapse.
88 if ( $.collapsibleTabs
.calculateTabDistance() < 0 ) {
89 // But only if the width of the tab to collapse is smaller than the width of the dropdown
90 // we would have to insert. An example language where this happens is Lithuanian (lt).
91 if ( $cactions
.hasClass( 'emptyPortlet' ) ) {
92 return $tabContainer
.children( 'li.collapsible:last' ).width() > originalDropdownWidth
;