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