When I edit a chunkor a snippet, I’d like to use the tab key to make soft indentation.
I have found a solution from
a site of Greg Taff.
For chunks (to adapt for snippets) :
<textarea id="htmlta" name="post" style="width:100%; height: 370px;" onChange='documentDirty=true;'><?php echo htmlspecialchars($content['snippet']); ?></textarea>
</div>
<!-- HTML text editor end -->
<input type="submit" name="save" style="display:none">
</div>
<script>
function insert(input, theText) {
if(typeof input.selectionStart != 'undefined')
{
var start = input.selectionStart;
var end = input.selectionEnd;
input.value = input.value.substr(0, start) + theText + input.value.substr(end);
input.selectionStart = start + theText.length;
input.selectionEnd = start + theText.length;
input.focus();
}
}
function keyDownHandler(e){
/* enable the tab key for the text areas */
if(e.keyCode == 9){
var cacheScrollTop = e.target.scrollTop;
setTimeout("insert($('"+e.target.id+"'), unescape('%09'));", 0);
setTimeout("$('"+e.target.id+"').scrollTop = " + cacheScrollTop, 10);
return false;
}
}
$("htmlta").onkeydown=keyDownHandler;
</script>
Note the attribute "id" for the textarea, and that this code makes use of prototype.js