update EditableContent

This commit is contained in:
rolux 2013-02-27 10:00:28 +00:00
parent 4c2564ffac
commit 90d8661641

View file

@ -9,7 +9,7 @@ Ox.EditableContent = function(options, self) {
: self.tooltip(e); : self.tooltip(e);
} }
} }
var that = Ox.Element(options.type == 'div' ? '<div>' : '<span>', self) var that = Ox.Element(options.type == 'textarea' ? '<div>' : '<span>', self)
.defaults({ .defaults({
clickLink: null, clickLink: null,
editable: true, editable: true,
@ -21,7 +21,7 @@ Ox.EditableContent = function(options, self) {
submitOnBlur: true, submitOnBlur: true,
tags: null, tags: null,
tooltip: '', tooltip: '',
type: 'span', type: 'input',
value: '' value: ''
}) })
.options(options || {}) .options(options || {})
@ -60,7 +60,7 @@ Ox.EditableContent = function(options, self) {
}, },
keydown: function(e) { keydown: function(e) {
if (e.keyCode == 13) { if (e.keyCode == 13) {
if (e.shiftKey || self.options.type == 'span') { if (e.shiftKey || self.options.type == 'input') {
submit(); submit();
} else { } else {
var selection = window.getSelection(), var selection = window.getSelection(),
@ -121,7 +121,7 @@ Ox.EditableContent = function(options, self) {
that.removeClass('OxEditableContentInput') that.removeClass('OxEditableContentInput')
.attr({contenteditable: false}) .attr({contenteditable: false})
.html(formatValue()); .html(formatValue());
if (self.options.type == 'span') { if (self.options.type == 'input') {
that.css({padding: 0}); that.css({padding: 0});
} }
that.triggerEvent('cancel', {value: self.options.value}); that.triggerEvent('cancel', {value: self.options.value});
@ -139,19 +139,19 @@ Ox.EditableContent = function(options, self) {
that.text(value); that.text(value);
} else { } else {
that.text(''); that.text('');
if (self.options.type == 'span') { if (self.options.type == 'input') {
that.css({padding: '0 2px'}); that.css({padding: '0 2px'});
} }
} }
self.options.editing = true; self.options.editing = true;
that.gainFocus(); that.gainFocus();
setTimeout(updateSelection); setTimeout(updateSelection, 50);
} }
} }
function formatInputValue() { function formatInputValue() {
return Ox.decodeHTMLEntities( return Ox.decodeHTMLEntities(
self.options.type == 'span' self.options.type == 'input'
? self.options.value ? self.options.value
: self.options.value.replace(/<br\/?><br\/?>/g, '\n\n') : self.options.value.replace(/<br\/?><br\/?>/g, '\n\n')
); );
@ -179,7 +179,7 @@ Ox.EditableContent = function(options, self) {
that.text().replace(/\n\n+/g, '\0') that.text().replace(/\n\n+/g, '\0')
).replace(/\0/g, '\n\n').trim(); ).replace(/\0/g, '\n\n').trim();
return ( return (
self.options.type == 'span' self.options.type == 'input'
? Ox.encodeHTMLEntities(value) ? Ox.encodeHTMLEntities(value)
: Ox.sanitizeHTML(value, self.options.tags, self.options.replaceTags) : Ox.sanitizeHTML(value, self.options.tags, self.options.replaceTags)
); );
@ -193,7 +193,7 @@ Ox.EditableContent = function(options, self) {
that.removeClass('OxEditableContentInput') that.removeClass('OxEditableContentInput')
.attr({contenteditable: false}) .attr({contenteditable: false})
.html(formatValue()); .html(formatValue());
if (self.options.type == 'span') { if (self.options.type == 'input') {
that.css({padding: 0}); that.css({padding: 0});
} }
that.triggerEvent('submit', {value: self.options.value}); that.triggerEvent('submit', {value: self.options.value});