From 4c6fb72db0fada906eb059868d7dd4f68e1d6249 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 12 Feb 2014 10:36:17 -0500 Subject: [PATCH] move cursor to end in share input --- public/src/forum/topic.js | 4 +++- public/src/utils.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index bc3cb9cd9d..2502412e01 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -506,7 +506,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { $('#post_' + pid + '_link').val(window.location.href + "#" + pid); // without the setTimeout can't select the text in the input setTimeout(function() { - $('#post_' + pid + '_link').select(); + $('#post_' + pid + '_link').putCursorAtEnd().select(); + + }, 50); }); diff --git a/public/src/utils.js b/public/src/utils.js index 3ecee02ee7..2e4064d1f8 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -242,6 +242,21 @@ }); }; + //http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element + $.fn.putCursorAtEnd = function() { + return this.each(function() { + $(this).focus(); + + if (this.setSelectionRange) { + var len = $(this).val().length * 2; + this.setSelectionRange(len, len); + } else { + $(this).val($(this).val()); + } + this.scrollTop = 999999; + }); + }; + })(jQuery); }