Jump to content

User:Fred Gandt/allowTabs.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Fred Gandt (talk | contribs) at 02:24, 15 November 2021 (arrow functions and template strings). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$( document ).ready( () => {
	"use strict";
	const TB1 = document.getElementById( "wpTextbox1" );
	if ( TB1 && !TB1.nextElementSibling ) {
		TB1.addEventListener( "keydown", evt => {
			if ( evt.key === "Tab" ) {
				const SS = TB1.selectionStart;
				evt.preventDefault();
				TB1.value = `${TB1.value.substr( 0, SS )}	${TB1.value.substr( TB1.selectionEnd )}`;	
				TB1.setSelectionRange( SS + 1, SS + 1 );
			}
		} );
	}
} );