From f7c1ca17c3ce873eb3e5ce33d279b4f054c9292d Mon Sep 17 00:00:00 2001 From: sunhao Date: Mon, 26 Aug 2024 11:14:12 +0800 Subject: [PATCH] * [misc] fix duplicated step popover show. --- module/tutorial/js/index.ui.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/module/tutorial/js/index.ui.js b/module/tutorial/js/index.ui.js index 36880bbd75..e94d4aafb7 100644 --- a/module/tutorial/js/index.ui.js +++ b/module/tutorial/js/index.ui.js @@ -109,7 +109,7 @@ const stepPresenters = /* Check form. */ const $form = getStepForm(scope, $target); - if(!$form.length) console.error(`[TUTORIAL] Cannot find form for step "${step.guide.name} > ${step.task.name} > ${step.title}"`, step); + if(!$form || !$form.length) console.error(`[TUTORIAL] Cannot find form for step "${step.guide.name} > ${step.task.name} > ${step.title}"`, step); $form.attr('zui-tutorial-step', step.id); step.$form = $form; @@ -124,7 +124,7 @@ const stepPresenters = /* Check form. */ const $form = getStepForm(scope, $target); - if(!$form.length) console.error(`[TUTORIAL] Cannot find form for step "${step.guide.name} > ${step.task.name} > ${step.title}"`, step); + if(!$form || !$form.length) console.error(`[TUTORIAL] Cannot find form for step "${step.guide.name} > ${step.task.name} > ${step.title}"`, step); $form.attr('zui-tutorial-step', step.id); step.$form = $form; @@ -168,6 +168,7 @@ function getStepForm(scope, $target) { $form.data('tutorial.formBinding', true); const ajaxForm = $form.zui('ajaxForm'); + if(!ajaxForm) return console.error(`[TUTORIAL] Cannot find ajaxForm for step "${currentStep.guide.name} > ${currentStep.task.name} > ${currentStep.title}"`, currentStep); ajaxForm.setOptions({beforeSubmit: () => { if(currentStep.type === 'form') @@ -241,7 +242,7 @@ function highlightStepTarget($target, step, popoverOptions) { if(popover.options.key === step.id) { - const target = (typeof $target === 'function' ? $target() : $target)[0]; + const target = (typeof $target === 'function' ? $target(getStepScope(step)) : $target)[0]; if(target === popover.trigger) return; } return destroyPopover(() => highlightStepTarget($target, step, popoverOptions)); @@ -290,6 +291,7 @@ function highlightStepTarget($target, step, popoverOptions) }, onHide: function() { + if(this.options.key !== step.id) return; $(this.trigger).closest('body').find('.tutorial-light-box').addClass('opacity-0'); }, onLayout: function(info) @@ -498,7 +500,12 @@ function ensureStepScope(step, callback) return; } } - return setTimeout(() => callback(scope), 200); + if(step.waitScopeTimer) clearTimeout(step.waitScopeTimer); + step.waitScopeTimer = setTimeout(() => + { + delete step.waitScopeTimer; + callback(scope); + }, 200); } function openApp(url, app)