Editable: avoid setTimeout

It's easily avoided and clearer without it.
This commit is contained in:
Will Thompson 2016-05-03 18:39:24 +01:00 committed by j
parent ec85c7b458
commit 84b3c34130

View file

@ -59,13 +59,13 @@ Ox.Editable = function(options, self) {
setCSS({width: self.options.width + 'px'}); setCSS({width: self.options.width + 'px'});
}, },
highlight: function() { highlight: function() {
self.$value.html(formatValue()); formatValue();
}, },
placeholder: function() { placeholder: function() {
self.$value.html(formatValue()); formatValue();
}, },
value: function() { value: function() {
self.$value.html(formatValue()); formatValue();
self.$input && self.$input.options({value: formatInputValue()}); self.$input && self.$input.options({value: formatInputValue()});
} }
}) })
@ -99,8 +99,8 @@ Ox.Editable = function(options, self) {
self.css = {}; self.css = {};
self.$value = Ox.Element(self.options.type == 'input' ? '<span>' : '<div>') self.$value = Ox.Element(self.options.type == 'input' ? '<span>' : '<div>')
.addClass('OxValue') .addClass('OxValue')
.html(formatValue())
.appendTo(that); .appendTo(that);
formatValue();
if (self.options.editing) { if (self.options.editing) {
// need timeout so that when determining height // need timeout so that when determining height
@ -127,13 +127,14 @@ Ox.Editable = function(options, self) {
self.options.value = self.originalValue; self.options.value = self.originalValue;
self.$input.value(formatInputValue()).hide(); self.$input.value(formatInputValue()).hide();
self.$test.html(formatTestValue()); self.$test.html(formatTestValue());
self.$value.html(formatValue()).show(); formatValue();
self.$value.show();
that.triggerEvent('cancel', {value: self.options.value}); that.triggerEvent('cancel', {value: self.options.value});
} }
function change(data) { function change(data) {
self.options.value = parseValue(data.value); self.options.value = parseValue(data.value);
self.$value.html(formatValue()); formatValue();
self.$test.html(formatTestValue()); self.$test.html(formatTestValue());
setSizes(); setSizes();
} }
@ -234,13 +235,11 @@ Ox.Editable = function(options, self) {
value, self.options.highlight, 'OxHighlight', true value, self.options.highlight, 'OxHighlight', true
); );
} }
// timeout needed since formatValue is used when assinging self.$value
setTimeout(function() { self.$value.html(value);
self.$value[ self.$value[
self.options.value === '' ? 'removeClass' : 'addClass' self.options.value === '' ? 'removeClass' : 'addClass'
]('OxSelectable'); ]('OxSelectable');
})
return value;
} }
function parseValue() { function parseValue() {
@ -292,7 +291,8 @@ Ox.Editable = function(options, self) {
that.removeClass('OxEditing'); that.removeClass('OxEditing');
self.$input.value(formatInputValue()).hide(); self.$input.value(formatInputValue()).hide();
self.$test.html(formatTestValue()); self.$test.html(formatTestValue());
self.$value.html(formatValue()).show(); formatValue();
self.$value.show();
that.$tooltip && that.$tooltip.options({title: self.options.tooltip}); that.$tooltip && that.$tooltip.options({title: self.options.tooltip});
that.triggerEvent('submit', {value: self.options.value}); that.triggerEvent('submit', {value: self.options.value});
} }