From b7791e57e9cb8d1e4e368ffad84087d1e0e47c9b Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 23 Aug 2016 17:23:06 +0200 Subject: [PATCH] [FIX] web_tour: use visible elements in run method When checking for a DOM element in a run method thanks to the action helper, visible elements are now considered first, then, if none is found, we take the first invisible one. --- addons/web_tour/static/src/js/tour_manager.js | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index 9033f049b24..87c7f5ed8ff 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -21,6 +21,26 @@ function get_running_delay_key() { return get_running_key() + "_delay"; } +function get_first_visible_element($elements) { + for (var i = 0 ; i < $elements.length ; i++) { + var $i = $elements.eq(i); + if ($i.is(":visible") && _has_visibility($i)) { + return $i; + } + } + return $(); + + function _has_visibility($elem) { + if ($elem.css("visibility") === "hidden") { + return false; + } + if ($elem.is("html")) { + return true; + } + return _has_visibility($elem.parent()); + } +} + function do_before_unload(if_unload_callback, if_not_unload_callback) { if_unload_callback = if_unload_callback || function () {}; if_not_unload_callback = if_not_unload_callback || if_unload_callback; @@ -64,7 +84,11 @@ var RunningTourActionHelper = core.Class.extend({ } }, _get_action_values: function (element) { - var $element = element ? $(element).first() : this.tip_widget.$anchor; + var $e = $(element); + var $element = element ? get_first_visible_element($e) : this.tip_widget.$anchor; + if ($element.length === 0) { + $element = $e.first(); + } var consume_event = element ? Tip.getConsumeEventType($element) : this.tip_widget.consume_event; return { $element: $element, @@ -279,26 +303,6 @@ return core.Class.extend({ } else { this._deactivate_tip(tip); } - - function get_first_visible_element($elements) { - for (var i = 0 ; i < $elements.length ; i++) { - var $i = $elements.eq(i); - if ($i.is(":visible") && _has_visibility($i)) { - return $i; - } - } - return $(); - - function _has_visibility($elem) { - if ($elem.css("visibility") === "hidden") { - return false; - } - if ($elem.is("html")) { - return true; - } - return _has_visibility($elem.parent()); - } - } }, _activate_tip: function(tip, tour_name, $anchor) { var tour = this.tours[tour_name]; @@ -438,5 +442,4 @@ return core.Class.extend({ }, }, }); - });