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 () {
|
2017-11-30 17:22:19 +00:00
|
|
|
var collapsibleWidth = 0;
|
|
|
|
|
2014-08-07 11:38:34 +00:00
|
|
|
// (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?
|
|
|
|
|
2017-11-30 17:22:19 +00:00
|
|
|
// Never collapse if there is no overlap.
|
|
|
|
if ( $.collapsibleTabs.calculateTabDistance() >= 0 ) {
|
2014-08-07 11:38:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-30 17:22:19 +00:00
|
|
|
|
|
|
|
// Always collapse if the "More" button is already shown.
|
|
|
|
if ( !$cactions.hasClass( 'emptyPortlet' ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tabContainer.children( 'li.collapsible' ).each( function ( index, element ) {
|
|
|
|
collapsibleWidth += $( element ).width();
|
|
|
|
// Stop this possibly expensive loop the moment the condition is met.
|
|
|
|
return !( collapsibleWidth > initialCactionsWidth() );
|
|
|
|
} );
|
|
|
|
return collapsibleWidth > initialCactionsWidth();
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|