From fbe3608c7e9ceeaeb4d1204ec8193ad6aaa4d0f0 Mon Sep 17 00:00:00 2001 From: "Denis Vermylen (dve)" Date: Wed, 24 Aug 2016 17:14:41 +0200 Subject: [PATCH] [FIX] web: avoid autoresize duplicates In web_planner, changing pages would take more and more time after a few clicks if autoresize was called on textareas. Every time we would change page, autoresize was called on all textareas and added an additional textarea for each one, doubling the amount on each page change. The autoresize function in dom_utils was checking too shallowly for duplicates and created a new textarea where autoresize would again be called upon on a later stage. This commit fixes both problems. --- addons/web/static/src/js/framework/dom_utils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/framework/dom_utils.js b/addons/web/static/src/js/framework/dom_utils.js index 63a5c25a3d2..d0beff2988b 100644 --- a/addons/web/static/src/js/framework/dom_utils.js +++ b/addons/web/static/src/js/framework/dom_utils.js @@ -11,6 +11,9 @@ var core = require('web.core'); * not in the dom when the autoresize is declared. */ function autoresize ($textarea, options) { + if ($textarea.data("auto_resize")) { + return; + } options = options || {}; var $fixed_text_area; @@ -25,6 +28,7 @@ function autoresize ($textarea, options) { }); $fixed_text_area.addClass($textarea[0].className); $fixed_text_area.insertAfter($textarea); + $fixed_text_area.data("auto_resize", true); } var style = window.getComputedStyle($textarea[0], null); @@ -34,10 +38,7 @@ function autoresize ($textarea, options) { $textarea[0].style.resize = 'horizontal'; } resize(); - if ($textarea.__auto_resized) { - return; - } - $textarea.__auto_resized = true; + $textarea.data("auto_resize", true); $textarea.on('input focus', resize); if (options.parent) {