forked from 0x2620/oxjs
select all text in span and move cursor to end otherwise
This commit is contained in:
parent
42e30f6a0a
commit
fdc84965bd
1 changed files with 15 additions and 1 deletions
|
|
@ -67,6 +67,7 @@ Ox.EditableContent = function(options, self) {
|
||||||
self.$input.show().on({
|
self.$input.show().on({
|
||||||
focus: function() {
|
focus: function() {
|
||||||
self.editing = true;
|
self.editing = true;
|
||||||
|
updateSelection();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
@ -125,6 +126,19 @@ Ox.EditableContent = function(options, self) {
|
||||||
self.$value.html(formatValue()).show();
|
self.$value.html(formatValue()).show();
|
||||||
that.triggerEvent('submit', {value: self.options.value});
|
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.css = function(css) {
|
||||||
that.$element.css(css);
|
that.$element.css(css);
|
||||||
|
|
@ -135,4 +149,4 @@ Ox.EditableContent = function(options, self) {
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue