some improvements to Ox.Editable
This commit is contained in:
parent
188656bd99
commit
1eb93125e6
2 changed files with 34 additions and 33 deletions
|
@ -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/> ');
|
||||
}
|
||||
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, ' ')
|
||||
: self.options.value.replace(/\n$/, '<br/> ')
|
||||
.replace(/\n/g, '<br/>'));
|
||||
return self.options.type == 'input'
|
||||
? self.options.value.replace(/ /g, ' ')
|
||||
: self.options.value.replace(/\n$/, '<br/> ')
|
||||
.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
|
||||
|
|
|
@ -37,10 +37,9 @@ Ox.parseHTML <f> Takes HTML from an untrusted source and returns something sane
|
|||
|
||||
Ox.parseHTML = (function() {
|
||||
var defaultTags = [
|
||||
// fixme: why not p?
|
||||
'a', 'b', 'blockquote', 'cite', 'code',
|
||||
'a', 'b', 'blockquote', 'br', 'cite', 'code',
|
||||
'del', 'em', 'i', 'img', 'ins',
|
||||
'li', 'ol', 'q', 'rtl', 's',
|
||||
'li', 'ol', 'p', 'q', 'rtl', 's',
|
||||
'strong', 'sub', 'sup', 'ul', '[]'
|
||||
],
|
||||
parse = {
|
||||
|
@ -89,7 +88,8 @@ Ox.parseHTML = (function() {
|
|||
matches.forEach(function(match, i) {
|
||||
html = html.replace(new RegExp(tab + i + tab, 'gi'), match);
|
||||
});
|
||||
html = html.replace(/\n/g, '<br/>\n');
|
||||
//html = html.replace(/\n/g, '<br/>\n');
|
||||
html = html.replace(/\n/g, '<br/>');
|
||||
// close extra opening (and remove extra closing) tags
|
||||
// note: this converts '"' to '"'
|
||||
return Ox.element('<div>').html(html).html();
|
||||
|
|
Loading…
Reference in a new issue