From e2b0d3efe401ad109fb58c9f95d6c12e2cedaec6 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 20 Oct 2023 13:25:04 +0200 Subject: [PATCH] [IMP] web: remove non used dom.js functions Part-of-task: 3439226 Part-of: odoo/odoo#140181 --- addons/web/static/src/legacy/js/core/dom.js | 173 +------------------- 1 file changed, 1 insertion(+), 172 deletions(-) diff --git a/addons/web/static/src/legacy/js/core/dom.js b/addons/web/static/src/legacy/js/core/dom.js index 80b693341ed..7ebf8ea2d69 100644 --- a/addons/web/static/src/legacy/js/core/dom.js +++ b/addons/web/static/src/legacy/js/core/dom.js @@ -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 = $('
', { - class: 'form-check', - }); - var $input = $('', { - type: 'checkbox', - id: id, - class: 'form-check-input', - }); - var $label = $('