From ae29c38f19ef0875447057084f5874ab8679aaa2 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 7 Sep 2015 13:06:07 -0700 Subject: [PATCH] Maintain cursor position while cleaning up the folder name value (fixes #144) --- themes/grav/js/pages-all.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/themes/grav/js/pages-all.js b/themes/grav/js/pages-all.js index 69172579..acf0e7b4 100644 --- a/themes/grav/js/pages-all.js +++ b/themes/grav/js/pages-all.js @@ -163,8 +163,14 @@ $(function(){ $('input[name="folder"]').on('input', function(e){ + var start = this.selectionStart, + end = this.selectionEnd; + value = $(this).val().toLowerCase().replace(/\s/g, '-').replace(/[^a-z0-9_\-]/g, ''); $(this).val(value); + + // restore cursor position + this.setSelectionRange(start, end); }); childrenToggles.on('click', function () {