summaryrefslogtreecommitdiff
path: root/addons/web_tour/static/src/js/tour_utils.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/web_tour/static/src/js/tour_utils.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/web_tour/static/src/js/tour_utils.js')
-rw-r--r--addons/web_tour/static/src/js/tour_utils.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/addons/web_tour/static/src/js/tour_utils.js b/addons/web_tour/static/src/js/tour_utils.js
new file mode 100644
index 00000000..ca6f11f8
--- /dev/null
+++ b/addons/web_tour/static/src/js/tour_utils.js
@@ -0,0 +1,72 @@
+odoo.define('web_tour.utils', function(require) {
+"use strict";
+
+function get_step_key(name) {
+ return 'tour_' + name + '_step';
+}
+
+function get_running_key() {
+ return 'running_tour';
+}
+
+function get_debugging_key(name) {
+ return `debugging_tour_${name}`;
+}
+
+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:hasVisibility')) {
+ return $i;
+ }
+ }
+ return $();
+}
+
+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;
+
+ var old_before = window.onbeforeunload;
+ var reload_timeout;
+ window.onbeforeunload = function () {
+ clearTimeout(reload_timeout);
+ window.onbeforeunload = old_before;
+ if_unload_callback();
+ if (old_before) return old_before.apply(this, arguments);
+ };
+ reload_timeout = _.defer(function () {
+ window.onbeforeunload = old_before;
+ if_not_unload_callback();
+ });
+}
+
+function get_jquery_element_from_selector(selector) {
+ if (_.isString(selector) && selector.indexOf('iframe') !== -1) {
+ var $iframe = $(selector.split('iframe')[0] + ' iframe');
+ var $el = $iframe.contents()
+ .find(selector.split('iframe')[1]);
+ $el.iframeContainer = $iframe[0];
+ return $el;
+ } else {
+ return $(selector);
+ }
+}
+
+
+return {
+ get_debugging_key: get_debugging_key,
+ 'get_step_key': get_step_key,
+ 'get_running_key': get_running_key,
+ 'get_running_delay_key': get_running_delay_key,
+ 'get_first_visible_element': get_first_visible_element,
+ 'do_before_unload': do_before_unload,
+ 'get_jquery_element_from_selector' : get_jquery_element_from_selector,
+};
+
+});
+