[IMP] web: remove non used dom.js functions

Part-of-task: 3439226
Part-of: odoo/odoo#140181
This commit is contained in:
Jorge Pinna Puissant
2023-10-30 12:05:31 +00:00
committed by FrancoisGe
parent 3de178ed42
commit e2b0d3efe4
+1 -172
View File
@@ -9,44 +9,12 @@
* something happens in the DOM.
*/
import { uniqueId } from "@web/core/utils/functions";
import { delay } from "@web/core/utils/concurrency";
import { localization } from "@web/core/l10n/localization";
/**
* Private function to notify that something has been attached in the DOM
* @param {htmlString or Element or Array or jQuery} [content] the content that
* has been attached in the DOM
* @params {Array} [callbacks] array of {widget: w, callback_args: args} such
* that on_attach_callback() will be called on each w with arguments args
*/
function _notify(content, callbacks) {
callbacks.forEach(function (c) {
if (c.widget && c.widget.on_attach_callback) {
c.widget.on_attach_callback(c.callback_args);
}
});
}
var dom = {
DEBOUNCE: 400,
/**
* Appends content in a jQuery object and optionnally triggers an event
*
* @param {jQuery} [$target] the node where content will be appended
* @param {htmlString or Element or Array or jQuery} [content] DOM element,
* array of elements, HTML string or jQuery object to append to $target
* @param {Boolean} [options.in_DOM] true if $target is in the DOM
* @param {Array} [options.callbacks] array of objects describing the
* callbacks to perform (see _notify for a complete description)
*/
append: function ($target, content, options) {
$target.append(content);
if (options && options.in_DOM) {
_notify(content, options.callbacks);
}
},
/**
* Detects if 2 elements are colliding.
*
@@ -54,7 +22,7 @@ var dom = {
* @param {Element} el2
* @returns {boolean}
*/
areColliding(el1, el2) {
areColliding(el1, el2) {
const el1Rect = el1.getBoundingClientRect();
const el2Rect = el2.getBoundingClientRect();
return el1Rect.bottom > el2Rect.top
@@ -186,64 +154,6 @@ var dom = {
return $results;
},
/**
* Detaches widgets from the DOM and performs their on_detach_callback()
*
* @param {Array} [to_detach] array of {widget: w, callback_args: args} such
* that w.$el will be detached and w.on_detach_callback(args) will be
* called
* @param {jQuery} [options.$to_detach] if given, detached instead of
* widgets' $el
* @return {jQuery} the detached elements
*/
detach: function (to_detach, options) {
to_detach.forEach( function (d) {
if (d.widget.on_detach_callback) {
d.widget.on_detach_callback(d.callback_args);
}
});
var $to_detach = options && options.$to_detach;
if (!$to_detach) {
$to_detach = $(to_detach.map(function (d) {
return d.widget.el;
}));
}
return $to_detach.detach();
},
/**
* Returns the selection range of an input or textarea
*
* @param {Object} node DOM item input or texteara
* @returns {Object} range
*/
getSelectionRange: function (node) {
return {
start: node.selectionStart,
end: node.selectionEnd,
};
},
/**
* Returns the distance between a DOM element and the top-left corner of the
* window
*
* @param {Object} e DOM element (input or texteara)
* @return {Object} the left and top distances in pixels
*/
getPosition: function (e) {
var position = {left: 0, top: 0};
while (e) {
position.left += e.offsetLeft;
position.top += e.offsetTop;
e = e.offsetParent;
}
return position;
},
/**
* @returns {HTMLElement}
*/
getScrollingElement() {
return $().getScrollingElement(...arguments)[0];
},
/**
* @param {HTMLElement} el
* @returns {boolean}
@@ -251,13 +161,6 @@ var dom = {
hasScrollableContent(el) {
return $(el).hasScrollableContent();
},
/**
* @param {HTMLElement} el
* @returns {boolean}
*/
isScrollable(el) {
return $(el).isScrollable();
},
/**
* Protects a function which is to be used as a handler by preventing its
* execution for the duration of a previous call to it (including async
@@ -371,22 +274,6 @@ var dom = {
$loader.remove();
};
},
/**
* Prepends content in a jQuery object and optionnally triggers an event
*
* @param {jQuery} [$target] the node where content will be prepended
* @param {htmlString or Element or Array or jQuery} [content] DOM element,
* array of elements, HTML string or jQuery object to prepend to $target
* @param {Boolean} [options.in_DOM] true if $target is in the DOM
* @param {Array} [options.callbacks] array of objects describing the
* callbacks to perform (see _notify for a complete description)
*/
prepend: function ($target, content, options) {
$target.prepend(content);
if (options && options.in_DOM) {
_notify(content, options.callbacks);
}
},
/**
* Renders a button with standard odoo template. This does not use any xml
* template to avoid forcing the frontend part to lazy load a xml file for
@@ -447,64 +334,6 @@ var dom = {
return $button;
},
/**
* Renders a checkbox with standard odoo/BS template. This does not use any
* xml template to avoid forcing the frontend part to lazy load a xml file
* for each widget which might want to create a simple checkbox.
*
* @param {Object} [options]
* @param {Object} [options.prop]
* Allows to set the input properties (disabled and checked states).
* @param {string} [options.text]
* The checkbox's associated text. If none is given then a simple
* checkbox is rendered.
* @returns {jQuery}
*/
renderCheckbox: function (options) {
var id = uniqueId('checkbox-');
var $container = $('<div/>', {
class: 'form-check',
});
var $input = $('<input/>', {
type: 'checkbox',
id: id,
class: 'form-check-input',
});
var $label = $('<label/>', {
for: id,
class: 'form-check-label',
text: options && options.text || '',
});
if (!options || !options.text) {
$label.html('&#8203;'); // BS checkboxes need some label content (so
// add a zero-width space when there is no text)
}
if (options && options.prop) {
$input.prop(options.prop);
}
if (options && options.role) {
$input.attr('role', options.role);
}
return $container.append($input, $label);
},
/**
* Sets the selection range of a given input or textarea
*
* @param {Object} node DOM element (input or textarea)
* @param {integer} range.start
* @param {integer} range.end
*/
setSelectionRange: function (node, range) {
if (node.setSelectionRange){
node.setSelectionRange(range.start, range.end);
} else if (node.createTextRange){
node.createTextRange()
.collapse(true)
.moveEnd('character', range.start)
.moveStart('character', range.end)
.select();
}
},
/**
* Computes the size by which a scrolling point should be decreased so that
* the top fixed elements of the page appear above that scrolling point.