|
3 | 3 |
|
4 | 4 | var SELECTOR_CONTAINER = '#tourContainer'; |
5 | 5 | var SELECTOR_TOUR_VISIBLE = '.popover-tour:visible'; |
| 6 | + var CLASS_TOUR = 'touring'; |
6 | 7 |
|
7 | 8 | var tourModule = function() { |
8 | 9 | // placeholder |
9 | 10 | }; |
10 | 11 |
|
11 | 12 | tourModule.prototype = { |
12 | 13 | // Initialize tour popover item |
13 | | - // `selector` - the trigger for the popover to initialize |
14 | | - prepare : function(selector) { |
15 | | - if (selector) { |
16 | | - var control = $(selector); |
17 | | - var target = control.attr('data-cfw-popover-target'); |
18 | | - if ((typeof target === 'undefined' || target === false) && control.is('[data-clusive-tip-id]')) { |
19 | | - target = '#tour_' + control.attr('data-clusive-tip-id'); |
20 | | - } |
21 | | - var placement = control.attr('data-cfw-popover-placement'); |
22 | | - control.CFW_Popover({ |
23 | | - container: SELECTOR_CONTAINER, |
24 | | - viewport: 'window', |
25 | | - trigger: 'manual', |
26 | | - target: target, |
27 | | - placement: placement ? placement : 'right auto', |
28 | | - popperConfig: { |
29 | | - positionFixed: true |
30 | | - } |
31 | | - }); |
| 14 | + // `name` - name (via data attribute) trigger for the popover to initialize |
| 15 | + prepare : function(name) { |
| 16 | + var $control = $('[data-clusive-tip-id="' + name + '"]'); |
| 17 | + if (!$control.length) { return; } |
| 18 | + |
| 19 | + var target = $control.attr('data-cfw-popover-target'); |
| 20 | + if ((typeof target === 'undefined' || target === false) && $control.is('[data-clusive-tip-id]')) { |
| 21 | + target = '#tour_' + $control.attr('data-clusive-tip-id'); |
32 | 22 | } |
| 23 | + var placement = $control.attr('data-cfw-popover-placement'); |
| 24 | + $control.CFW_Popover({ |
| 25 | + container: SELECTOR_CONTAINER, |
| 26 | + viewport: 'window', |
| 27 | + trigger: 'manual', |
| 28 | + target: target, |
| 29 | + placement: placement ? placement : 'right auto', |
| 30 | + popperConfig: { |
| 31 | + positionFixed: true |
| 32 | + } |
| 33 | + }); |
| 34 | + }, |
| 35 | + |
| 36 | + // Show a singleton from the tour |
| 37 | + singleton: function(name) { |
| 38 | + var $control = $('[data-clusive-tip-id="' + name + '"]'); |
| 39 | + if (!$control.length) { return; } |
| 40 | + |
| 41 | + document.body.classList.remove(CLASS_TOUR); |
| 42 | + $control.one('afterShow.cfw.popover', function() { |
| 43 | + document.querySelector('#tour_' + name).focus(); |
| 44 | + window.parent.clusiveEvents.addTipViewToQueue(name); |
| 45 | + }); |
| 46 | + setTimeout(function() { |
| 47 | + $control.CFW_Popover('show'); |
| 48 | + }, 2000); |
33 | 49 | }, |
34 | 50 |
|
35 | 51 | // Chain animations for tour items together |
36 | 52 | // `selector` - the next popover in the chain |
37 | 53 | chain: function(selector) { |
38 | 54 | var $curr = $(document).find(SELECTOR_TOUR_VISIBLE); |
39 | 55 | var $next = $(selector); |
| 56 | + var $trigger = $next.data('cfw.popover').$element; |
| 57 | + |
| 58 | + var showComplete = function() { |
| 59 | + $next[0].focus(); |
| 60 | + var name = $next.attr('id').replace('tour_', ''); |
| 61 | + window.parent.clusiveEvents.addTipViewToQueue(name); |
| 62 | + }; |
| 63 | + |
| 64 | + // Hide tip/tour tooltip if showing |
| 65 | + $('#tip').CFW_Tooltip('hide'); |
40 | 66 |
|
41 | 67 | if ($curr.length) { |
42 | | - // Wait until hide animation is complete before callling show |
| 68 | + // Wait until hide animation is complete before calling show |
43 | 69 | $curr.CFW_Popover('hide').CFW_transition(null, function() { |
44 | | - $next.CFW_Popover('show'); |
45 | | - $next[0].focus(); |
| 70 | + document.body.classList.add(CLASS_TOUR); |
| 71 | + $trigger.one('afterShow.cfw.popover', showComplete); |
| 72 | + $trigger.CFW_Popover('show'); |
46 | 73 | }); |
47 | 74 | } else { |
48 | | - $next.CFW_Popover('show'); |
49 | | - $next[0].focus(); |
| 75 | + document.body.classList.add(CLASS_TOUR); |
| 76 | + $trigger.one('afterShow.cfw.popover', showComplete); |
| 77 | + $trigger.CFW_Popover('show'); |
50 | 78 | } |
51 | 79 |
|
52 | 80 | return false; |
|
61 | 89 | if ($curr.length) { |
62 | 90 | // Wait until hide animation is complete before focusing |
63 | 91 | $curr.CFW_Popover('hide').CFW_transition(null, function() { |
| 92 | + document.body.classList.remove(CLASS_TOUR); |
64 | 93 | $next[0].focus(); |
65 | 94 | }); |
66 | 95 | } else { |
| 96 | + document.body.classList.remove(CLASS_TOUR); |
67 | 97 | $next[0].focus(); |
68 | 98 | } |
69 | 99 |
|
|
0 commit comments