update EditableContent, plus some debugging

This commit is contained in:
rolux 2013-02-26 15:59:05 +00:00
parent 72a017e106
commit ceba2a7223

View file

@ -53,10 +53,10 @@ Ox.EditableContent = function(options, self) {
self.$value = Ox.Element(self.options.type == 'span' ? '<span>' : '<div>') self.$value = Ox.Element(self.options.type == 'span' ? '<span>' : '<div>')
.html(formatValue()) .html(formatValue())
.on({ .on({
blur: submit, blur: self.options.submitOnBlur ? submit : blur,
keydown: function(e) { keydown: function(e) {
if (self.options.editing) { if (self.options.editing) {
if (self.options.type == 'span' && e.keyCode == 13) { if (e.keyCode == 13 && self.options.type == 'span') {
submit(); submit();
return false; return false;
} else if (e.keyCode == 27) { } else if (e.keyCode == 27) {
@ -69,11 +69,12 @@ Ox.EditableContent = function(options, self) {
.appendTo(that); .appendTo(that);
function blur() { function blur() {
Ox.print('BLUR!')
} }
function cancel() { function cancel() {
if (self.options.editing) { if (self.options.editing) {
Ox.print('CANCEL!')
that.loseFocus(); that.loseFocus();
self.options.editing = false; self.options.editing = false;
self.$value self.$value
@ -86,6 +87,7 @@ Ox.EditableContent = function(options, self) {
function edit() { function edit() {
if (self.options.editable && !self.options.editing) { if (self.options.editable && !self.options.editing) {
Ox.print('EDIT!')
var value = formatInputValue(); var value = formatInputValue();
self.$value self.$value
.addClass('OxEditableContentInput') .addClass('OxEditableContentInput')
@ -141,11 +143,13 @@ Ox.EditableContent = function(options, self) {
function submit() { function submit() {
if (self.options.editing) { if (self.options.editing) {
Ox.print('SUBMIT!')
that.loseFocus(); that.loseFocus();
self.options.editing = false; self.options.editing = false;
self.options.value = self.$value.text(); self.options.value = self.$value.text();
if (self.options.value.charCodeAt(0) == 160) { if (self.options.value.charCodeAt(0) == 160) {
self.options.value = ''; // remove nbsp
self.options.value = self.options.value.substr(1);
} }
self.$value self.$value
.attr({contenteditable: false}) .attr({contenteditable: false})
@ -163,7 +167,7 @@ Ox.EditableContent = function(options, self) {
range = document.createRange(); range = document.createRange();
range.selectNodeContents(self.$value[0]); range.selectNodeContents(self.$value[0]);
selection.addRange(range); selection.addRange(range);
if (self.options.type != 'span') { if (self.options.type == 'div') {
setTimeout(function() { setTimeout(function() {
selection.collapseToEnd(); selection.collapseToEnd();
}, 0); }, 0);