From 29427bdcb33794f9a63e9ef93bec7faf0df81049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 7 Jan 2016 15:36:53 +0100 Subject: [PATCH] [FIX] web: reimplement autosize for fun (and some bugfixing) autosize does not work correctly (it moves the screen in all directions sometimes when the user press enter in the bottom of the screen in some browser), So, we decided to have our own version, because of course, we can do it better. A few horrible hacks later, I proudly present you "autoresize" (it was almost named "odooresize" but common sense prevailed). As added benefits, it plays better with our web client, so when you open a dialog in a modal for example, the autosize fields should have the correct height automagically (or should I say 'odoomagically') --- addons/web/static/src/js/framework/utils.js | 62 +++++++++++++++++++ .../web/static/src/js/views/form_widgets.js | 11 +--- addons/web/static/test/x2many.js | 2 +- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/framework/utils.js b/addons/web/static/src/js/framework/utils.js index f1f28d83613..087d4c73d65 100644 --- a/addons/web/static/src/js/framework/utils.js +++ b/addons/web/static/src/js/framework/utils.js @@ -441,3 +441,65 @@ return { }); +odoo.define('web.dom_utils', function (require) { +"use strict"; + +var core = require('web.core'); + +// TO DO: move this into new file dom_utils.js +/** + * Autoresize a $textarea node, by recomputing its height when necessary + * @param {number} [options.min_height] by default, 50. + * @param {Widget} [options.parent] if set, autoresize will listen to some extra + * events to decide when to resize itself. This is useful for widgets that are + * not in the dom when the autoresize is declared. + */ +function autoresize ($textarea, options) { + options = options || {}; + + var $fixed_text_area; + var min_height = (options && options.min_height) || 50; + if (!$fixed_text_area) { + $fixed_text_area = $('