User:Apheori/common.js
A fragment of the Garden of Remembering
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Tab thing like proper (yoinked from SO) */
jQuery( "textarea" ).keydown( function( e ) {
if( e.keyCode === 9 ) { // tab was pressed
// get caret position/selection
var start = this.selectionStart;
var end = this.selectionEnd;
var $this = jQuery( this );
var value = $this.val();
// set textarea value to: text before caret + tab + text after caret
$this.val( value.substring( 0, start )
+ "\t"
+ value.substring( end ) );
// put caret at right position again (add one for the tab)
this.selectionStart = this.selectionEnd = start + 1;
// prevent the focus lose
e.preventDefault();
}
} );