From 87b41a0c3dc41370bc064198bfec607db388f758 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 15 Oct 2015 22:06:01 +0200 Subject: [PATCH] implemented tab input support from #40, thank you azlux! --- CREDITS.md | 1 + js/zerobin.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index 58d5db30..a9084ff2 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 70e0262f..492e8a2a 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); }, /**