Last active
December 31, 2015 04:39
-
-
Save TerryMooreII/7935223 to your computer and use it in GitHub Desktop.
Add Tab support within a text area. In particular Metlifes Synapse site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Added tab support to Metlife Synapse json resume builder site | |
$('#json_textarea').on('keydown', function(event){ | |
$this = $(this); | |
var TAB_SPACES = 2; | |
var getSpaces = function(){ | |
var space=''; | |
for(var i=0; i<TAB_SPACES; i++){ | |
space += ' '; | |
} | |
return space; | |
} | |
if (event.keyCode === 9){ | |
event.preventDefault(); | |
var start = $this.get(0).selectionStart | |
, end = $this.get(0).selectionEnd | |
, isShiftTab = false | |
, beginText = $this.val().substring(0, start) | |
, endText = $this.val().substring(end) | |
, spaces = getSpaces(); | |
if (event.shiftKey === true && beginText.substr(beginText.length - TAB_SPACES) === spaces) { | |
beginText = $this.val().substring(0, start - TAB_SPACES); | |
isShiftTab = true; | |
} | |
else{ | |
beginText += spaces; | |
} | |
$this.val(beginText + endText); | |
$this.get(0).selectionStart = | |
$this.get(0).selectionEnd = start + (isShiftTab ? -TAB_SPACES : TAB_SPACES); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment