all files / src/src/widgets/ TabOptionWidget.js

85.71% Statements 12/14
62.5% Branches 5/8
100% Functions 2/2
85.71% Lines 12/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                              556×   556× 68×           556×     556×                                                     64×   64×                                  
/**
 * TabOptionWidget is an item in a {@link OO.ui.TabSelectWidget TabSelectWidget}.
 *
 * Currently, this class is only used by {@link OO.ui.IndexLayout index layouts}, which contain
 * {@link OO.ui.TabPanelLayout tab panel layouts}. See {@link OO.ui.IndexLayout IndexLayout}
 * for an example.
 *
 * @class
 * @extends OO.ui.OptionWidget
 *
 * @constructor
 * @param {Object} [config] Configuration options
 * @cfg {string} [href] Hyperlink to add to TabOption. Mostly used in OOUI PHP.
 */
OO.ui.TabOptionWidget = function OoUiTabOptionWidget( config ) {
	// Configuration initialization
	config = config || {};
 
	if ( config.href ) {
		config = $.extend( {
			$label: $( '<a>' ).attr( 'href', config.href )
		}, config );
	}
 
	// Parent constructor
	OO.ui.TabOptionWidget.super.call( this, config );
 
	// Initialization
	this.$element
		.addClass( 'oo-ui-tabOptionWidget' )
		.attr( 'role', 'tab' );
};
 
/* Setup */
 
OO.inheritClass( OO.ui.TabOptionWidget, OO.ui.OptionWidget );
 
/* Static Properties */
 
/**
 * @static
 * @inheritdoc
 */
OO.ui.TabOptionWidget.static.highlightable = false;
 
/**
 * @static
 * @inheritdoc
 */
OO.ui.TabOptionWidget.static.scrollIntoViewOnSelect = true;
 
/**
 * Center tab horizontally after selecting on mobile
 *
 * @param {Object} [config] Configuration options
 * @return {jQuery.Promise} Promise which resolves when the scroll is complete
 */
OO.ui.TabOptionWidget.prototype.scrollElementIntoView = function ( config ) {
	var padding;
	Eif ( !OO.ui.isMobile() || !this.getElementGroup() ) {
		// Parent method
		return OO.ui.TabOptionWidget.super.prototype.scrollElementIntoView.call( this );
	} else {
		padding = Math.max( (
			this.getElementGroup().$element[ 0 ].clientWidth - this.$element[ 0 ].clientWidth
		) / 2, 0 );
		// Parent method
		return OO.ui.TabOptionWidget.super.prototype.scrollElementIntoView.call( this, $.extend(
			{
				padding: {
					left: padding,
					right: padding
				}
			},
			config
		) );
	}
};