[REF] web: move dom_utils to its own file

This commit is contained in:
Géry Debongnie
2016-05-27 16:08:50 +02:00
parent b107b14e6b
commit 4828a00f9e
3 changed files with 68 additions and 69 deletions
@@ -0,0 +1,67 @@
odoo.define('web.dom_utils', function (require) {
"use strict";
var core = require('web.core');
/**
* 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 = $('<textarea disabled>').css({
position: 'absolute',
opacity: 0,
height: 10,
top: -10000,
left: -10000,
});
$fixed_text_area.addClass($textarea[0].className);
$fixed_text_area.insertAfter($textarea);
}
var style = window.getComputedStyle($textarea[0], null);
if (style.resize === 'vertical') {
$textarea[0].style.resize = 'none';
} else if (style.resize === 'both') {
$textarea[0].style.resize = 'horizontal';
}
resize();
if ($textarea.__auto_resized) {
return;
}
$textarea.__auto_resized = true;
$textarea.on('input focus', resize);
if (options.parent) {
core.bus.on('DOM_updated', options.parent, resize);
core.bus.on('view_shown', options.parent, resize);
}
function resize () {
var heightOffset;
var style = window.getComputedStyle($textarea[0], null);
if (style.boxSizing === 'content-box') {
heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
} else {
heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
}
$fixed_text_area.width($textarea.width());
$fixed_text_area.val($textarea.val());
var height = $fixed_text_area[0].scrollHeight;
$textarea.css({height: Math.max(height + heightOffset, min_height)});
}
}
return {
autoresize: autoresize,
};
});
@@ -494,72 +494,3 @@ 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 = $('<textarea disabled>').css({
position: 'absolute',
opacity: 0,
height: 10,
top: -10000,
left: -10000,
});
$fixed_text_area.addClass($textarea[0].className);
$fixed_text_area.insertAfter($textarea);
}
var style = window.getComputedStyle($textarea[0], null);
if (style.resize === 'vertical') {
$textarea[0].style.resize = 'none';
} else if (style.resize === 'both') {
$textarea[0].style.resize = 'horizontal';
}
resize();
if ($textarea.__auto_resized) {
return;
}
$textarea.__auto_resized = true;
$textarea.on('input focus', resize);
if (options.parent) {
core.bus.on('DOM_updated', options.parent, resize);
core.bus.on('view_shown', options.parent, resize);
}
function resize () {
var heightOffset;
var style = window.getComputedStyle($textarea[0], null);
if (style.boxSizing === 'content-box') {
heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
} else {
heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
}
$fixed_text_area.width($textarea.width());
$fixed_text_area.val($textarea.val());
var height = $fixed_text_area[0].scrollHeight;
$textarea.css({height: Math.max(height + heightOffset, min_height)});
}
}
return {
autoresize: autoresize,
};
});
+1
View File
@@ -65,6 +65,7 @@
<script type="text/javascript" src="/web/static/src/js/framework/registry.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/session.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/model.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/dom_utils.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/utils.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/core.js"></script>
<script type="text/javascript" src="/web/static/src/js/framework/dialog.js"></script>