From 84b3c341307b7bd16c3f52fe7827f9c968779e2f Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 3 May 2016 18:39:24 +0100 Subject: [PATCH] Editable: avoid setTimeout It's easily avoided and clearer without it. --- source/UI/js/Form/Editable.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/UI/js/Form/Editable.js b/source/UI/js/Form/Editable.js index 3d528bc9..61e96f54 100644 --- a/source/UI/js/Form/Editable.js +++ b/source/UI/js/Form/Editable.js @@ -59,13 +59,13 @@ Ox.Editable = function(options, self) { setCSS({width: self.options.width + 'px'}); }, highlight: function() { - self.$value.html(formatValue()); + formatValue(); }, placeholder: function() { - self.$value.html(formatValue()); + formatValue(); }, value: function() { - self.$value.html(formatValue()); + formatValue(); self.$input && self.$input.options({value: formatInputValue()}); } }) @@ -99,8 +99,8 @@ Ox.Editable = function(options, self) { self.css = {}; self.$value = Ox.Element(self.options.type == 'input' ? '' : '
') .addClass('OxValue') - .html(formatValue()) .appendTo(that); + formatValue(); if (self.options.editing) { // need timeout so that when determining height @@ -127,13 +127,14 @@ Ox.Editable = function(options, self) { self.options.value = self.originalValue; self.$input.value(formatInputValue()).hide(); self.$test.html(formatTestValue()); - self.$value.html(formatValue()).show(); + formatValue(); + self.$value.show(); that.triggerEvent('cancel', {value: self.options.value}); } function change(data) { self.options.value = parseValue(data.value); - self.$value.html(formatValue()); + formatValue(); self.$test.html(formatTestValue()); setSizes(); } @@ -234,13 +235,11 @@ Ox.Editable = function(options, self) { value, self.options.highlight, 'OxHighlight', true ); } - // timeout needed since formatValue is used when assinging self.$value - setTimeout(function() { - self.$value[ - self.options.value === '' ? 'removeClass' : 'addClass' - ]('OxSelectable'); - }) - return value; + + self.$value.html(value); + self.$value[ + self.options.value === '' ? 'removeClass' : 'addClass' + ]('OxSelectable'); } function parseValue() { @@ -292,7 +291,8 @@ Ox.Editable = function(options, self) { that.removeClass('OxEditing'); self.$input.value(formatInputValue()).hide(); self.$test.html(formatTestValue()); - self.$value.html(formatValue()).show(); + formatValue(); + self.$value.show(); that.$tooltip && that.$tooltip.options({title: self.options.tooltip}); that.triggerEvent('submit', {value: self.options.value}); }