<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="nl">
	<id>https://informatiestandaarden.test-nictiz.nl/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-TabOverride.js</id>
	<title>MediaWiki:Gadget-TabOverride.js - Bewerkingsoverzicht</title>
	<link rel="self" type="application/atom+xml" href="https://informatiestandaarden.test-nictiz.nl/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-TabOverride.js"/>
	<link rel="alternate" type="text/html" href="https://informatiestandaarden.test-nictiz.nl/index.php?title=MediaWiki:Gadget-TabOverride.js&amp;action=history"/>
	<updated>2026-04-23T20:21:51Z</updated>
	<subtitle>Bewerkingsoverzicht voor deze pagina op de wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://informatiestandaarden.test-nictiz.nl/index.php?title=MediaWiki:Gadget-TabOverride.js&amp;diff=3238&amp;oldid=prev</id>
		<title>Ahenket: Nieuwe pagina aangemaakt met &#039;/**  * @fileOverview The JavaScript component of the Tab Override MediaWiki extension  * @author Bill Bryant  * @version 2.0.1-MediaWiki  * @note Rewritten by Jack ...&#039;</title>
		<link rel="alternate" type="text/html" href="https://informatiestandaarden.test-nictiz.nl/index.php?title=MediaWiki:Gadget-TabOverride.js&amp;diff=3238&amp;oldid=prev"/>
		<updated>2013-07-19T18:13:32Z</updated>

		<summary type="html">&lt;p&gt;Nieuwe pagina aangemaakt met &amp;#039;/**  * @fileOverview The JavaScript component of the Tab Override MediaWiki extension  * @author Bill Bryant  * @version 2.0.1-MediaWiki  * @note Rewritten by Jack ...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nieuwe pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * @fileOverview The JavaScript component of the Tab Override MediaWiki extension&lt;br /&gt;
 * @author Bill Bryant&lt;br /&gt;
 * @version 2.0.1-MediaWiki&lt;br /&gt;
 * @note Rewritten by Jack Phoenix to work without legacy JS globals&lt;br /&gt;
 * @url http://tinsology.net/plugins/tab-override/ Original source code etc.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// register the keydown event listener on the content textarea element&lt;br /&gt;
