[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.
This commit is contained in:
Denis Vermylen (dve)
2016-08-31 17:17:37 +02:00
parent 275ee5825d
commit fbe3608c7e
@@ -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) {