diff --git a/CREDITS.md b/CREDITS.md index 58d5db3..a9084ff 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -8,6 +8,7 @@ MrKooky - HTML5 markup, CSS cleanup Simon Rupf - MVC refactoring, configuration, i18n and unit tests Hexalyse - Password protection Viktor Stanchev - File upload support +azlux - Tab character input support Translations: Hexalyse - French diff --git a/js/zerobin.js b/js/zerobin.js index 70e0262..492e8a2 100644 --- a/js/zerobin.js +++ b/js/zerobin.js @@ -1073,7 +1073,7 @@ $(function() { }, /** - * Reload the page + * Reload the page. * * @param Event event */ @@ -1084,7 +1084,7 @@ $(function() { }, /** - * Return raw text + * Return raw text. * * @param Event event */ @@ -1120,6 +1120,30 @@ $(function() { $('.navbar-toggle').click(); }, + /** + * Support input of tab character. + * + * @param Event event + */ + supportTabs: function(event) + { + var keyCode = event.keyCode || event.which; + // tab was pressed + if (keyCode === 9) + { + // prevent the textarea to lose focus + event.preventDefault(); + // get caret position & selection + var val = this.value, + start = this.selectionStart, + end = this.selectionEnd; + // set textarea value to: text before caret + tab + text after caret + this.value = val.substring(0, start) + '\t' + val.substring(end); + // put caret at right position again + this.selectionStart = this.selectionEnd = start + 1; + } + }, + /** * Create a new paste. */ @@ -1203,6 +1227,7 @@ $(function() { this.rawTextButton.click($.proxy(this.rawText, this)); this.fileRemoveButton.click($.proxy(this.removeAttachment, this)); $('.reloadlink').click($.proxy(this.reloadPage, this)); + this.message.keydown(this.supportTabs); }, /**