2014-08-07 11:38:34 +00:00
|
|
|
/**
|
|
|
|
* Vector-specific scripts
|
|
|
|
*/
|
2019-03-13 23:00:40 +00:00
|
|
|
/* eslint-disable no-jquery/no-global-selector */
|
2018-11-16 15:35:52 +00:00
|
|
|
$( 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
|
|
|
// Avoid forced style calculation during page load
|
|
|
|
initialCactionsWidth = function () {
|
|
|
|
var width = $cactions.width();
|
|
|
|
initialCactionsWidth = function () {
|
|
|
|
return width;
|
|
|
|
};
|
|
|
|
return width;
|
|
|
|
};
|
|
|
|
|
2019-09-11 01:18:04 +00:00
|
|
|
mw.requestIdleCallback( initialCactionsWidth );
|
2015-07-26 19:17:11 +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' );
|
2019-03-13 23:00:40 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-animate
|
2017-08-25 15:21:21 +00:00
|
|
|
$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 ) {
|
2019-03-13 23:00:40 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-animate
|
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 ) {
|
2018-09-09 17:05:47 +00:00
|
|
|
// This looks a bit awkward because we're doing expensive queries as late
|
|
|
|
// as possible.
|
2014-08-07 11:38:34 +00:00
|
|
|
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 {
|
2018-09-09 17:05:47 +00:00
|
|
|
// Maybe we can still expand? Account for the width of the "Actions" dropdown
|
|
|
|
// if the expansion would hide it.
|
2014-08-07 11:38:34 +00:00
|
|
|
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;
|
|
|
|
|
2018-09-09 17:05:47 +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?
|
2014-08-07 11:38:34 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|