function onMousedown( e ) {
	if ( isMiddleClickScrolling ) {
		return;
	}

	// watch for middle clicks only
	if ( e.button !== 1 ) {
		return;
	}

	let elem = e.target;

	// linux middle mouse shouldn't be overwritten (paste)
	if ( isLinux && ( elem.tagName === "INPUT" || elem.tagName === "TEXTAREA" ) ) {
		return;
	}

	do {
		if (
			// ignore anchors
			   elem.tagName === "A"
			// ignore "no-middleclick-scroll" data attributes
			|| elem.parentNode && elem.dataset.noMiddleclickScroll
		) {
			e.preventDefault();
			return;
		}
	} while ( ( elem = elem.parentNode ) );

	elem = overflowingAncestor( e.target );
	// only apply to scrollable regions
	if ( !elem || elem.clientHeight === elem.scrollHeight ) {
		return;
	}

	// we don't want the default by now
	e.preventDefault();

	// set up a new scrolling phase
	isMiddleClickScrolling = true;

	// reference point
	icon.style.left = `${e.clientX}px`;
	icon.style.top  = `${e.clientY}px`;
	document.body.appendChild( icon );

	const refereceX = e.clientX;
	const refereceY = e.clientY;

	let speedX = 0;
	let speedY = 0;

	// animation loop
	let last = window.performance.now();
	let finished = false;

	function step( now ) {
		const elapsed = now - last;
		elem.scrollLeft += ( speedX * elapsed ) >> 0;
		elem.scrollTop  += ( speedY * elapsed ) >> 0;
		last = now;
		if ( !finished ) {
			requestAnimationFrame( step );
		}
	}
	requestAnimationFrame( step );

	let first = true;

	function mousemove( e ) {
		const deltaX = Math.abs( refereceX - e.clientX );
		const deltaY = Math.abs( refereceY - e.clientY );
		const movedEnough = Math.max( deltaX, deltaY ) > 10;
		if ( first && movedEnough ) {
			window.addEventListener( "mouseup", remove, false );
			first = false;
		}
		speedX = ( e.clientX - refereceX ) * 10 / 1000;
		speedY = ( e.clientY - refereceY ) * 10 / 1000;
	}

	function remove() {
		window.removeEventListener( "mousemove", mousemove, false );
		window.removeEventListener( "mousedown", remove, false );
		window.removeEventListener( "mouseup", remove, false );
		window.removeEventListener( "keydown", remove, false );
		document.body.removeChild( icon );
		isMiddleClickScrolling = false;
		finished = true;
	}

	window.addEventListener( "mousemove", mousemove, false );
	window.addEventListener( "mousedown", remove, false );
	window.addEventListener( "keydown", remove, false );
}
Middle mouse button handler
@param {MouseEvent} e