From ceba2a722343b8a13d0f683e0c84e670b47e1581 Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 26 Feb 2013 15:59:05 +0000 Subject: [PATCH] update EditableContent, plus some debugging --- source/Ox.UI/js/Form/EditableContent.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/Ox.UI/js/Form/EditableContent.js b/source/Ox.UI/js/Form/EditableContent.js index 40640e5a..c238e43a 100644 --- a/source/Ox.UI/js/Form/EditableContent.js +++ b/source/Ox.UI/js/Form/EditableContent.js @@ -53,10 +53,10 @@ Ox.EditableContent = function(options, self) { self.$value = Ox.Element(self.options.type == 'span' ? '' : '
') .html(formatValue()) .on({ - blur: submit, + blur: self.options.submitOnBlur ? submit : blur, keydown: function(e) { if (self.options.editing) { - if (self.options.type == 'span' && e.keyCode == 13) { + if (e.keyCode == 13 && self.options.type == 'span') { submit(); return false; } else if (e.keyCode == 27) { @@ -69,11 +69,12 @@ Ox.EditableContent = function(options, self) { .appendTo(that); function blur() { - + Ox.print('BLUR!') } function cancel() { if (self.options.editing) { + Ox.print('CANCEL!') that.loseFocus(); self.options.editing = false; self.$value @@ -86,6 +87,7 @@ Ox.EditableContent = function(options, self) { function edit() { if (self.options.editable && !self.options.editing) { + Ox.print('EDIT!') var value = formatInputValue(); self.$value .addClass('OxEditableContentInput') @@ -141,11 +143,13 @@ Ox.EditableContent = function(options, self) { function submit() { if (self.options.editing) { + Ox.print('SUBMIT!') that.loseFocus(); self.options.editing = false; self.options.value = self.$value.text(); if (self.options.value.charCodeAt(0) == 160) { - self.options.value = ''; + // remove nbsp + self.options.value = self.options.value.substr(1); } self.$value .attr({contenteditable: false}) @@ -163,7 +167,7 @@ Ox.EditableContent = function(options, self) { range = document.createRange(); range.selectNodeContents(self.$value[0]); selection.addRange(range); - if (self.options.type != 'span') { + if (self.options.type == 'div') { setTimeout(function() { selection.collapseToEnd(); }, 0);