| 1 |
window.addEventListener('load', function () |
| 2 |
{ |
| 3 |
const tours = tour_plugin.tours; |
| 4 |
const driver = window.driver.js.driver; |
| 5 |
|
| 6 |
function revert_to_first_tab(activeElement, activeStep, options) { |
| 7 |
jQuery('#propertyhive_metabox_tabs a').eq(0).trigger('click'); |
| 8 |
} |
| 9 |
|
| 10 |
function revert_to_third_tab(activeElement, activeStep, options) { |
| 11 |
jQuery('#propertyhive_metabox_tabs a').eq(2).trigger('click'); |
| 12 |
} |
| 13 |
|
| 14 |
// Function to resolve string to function |
| 15 |
function getCallbackFunction(callbackName) { |
| 16 |
const callbacks = { |
| 17 |
revert_to_first_tab, |
| 18 |
revert_to_third_tab |
| 19 |
}; |
| 20 |
|
| 21 |
return callbacks[callbackName] || null; |
| 22 |
} |
| 23 |
|
| 24 |
const tourId = 'add-property'; |
| 25 |
|
| 26 |
if (!tours || !tours[tourId]) { |
| 27 |
console.log('Tour not found'); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
const tourSteps = tours[tourId].map((step) => ({ |
| 32 |
...step, |
| 33 |
popover: { |
| 34 |
...step.popover, |
| 35 |
onNextClick: step.popover.onNextClick |
| 36 |
? (activeElement, activeStep, options) => |
| 37 |
getCallbackFunction(step.popover.onNextClick)?.( |
| 38 |
activeElement, |
| 39 |
activeStep, |
| 40 |
{ ...options, driver: driverObj } // Pass driverObj explicitly |
| 41 |
) || driverObj.moveNext() |
| 42 |
: () => driverObj.moveNext(), // Default behavior |
| 43 |
onPrevClick: step.popover.onPrevClick |
| 44 |
? (activeElement, activeStep, options) => |
| 45 |
getCallbackFunction(step.popover.onPrevClick)?.( |
| 46 |
activeElement, |
| 47 |
activeStep, |
| 48 |
{ ...options, driver: driverObj } |
| 49 |
) || driverObj.movePrevious() |
| 50 |
: () => driverObj.movePrevious(), // Default behavior |
| 51 |
}, |
| 52 |
})); |
| 53 |
|
| 54 |
const driverObj = driver({ |
| 55 |
showProgress: true, |
| 56 |
steps: tourSteps, |
| 57 |
}); |
| 58 |
|
| 59 |
setTimeout(() => { driverObj.drive(0) }, 250); |
| 60 |
}); |
| 61 |
|