add support for data annotations
This commit is contained in:
parent
33a7832d64
commit
8243614546
5 changed files with 77 additions and 34 deletions
|
|
@ -19,7 +19,7 @@ Ox.Editable = function(options, self) {
|
|||
|
||||
self = self || {};
|
||||
var that = Ox.Element({
|
||||
element: options.type == 'textarea' ? '<div>' : '<span>',
|
||||
element: options.type == 'input' ? '<span>' : '<div>',
|
||||
tooltip: options.tooltip
|
||||
}, self)
|
||||
.defaults({
|
||||
|
|
@ -94,7 +94,9 @@ Ox.Editable = function(options, self) {
|
|||
}
|
||||
});
|
||||
|
||||
self.options.value = self.options.value.toString();
|
||||
if (self.options.type != 'data') {
|
||||
self.options.value = self.options.value.toString();
|
||||
}
|
||||
|
||||
self.css = {};
|
||||
self.$value = Ox.Element(self.options.type == 'input' ? '<span>' : '<div>')
|
||||
|
|
@ -159,7 +161,7 @@ Ox.Editable = function(options, self) {
|
|||
changeOnKeypress: true,
|
||||
element: self.options.type == 'input' ? '<span>' : '<div>',
|
||||
style: 'square',
|
||||
type: self.options.type,
|
||||
type: getInputType(),
|
||||
value: formatInputValue()
|
||||
})
|
||||
.css(self.css)
|
||||
|
|
@ -203,14 +205,15 @@ Ox.Editable = function(options, self) {
|
|||
}
|
||||
|
||||
function formatInputValue() {
|
||||
return self.options.type == 'input'
|
||||
? (self.options.unformat || Ox.decodeHTMLEntities)(self.options.value)
|
||||
return self.options.unformat
|
||||
? self.options.unformat(self.options.value)
|
||||
: self.options.type == 'input' ? Ox.decodeHTMLEntities(self.options.value)
|
||||
: self.options.value.replace(/<br\/?><br\/?>/g, '\n\n');
|
||||
}
|
||||
|
||||
function formatTestValue() {
|
||||
var value = Ox.encodeHTMLEntities(
|
||||
(self.options.unformat || Ox.identity)(self.$input.options('value'))
|
||||
(self.options.type != 'data' && self.options.unformat || Ox.identity)(self.$input.options('value'))
|
||||
);
|
||||
return !value ? ' '
|
||||
: self.options.type == 'input'
|
||||
|
|
@ -247,7 +250,9 @@ Ox.Editable = function(options, self) {
|
|||
self.$input.value().replace(/\n\n+/g, '\0')
|
||||
).replace(/\0/g, '\n\n').trim();
|
||||
return (
|
||||
self.options.type == 'input'
|
||||
self.options.type == 'data'
|
||||
? JSON.parse(value)
|
||||
: self.options.type == 'input'
|
||||
? Ox.encodeHTMLEntities(value)
|
||||
: Ox.sanitizeHTML(value, self.options.tags, self.options.globalAttributes)
|
||||
);
|
||||
|
|
@ -265,7 +270,7 @@ Ox.Editable = function(options, self) {
|
|||
height = self.options.height || Ox.limit(self.$test.height(), self.minHeight, self.maxHeight);
|
||||
width = self.$test.width();
|
||||
// +Ox.UI.SCROLLBAR_SIZE to prevent scrollbar from showing up
|
||||
if (self.options.type == 'textarea') {
|
||||
if (self.options.type != 'input') {
|
||||
width += Ox.UI.SCROLLBAR_SIZE;
|
||||
}
|
||||
width = self.options.width || Ox.limit(width, self.minWidth, self.maxWidth);
|
||||
|
|
@ -280,12 +285,16 @@ Ox.Editable = function(options, self) {
|
|||
width: width,
|
||||
height: height
|
||||
});
|
||||
self.$input.find(self.options.type).css({
|
||||
self.$input.find(getInputType()).css({
|
||||
width: width + 'px',
|
||||
height: height + 'px'
|
||||
});
|
||||
}
|
||||
|
||||
function getInputType() {
|
||||
return self.options.type == 'data' ? 'textarea' : self.options.type
|
||||
}
|
||||
|
||||
function submit() {
|
||||
self.options.editing = false;
|
||||
that.removeClass('OxEditing');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue