2014-08-07 11:38:34 +00:00
|
|
|
/**
|
|
|
|
* Vector-specific scripts
|
|
|
|
*/
|
|
|
|
jQuery( function ( $ ) {
|
2015-07-26 19:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Collapsible tabs
|
|
|
|
*/
|
|
|
|
var $cactions = $( '#p-cactions' ),
|
|
|
|
$tabContainer = $( '#p-views ul' ),
|
2016-08-26 03:56:34 +00:00
|
|
|
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 );
|
2015-07-26 19:17:11 +00:00
|
|
|
|
2014-08-07 11:38:34 +00:00
|
|
|
/**
|
|
|
|
* Focus search input at the very end
|
|
|
|
*/
|
|
|
|
$( '#searchInput' ).attr( 'tabindex', $( document ).lastTabIndex() + 1 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dropdown menu accessibility
|
|
|
|
*/
|
|
|
|
$( 'div.vectorMenu' ).each( function () {
|
|
|
|
var $el = $( this );
|
2017-07-04 15:51:10 +00:00
|
|
|
$el.find( '> h3 > span' ).parent()
|
2014-08-07 11:38:34 +00:00
|
|
|
.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();
|
|
|
|
}
|
2017-06-06 06:14:22 +00:00
|
|
|
} );
|
2014-08-07 11:38:34 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Bind callback functions to animate our drop down menu in and out
|
|
|
|
// and then call the collapsibleTabs function on the menu
|
|
|
|
$tabContainer
|
2016-11-22 02:08:39 +00:00
|
|
|
.on( 'beforeTabCollapse', function () {
|
2014-08-07 11:38:34 +00:00
|
|
|
// If the dropdown was hidden, show it
|
|
|
|
if ( $cactions.hasClass( 'emptyPortlet' ) ) {
|
2017-08-25 15:21:21 +00:00
|
|
|
$cactions.removeClass( 'emptyPortlet' );
|
|
|
|
$cactions.find( 'h3' )
|
|
|
|
.css( 'width', '1px' )
|
|
|
|
.animate( { width: initialCactionsWidth() }, 'normal' );
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|
|
|
|
} )
|
2016-11-22 02:08:39 +00:00
|
|
|
.on( 'beforeTabExpand', function () {
|
2014-08-07 11:38:34 +00:00
|
|
|
// If we're removing the last child node right now, hide the dropdown
|
|
|
|
if ( $cactions.find( 'li' ).length === 1 ) {
|
2015-02-14 20:44:54 +00:00
|
|
|
$cactions.find( 'h3' ).animate( { width: '1px' }, 'normal', function () {
|
2014-08-07 11:38:34 +00:00
|
|
|
$( this ).attr( 'style', '' )
|
|
|
|
.parent().addClass( 'emptyPortlet' );
|
2015-02-14 20:44:54 +00:00
|
|
|
} );
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
.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 ) {
|
2016-08-26 03:56:34 +00:00
|
|
|
return distance >= eleWidth + 1 - initialCactionsWidth();
|
2014-08-07 11:38:34 +00:00
|
|
|
} 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' ) ) {
|
2016-08-26 03:56:34 +00:00
|
|
|
return $tabContainer.children( 'li.collapsible:last' ).width() > initialCactionsWidth();
|
2014-08-07 11:38:34 +00:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|