From bca7afe3ce93708d84f6241f9e242b22c899e6dd Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 3 Aug 2017 11:47:45 +0200 Subject: [PATCH] [REF] web, web_editor: expose 'cssFind' function The web_editor app uses a 'cssFind' function but does not expose it. It makes sense to move it in the web app in the 'dom' utility function set. --- addons/web/static/src/js/core/dom.js | 14 ++++++++++++ .../static/src/js/snippets.editor.js | 22 ++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/addons/web/static/src/js/core/dom.js b/addons/web/static/src/js/core/dom.js index 0ce30e2ac4e..8ad094b0ae8 100644 --- a/addons/web/static/src/js/core/dom.js +++ b/addons/web/static/src/js/core/dom.js @@ -104,6 +104,20 @@ return { core.bus.on('view_shown', options.parent, resize); } }, + /** + * jQuery find function behavior is: + * $('A').find('A B') <=> $('A A B') + * The searches behavior to find options' DOM needs to be + * $('A').find('A B') <=> $('A B') + * This is what this function does. + * + * @param {jQuery} $from - the jQuery element(s) from which to search + * @param {string} selector - the CSS selector to match + * @returns {jQuery} + */ + cssFind: function ($from, selector) { + return $from.find('*').filter(selector); + }, /** * Detaches widgets from the DOM and performs their on_detach_callback() * diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index 2353fcaee2f..a0bfb8b300c 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -4,6 +4,7 @@ odoo.define('web_editor.snippet.editor', function (require) { var Class = require('web.Class'); var ajax = require('web.ajax'); var core = require('web.core'); +var dom = require('web.dom'); var Widget = require('web.Widget'); var editor = require('web_editor.editor'); var animation = require('web_editor.snippets.animation'); @@ -98,7 +99,7 @@ data.Class = Widget.extend({ return $from.closest(selector, parentNode); }, all: function ($from) { - return $from ? cssFind($from, selector) : $(selector); + return $from ? dom.cssFind($from, selector) : $(selector); }, is: function ($from) { return $from.is(selector); @@ -121,31 +122,16 @@ data.Class = Widget.extend({ }); }, all: is_children ? function ($from) { - return cssFind($from || self.$editable, selector); + return dom.cssFind($from || self.$editable, selector); } : function ($from) { $from = $from || self.$editable; - return $from.filter(selector).add(cssFind($from, selector)); + return $from.filter(selector).add(dom.cssFind($from, selector)); }, is: function ($from) { return $from.is(selector); } }; } - - /** - * jQuery find function behavior is: - * $('A').find('A B') <=> $('A A B') - * The searches behavior to find options' DOM needs to be - * $('A').find('A B') <=> $('A B') - * This is what this function does. - * - * @param {jQuery} $from - the jQuery element(s) from which to search - * @param {string} selector - the CSS selector to match - * @returns {jQuery} - */ - function cssFind($from, selector) { - return $from.find('*').filter(selector); - } }, fetch_snippet_templates: function () {