From fdc84965bd768fea5b62d0933116e308d3ae40a7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 25 Feb 2013 18:47:07 +0000 Subject: [PATCH] select all text in span and move cursor to end otherwise --- source/Ox.UI/js/Form/EditableContent.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/Ox.UI/js/Form/EditableContent.js b/source/Ox.UI/js/Form/EditableContent.js index 2e1a7420..68bc3ad6 100644 --- a/source/Ox.UI/js/Form/EditableContent.js +++ b/source/Ox.UI/js/Form/EditableContent.js @@ -67,6 +67,7 @@ Ox.EditableContent = function(options, self) { self.$input.show().on({ focus: function() { self.editing = true; + updateSelection(); } }); setTimeout(function() { @@ -125,6 +126,19 @@ Ox.EditableContent = function(options, self) { self.$value.html(formatValue()).show(); that.triggerEvent('submit', {value: self.options.value}); } + function updateSelection() { + var range, selection; + selection = window.getSelection(); + selection.removeAllRanges(); + range = document.createRange(); + range.selectNodeContents(self.$input[0]); + selection.addRange(range); + if (self.options.type != 'span') { + setTimeout(function() { + selection.collapseToEnd(); + }, 0); + } + } that.css = function(css) { that.$element.css(css); @@ -135,4 +149,4 @@ Ox.EditableContent = function(options, self) { return that; -}; \ No newline at end of file +};