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({
|
||||
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;
|
||||
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue