mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-05 14:22:56 +00:00
3c542f3078
The .vectorMenuFocus class was being added on the wrong element, so the styles for it never kicked in. I think this has been broken since 4fabc910d2e1bb4581ac7a80f019bd22758d089b (August 2013), which is understandable since the style change is near impossible to notice (the little triangle arrow turns a slightly lighter shade of grey). Change-Id: I0f7881afde9e01061aacf009033255774d0acd8d
111 lines
3.5 KiB
JavaScript
111 lines
3.5 KiB
JavaScript
/**
|
|
* Vector-specific scripts
|
|
*/
|
|
jQuery( function ( $ ) {
|
|
|
|
/**
|
|
* Collapsible tabs
|
|
*/
|
|
var $cactions = $( '#p-cactions' ),
|
|
$tabContainer = $( '#p-views ul' ),
|
|
rAF = window.requestAnimationFrame || setTimeout,
|
|
// Avoid forced style calculation during page load
|
|
initialCactionsWidth = function () {
|
|
var width = $cactions.width();
|
|
initialCactionsWidth = function () {
|
|
return width;
|
|
};
|
|
return width;
|
|
};
|
|
|
|
rAF( initialCactionsWidth );
|
|
|
|
/**
|
|
* Focus search input at the very end
|
|
*/
|
|
$( '#searchInput' ).attr( 'tabindex', $( document ).lastTabIndex() + 1 );
|
|
|
|
/**
|
|
* Dropdown menu accessibility
|
|
*/
|
|
$( 'div.vectorMenu' ).each( function () {
|
|
var $el = $( this );
|
|
$el.find( '> h3 > span' ).parent()
|
|
.attr( 'tabindex', '0' )
|
|
// For accessibility, show the menu when the h3 is clicked (bug 24298/46486)
|
|
.on( 'click keypress', function ( e ) {
|
|
if ( e.type === 'click' || e.which === 13 ) {
|
|
$el.toggleClass( 'menuForceShow' );
|
|
e.preventDefault();
|
|
}
|
|
} )
|
|
// When the heading has focus, also set a class that will change the arrow icon
|
|
.focus( function () {
|
|
$el.addClass( 'vectorMenuFocus' );
|
|
} )
|
|
.blur( function () {
|
|
$el.removeClass( 'vectorMenuFocus' );
|
|
} );
|
|
} );
|
|
|
|
// Bind callback functions to animate our drop down menu in and out
|
|
// and then call the collapsibleTabs function on the menu
|
|
$tabContainer
|
|
.on( 'beforeTabCollapse', function () {
|
|
// If the dropdown was hidden, show it
|
|
if ( $cactions.hasClass( 'emptyPortlet' ) ) {
|
|
$cactions.removeClass( 'emptyPortlet' );
|
|
$cactions.find( 'h3' )
|
|
.css( 'width', '1px' )
|
|
.animate( { width: initialCactionsWidth() }, 'normal' );
|
|
}
|
|
} )
|
|
.on( 'beforeTabExpand', function () {
|
|
// If we're removing the last child node right now, hide the dropdown
|
|
if ( $cactions.find( 'li' ).length === 1 ) {
|
|
$cactions.find( 'h3' ).animate( { width: '1px' }, 'normal', function () {
|
|
$( this ).attr( 'style', '' )
|
|
.parent().addClass( 'emptyPortlet' );
|
|
} );
|
|
}
|
|
} )
|
|
.collapsibleTabs( {
|
|
expandCondition: function ( eleWidth ) {
|
|
// (This looks a bit awkward because we're doing expensive queries as late as possible.)
|
|
|
|
var distance = $.collapsibleTabs.calculateTabDistance();
|
|
// If there are at least eleWidth + 1 pixels of free space, expand.
|
|
// We add 1 because .width() will truncate fractional values but .offset() will not.
|
|
if ( distance >= eleWidth + 1 ) {
|
|
return true;
|
|
} else {
|
|
// Maybe we can still expand? Account for the width of the "Actions" dropdown if the
|
|
// expansion would hide it.
|
|
if ( $cactions.find( 'li' ).length === 1 ) {
|
|
return distance >= eleWidth + 1 - initialCactionsWidth();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
},
|
|
collapseCondition: function () {
|
|
// (This looks a bit awkward because we're doing expensive queries as late as possible.)
|
|
// TODO The dropdown itself should probably "fold" to just the down-arrow (hiding the text)
|
|
// if it can't fit on the line?
|
|
|
|
// If there's an overlap, collapse.
|
|
if ( $.collapsibleTabs.calculateTabDistance() < 0 ) {
|
|
// But only if the width of the tab to collapse is smaller than the width of the dropdown
|
|
// we would have to insert. An example language where this happens is Lithuanian (lt).
|
|
if ( $cactions.hasClass( 'emptyPortlet' ) ) {
|
|
return $tabContainer.children( 'li.collapsible:last' ).width() > initialCactionsWidth();
|
|
} else {
|
|
return true;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
} );
|
|
} );
|