select all text in span and move cursor to end otherwise

This commit is contained in:
j 2013-02-25 18:47:07 +00:00
parent 42e30f6a0a
commit fdc84965bd

View file

@ -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;
};
};