// after the window is loaded to make sure that the element is accessible&lt;br /&gt;
// using the document&amp;#039;s getElementById method&lt;br /&gt;
jQuery( document ).ready( function() {&lt;br /&gt;
    // only on edit pages (action=edit in the URL)&lt;br /&gt;
	// action=submit is preview mode (the &amp;quot;Show preview&amp;quot; button has been pressed)&lt;br /&gt;
	if (&lt;br /&gt;
		mw.config.get( &amp;#039;wgAction&amp;#039; ) !== &amp;#039;edit&amp;#039; ||&lt;br /&gt;
		mw.config.get( &amp;#039;wgAction&amp;#039; ) !== &amp;#039;submit&amp;#039;&lt;br /&gt;
	)&lt;br /&gt;
	{&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	var content = jQuery( &amp;#039;#wpTextbox1&amp;#039; ); // the MediaWiki page edit textarea&lt;br /&gt;
&lt;br /&gt;
	// if there is no content textarea element on this page, do nothing&lt;br /&gt;
	if ( !content.length ) {&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	content.keydown( function( e ) {&lt;br /&gt;
		var text, // initial text in the textarea&lt;br /&gt;
			range, // the IE TextRange object&lt;br /&gt;
			tempRange, // used to calculate selection start and end positions in IE&lt;br /&gt;
			preNewlines, // the number of newline (\r\n) characters before the selection start (for IE)&lt;br /&gt;
			selNewlines, // the number of newline (\r\n) characters within the selection (for IE)&lt;br /&gt;
			initScrollTop, // initial scrollTop value to fix scrolling in Firefox&lt;br /&gt;
			selStart, // the selection start position&lt;br /&gt;
			selEnd, // the selection end position&lt;br /&gt;
			sel, // the selected text&lt;br /&gt;
			startLine, // for multi-line selections, the first character position of the first line&lt;br /&gt;
			endLine, // for multi-line selections, the last character position of the last line&lt;br /&gt;
			numTabs, // the number of tabs inserted / removed in the selection&lt;br /&gt;
			startTab, // if a tab was removed from the start of the first line&lt;br /&gt;
			preTab; // if a tab was removed before the start of the selection&lt;br /&gt;
&lt;br /&gt;
		// tab key - insert / remove tab&lt;br /&gt;
		if ( e.keyCode === 9 ) {&lt;br /&gt;
			// initialize variables&lt;br /&gt;
			text = this.value;&lt;br /&gt;
			initScrollTop = this.scrollTop; // scrollTop is supported by all modern browsers&lt;br /&gt;
			numTabs = 0;&lt;br /&gt;
			startTab = 0;&lt;br /&gt;
			preTab = 0;&lt;br /&gt;
&lt;br /&gt;
			if ( typeof this.selectionStart !== &amp;#039;undefined&amp;#039; ) {&lt;br /&gt;
				selStart = this.selectionStart;&lt;br /&gt;
				selEnd = this.selectionEnd;&lt;br /&gt;
				sel = text.slice( selStart, selEnd );&lt;br /&gt;
			} else if ( document.selection ) { // IE&lt;br /&gt;
				range = document.selection.createRange();&lt;br /&gt;
				sel = range.text;&lt;br /&gt;
				tempRange = range.duplicate();&lt;br /&gt;
				tempRange.moveToElementText( this );&lt;br /&gt;
				tempRange.setEndPoint( &amp;#039;EndToEnd&amp;#039;, range );&lt;br /&gt;
				selEnd = tempRange.text.length;&lt;br /&gt;
				selStart = selEnd - sel.length;&lt;br /&gt;
				// whenever the value of the textarea is changed, the range needs to be reset&lt;br /&gt;
				// IE (and Opera) use both \r and \n for newlines - this adds an extra character&lt;br /&gt;
				// that needs to be accounted for when doing position calculations&lt;br /&gt;
				// these values are used to offset the selection start and end positions&lt;br /&gt;
				preNewlines = text.slice( 0, selStart ).split( &amp;#039;\r\n&amp;#039; ).length - 1;&lt;br /&gt;
				selNewlines = sel.split( &amp;#039;\r\n&amp;#039; ).length - 1;&lt;br /&gt;
			} else {&lt;br /&gt;
				// cannot access textarea selection - do nothing&lt;br /&gt;
				return;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			// special case of multi-line selection&lt;br /&gt;
			if ( selStart !== selEnd &amp;amp;&amp;amp; sel.indexOf( &amp;#039;\n&amp;#039; ) !== -1 ) {&lt;br /&gt;
				// for multiple lines, only insert / remove tabs from the beginning of each line&lt;br /&gt;
&lt;br /&gt;
				// find the start of the first selected line&lt;br /&gt;
				if ( selStart === 0 || text.charAt( selStart - 1 ) === &amp;#039;\n&amp;#039; ) {&lt;br /&gt;
					// the selection starts at the beginning of a line&lt;br /&gt;
					startLine = selStart;&lt;br /&gt;
				} else {&lt;br /&gt;
					// the selection starts after the beginning of a line&lt;br /&gt;
					// set startLine to the beginning of the first partially selected line&lt;br /&gt;
					// subtract 1 from selStart in case the cursor is at the newline character,&lt;br /&gt;
					// for instance, if the very end of the previous line was selected&lt;br /&gt;
					// add 1 to get the next character after the newline&lt;br /&gt;
					// if there is none before the selection, lastIndexOf returns -1&lt;br /&gt;
					// when 1 is added to that it becomes 0 and the first character is used&lt;br /&gt;
					startLine = text.lastIndexOf( &amp;#039;\n&amp;#039;, selStart - 1 ) + 1;&lt;br /&gt;
				}&lt;br /&gt;
&lt;br /&gt;
				// find the end of the last selected line&lt;br /&gt;
				if ( selEnd === text.length || text.charAt( selEnd ) === &amp;#039;\n&amp;#039; ) {&lt;br /&gt;
					// the selection ends at the end of a line&lt;br /&gt;
					endLine = selEnd;&lt;br /&gt;
				} else {&lt;br /&gt;
					// the selection ends before the end of a line&lt;br /&gt;
					// set endLine to the end of the last partially selected line&lt;br /&gt;
					endLine = text.indexOf( &amp;#039;\n&amp;#039;, selEnd );&lt;br /&gt;
					if ( endLine === -1 ) {&lt;br /&gt;
						endLine = text.length;&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
&lt;br /&gt;
				// if the shift key was pressed, remove tabs instead of inserting them&lt;br /&gt;
				if ( e.shiftKey ) {&lt;br /&gt;
					if ( text.charAt( startLine ) === &amp;#039;\t&amp;#039; ) {&lt;br /&gt;
						// is this tab part of the selection?&lt;br /&gt;
						if ( startLine === selStart ) {&lt;br /&gt;
							// it is, remove it&lt;br /&gt;
							sel = sel.slice( 1 );&lt;br /&gt;
						} else {&lt;br /&gt;
							// the tab comes before the selection&lt;br /&gt;
							preTab = 1;&lt;br /&gt;
						}&lt;br /&gt;
						startTab = 1;&lt;br /&gt;
					}&lt;br /&gt;
&lt;br /&gt;
					this.value = text.slice( 0, startLine ) + text.slice( startLine + preTab, selStart ) +&lt;br /&gt;
						sel.replace( /\n\t/g, function() {&lt;br /&gt;
							numTabs += 1;&lt;br /&gt;
							return &amp;#039;\n&amp;#039;;&lt;br /&gt;
						}) + text.slice( selEnd );&lt;br /&gt;
&lt;br /&gt;
					// set start and end points&lt;br /&gt;
					if ( range ) { // IE&lt;br /&gt;
						// setting end first makes calculations easier&lt;br /&gt;
						range.collapse();&lt;br /&gt;
						range.moveEnd( &amp;#039;character&amp;#039;, selEnd - startTab - numTabs - selNewlines - preNewlines );&lt;br /&gt;
						range.moveStart( &amp;#039;character&amp;#039;, selStart - preTab - preNewlines );&lt;br /&gt;
						range.select();&lt;br /&gt;
					} else {&lt;br /&gt;
						// set start first for Opera&lt;br /&gt;
						this.selectionStart = selStart - preTab; // preTab is 0 or 1&lt;br /&gt;
						// move the selection end over by the total number of tabs removed&lt;br /&gt;
						this.selectionEnd = selEnd - startTab - numTabs;&lt;br /&gt;
					}&lt;br /&gt;
				} else {&lt;br /&gt;
					// no shift key&lt;br /&gt;
					// insert tabs at the beginning of each line of the selection&lt;br /&gt;
					this.value = text.slice( 0, startLine ) + &amp;#039;\t&amp;#039; + text.slice( startLine, selStart ) +&lt;br /&gt;
						sel.replace( /\n/g, function() {&lt;br /&gt;
							numTabs += 1;&lt;br /&gt;
							return &amp;#039;\n\t&amp;#039;;&lt;br /&gt;
						}) + text.slice( selEnd );&lt;br /&gt;
&lt;br /&gt;
					// set start and end points&lt;br /&gt;
					if ( range ) { // IE&lt;br /&gt;
						range.collapse();&lt;br /&gt;
						range.moveEnd( &amp;#039;character&amp;#039;, selEnd + 1 - preNewlines ); // numTabs cancels out selNewlines&lt;br /&gt;
						range.moveStart( &amp;#039;character&amp;#039;, selStart + 1 - preNewlines );&lt;br /&gt;
						range.select();&lt;br /&gt;
					} else {&lt;br /&gt;
						// the selection start is always moved by 1 character&lt;br /&gt;
						this.selectionStart = selStart + 1;&lt;br /&gt;
						// move the selection end over by the total number of tabs inserted&lt;br /&gt;
						this.selectionEnd = selEnd + 1 + numTabs;&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
			} else {&lt;br /&gt;
				// &amp;quot;normal&amp;quot; case (no selection or selection on one line only)&lt;br /&gt;
&lt;br /&gt;
				// if the shift key was pressed, remove a tab instead of inserting one&lt;br /&gt;
				if ( e.shiftKey ) {&lt;br /&gt;
					// if the character before the selection is a tab, remove it&lt;br /&gt;
					if ( text.charAt( selStart - 1 ) === &amp;#039;\t&amp;#039; ) {&lt;br /&gt;
						this.value = text.slice( 0, selStart - 1 ) + text.slice( selStart );&lt;br /&gt;
&lt;br /&gt;
						// set start and end points&lt;br /&gt;
						if ( range ) { // IE&lt;br /&gt;
							// collapses range and moves it by -1 character&lt;br /&gt;
							range.move( &amp;#039;character&amp;#039;, selStart - 1 - preNewlines );&lt;br /&gt;
							range.select();&lt;br /&gt;
						} else {&lt;br /&gt;
							this.selectionEnd = this.selectionStart = selStart - 1;&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
				} else {&lt;br /&gt;
					// no shift key - insert a tab&lt;br /&gt;
					if ( range ) { // IE&lt;br /&gt;
						// if no text is selected and the cursor is at the beginning of a line&lt;br /&gt;
						// (except the first line), IE places the cursor at the carriage return character&lt;br /&gt;
						// the tab must be placed after the \r\n pair&lt;br /&gt;
						if ( text.charAt( selStart ) === &amp;#039;\r&amp;#039; ) {&lt;br /&gt;
							this.value = text.slice( 0, selStart + 2 ) + &amp;#039;\t&amp;#039; + text.slice( selEnd + 2 );&lt;br /&gt;
							// collapse the range and move it to the appropriate location&lt;br /&gt;
							range.move( &amp;#039;character&amp;#039;, selStart + 2 - preNewlines );&lt;br /&gt;
						} else {&lt;br /&gt;
							this.value = text.slice( 0, selStart ) + &amp;#039;\t&amp;#039; + text.slice( selEnd );&lt;br /&gt;
							// collapse the range and move it to the appropriate location&lt;br /&gt;
							range.move( &amp;#039;character&amp;#039;, selStart + 1 - preNewlines );&lt;br /&gt;
						}&lt;br /&gt;
						range.select();&lt;br /&gt;
					} else {&lt;br /&gt;
						this.value = text.slice( 0, selStart ) + &amp;#039;\t&amp;#039; + text.slice( selEnd );&lt;br /&gt;
						this.selectionEnd = this.selectionStart = selStart + 1;&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			// this is really just for Firefox, but will be executed by all browsers&lt;br /&gt;
			// whenever the textarea value property is reset, Firefox scrolls back to the top&lt;br /&gt;
			// this will reset it to the original scroll value&lt;br /&gt;
			this.scrollTop = initScrollTop;&lt;br /&gt;
&lt;br /&gt;
			// prevent the default action&lt;br /&gt;
			if ( e.preventDefault ) {&lt;br /&gt;
				e.preventDefault();&lt;br /&gt;
			}&lt;br /&gt;
			e.returnValue = false;&lt;br /&gt;
		}&lt;br /&gt;
	} ).keypress( function( e ) {&lt;br /&gt;
		// Opera (and Firefox) also fire a keypress event when the tab key is pressed&lt;br /&gt;
		// Opera requires that the default action be prevented on this event, or the&lt;br /&gt;
		// textarea will lose focus (preventDefault is enough, IE never fires this&lt;br /&gt;
		// for the tab key)&lt;br /&gt;
		if ( e.keyCode === 9 &amp;amp;&amp;amp; e.preventDefault ) {&lt;br /&gt;
			e.preventDefault();&lt;br /&gt;
		}&lt;br /&gt;
	} );&lt;br /&gt;
} );&lt;/div&gt;</summary>
		<author><name>Ahenket</name></author>
	</entry>
</feed>