1
0
Fork 0
forked from 0x2620/oxjs

some improvements to Ox.Editable

This commit is contained in:
rlx 2011-10-27 08:47:31 +00:00
commit 1eb93125e6
2 changed files with 34 additions and 33 deletions

View file

@ -58,11 +58,7 @@ Ox.Editable = function(options, self) {
//padding: '0 4px 0 4px'
width: self.options.width + 'px'
})
.html(
self.options.format
? self.options.format(self.options.value)
: self.options.value
)
.html(formatValue())
//[self.options.editing ? 'hide' : 'show']()
.appendTo(that);
@ -73,7 +69,7 @@ Ox.Editable = function(options, self) {
//left: 200,
//top: 200
})
.html(self.options.value.replace(/ /g, ' '))
.html(formatTestValue())
.hide()
.appendTo(that.$element);
@ -81,7 +77,7 @@ Ox.Editable = function(options, self) {
changeOnKeypress: true,
style: 'square',
type: self.options.type,
value: Ox.parseHTML(self.options.value)
value: formatInputValue()
}, self.options.type == 'textarea' ? {
width: self.options.width
} : {}))
@ -109,13 +105,9 @@ Ox.Editable = function(options, self) {
function change(event) {
var height, width;
self.options.value = formatValue(event.value);
self.$value.html(
self.options.format
? self.options.format(self.options.value)
: self.options.value
);
self.$test.html(self.options.value.replace(/ /g, ' '));
self.options.value = event.value;
self.$value.html(formatValue);
self.$test.html(formatTestValue());
height = self.options.height || self.$test.height();
//height = Math.max(self.$test.height(), 14);
width = Math.max(self.$test.width() + 2, 8);
@ -180,24 +172,33 @@ Ox.Editable = function(options, self) {
}
}
function formatValue(value) {
if (self.options.type == 'input') {
value = value.replace(/ /g, ' ');
} else {
value = value.replace(/\n/g, '<br/>')
.replace(/<br\/>$/, '<br/>&nbsp;');
}
return value;
function formatInputValue() {
return self.options.type == 'input'
? self.options.value
: self.options.value.replace(/<br\/?>/g, '\n');
}
function formatTestValue() {
Ox.print('TEST VALUE =', self.options.type == 'input'
? self.options.value.replace(/ /g, '&nbsp;')
: self.options.value.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>'));
return self.options.type == 'input'
? self.options.value.replace(/ /g, '&nbsp;')
: self.options.value.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>');
}
function formatValue() {
return self.options.format
? self.options.format(self.options.value)
: self.options.value
}
function submit() {
self.options.value = self.$input.value().trim();
self.$input.value(self.options.value);
self.$value.html(
self.options.format
? self.options.format(self.options.value)
: self.options.value
);
self.options.value = Ox.parseHTML(self.$input.value());
self.$input.value(formatInputValue());
self.$value.html(formatValue());
cancel();
that.triggerEvent('submit', {
value: self.options.value