All files / mobile.editor.overlay blockMessageDrawer.js

21.73% Statements 5/23
0% Branches 0/4
25% Functions 1/4
21.73% Lines 5/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  1x 1x                                           1x 2x                                                                         2x    
const
	Drawer = require( '../mobile.startup/Drawer' ),
	BlockMessageDetails = require( './BlockMessageDetails' );
 
/**
 * @typedef {Object} BlockMessageOptions
 * @property {number} blockId representing the block
 * @property {boolean} partial is this a partial block?
 * @property {Object} creator
 * @property {string} creator.name of the blocker
 * @property {string} creator.url associated with the block
 * @property {string} reason for block
 * @property {string} [duration] of block e.g. "1 week"
 * @property {string} [expiry] of block, wrapped in parentheses
 *  e.g. "(1st September 2019)"
 */
 
/**
 * This creates the drawer at the bottom of the screen that appears when a
 * blocked user tries to edit.
 *
 * @param {BlockMessageOptions} props
 * @return {Drawer}
 */
module.exports = function blockMessageDrawer( props ) {
	const blockDrawer = new Drawer( {
		className: 'drawer block-message',
		onBeforeHide: function ( drawer ) {
			drawer.$el.remove();
		},
		onShow: function () {
			const $drawer = blockDrawer.$el.find( '.drawer.block-message' ),
				drawerTop = $drawer.offset().top - 100,
				creatorTop = blockDrawer.$el.find( '.block-message-creator' ).offset().top - 100,
				buttonsTop = blockDrawer.$el.find( '.block-message-buttons' ).offset().top - 100,
				$seeMore = blockDrawer.$el.find( '.block-message-see-more' ),
				wiki = mw.config.get( 'wgDBname' );
 
			$drawer.css( 'top', drawerTop + ( buttonsTop - creatorTop ) );
			$seeMore.on(
				'click',
				function () {
					const $container = blockDrawer.$el.find( '.block-message-container' );
					$drawer.css( 'top', 0 );
					$container.css( 'overflow-y', 'auto' );
					$container.css( 'height', buttonsTop - $container.offset().top );
					$seeMore.hide();
 
					if ( mw.config.get( 'wgMFTrackBlockNotices' ) ) {
						mw.track( 'counter.MediaWiki.BlockNotices.' + wiki + '.MobileFrontend.reasonShown', 1 );
					}
				}
			);
 
			if ( mw.config.get( 'wgMFTrackBlockNotices' ) ) {
				mw.track( 'counter.MediaWiki.BlockNotices.' + wiki + '.MobileFrontend.shown', 1 );
			}
		},
		children: [
			( new BlockMessageDetails( props ) ).$el
		]
	} );
	return blockDrawer;
};