2 * Vector-specific scripts
4 jQuery( function ( $ ) {
9 var $cactions
= $( '#p-cactions' ),
10 $tabContainer
= $( '#p-views ul' ),
11 rAF
= window
.requestAnimationFrame
|| setTimeout
,
12 // Avoid forced style calculation during page load
13 initialCactionsWidth = function () {
14 var width
= $cactions
.width();
15 initialCactionsWidth = function () {
21 rAF( initialCactionsWidth
);
24 * Focus search input at the very end
26 $( '#searchInput' ).attr( 'tabindex', $( document
).lastTabIndex() + 1 );
29 * Dropdown menu accessibility
31 $( 'div.vectorMenu' ).each( function () {
33 $el
.find( '> h3 > a' ).parent()
34 .attr( 'tabindex', '0' )
35 // For accessibility, show the menu when the h3 is clicked (bug 24298/46486)
36 .on( 'click keypress', function ( e
) {
37 if ( e
.type
=== 'click' || e
.which
=== 13 ) {
38 $el
.toggleClass( 'menuForceShow' );
42 // When the heading has focus, also set a class that will change the arrow icon
44 $el
.find( '> a' ).addClass( 'vectorMenuFocus' );
47 $el
.find( '> a' ).removeClass( 'vectorMenuFocus' );
50 // As the h3 can already be focused there's no need for the link to be focusable
51 .attr( 'tabindex', '-1' );
54 // Bind callback functions to animate our drop down menu in and out
55 // and then call the collapsibleTabs function on the menu
57 .bind( 'beforeTabCollapse', function () {
58 // If the dropdown was hidden, show it
59 if ( $cactions
.hasClass( 'emptyPortlet' ) ) {
61 .removeClass( 'emptyPortlet' )
63 .css( 'width', '1px' ).animate( { width
: initialCactionsWidth() }, 'normal' );
66 .bind( 'beforeTabExpand', function () {
67 // If we're removing the last child node right now, hide the dropdown
68 if ( $cactions
.find( 'li' ).length
=== 1 ) {
69 $cactions
.find( 'h3' ).animate( { width
: '1px' }, 'normal', function () {
70 $( this ).attr( 'style', '' )
71 .parent().addClass( 'emptyPortlet' );
76 expandCondition: function ( eleWidth
) {
77 // (This looks a bit awkward because we're doing expensive queries as late as possible.)
79 var distance
= $.collapsibleTabs
.calculateTabDistance();
80 // If there are at least eleWidth + 1 pixels of free space, expand.
81 // We add 1 because .width() will truncate fractional values but .offset() will not.
82 if ( distance
>= eleWidth
+ 1 ) {
85 // Maybe we can still expand? Account for the width of the "Actions" dropdown if the
86 // expansion would hide it.
87 if ( $cactions
.find( 'li' ).length
=== 1 ) {
88 return distance
>= eleWidth
+ 1 - initialCactionsWidth();
94 collapseCondition: function () {
95 // (This looks a bit awkward because we're doing expensive queries as late as possible.)
96 // TODO The dropdown itself should probably "fold" to just the down-arrow (hiding the text)
97 // if it can't fit on the line?
99 // If there's an overlap, collapse.
100 if ( $.collapsibleTabs
.calculateTabDistance() < 0 ) {
101 // But only if the width of the tab to collapse is smaller than the width of the dropdown
102 // we would have to insert. An example language where this happens is Lithuanian (lt).
103 if ( $cactions
.hasClass( 'emptyPortlet' ) ) {
104 return $tabContainer
.children( 'li.collapsible:last' ).width() > initialCactionsWidth();