-
Notifications
You must be signed in to change notification settings - Fork 7
/
cicerone.js
146 lines (115 loc) · 3.27 KB
/
cicerone.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import 'shiny';
import 'jquery';
import Driver from 'driver.js';
import 'driver.js/dist/driver.min.css';
import './custom.css';
let driver = [];
let highlighted;
let previous;
let has_next;
const on_next = (id) => {
highlighted = driver[id].getHighlightedElement();
previous = driver[id].getLastHighlightedElement();
has_next = driver[id].hasNextStep();
try{
highlighted = highlighted.options.element.substr(1);
}
catch(err){
highlighted = null;
}
try{
previous = previous.options.element.substr(1);
}
catch(err){
previous = null;
}
var data = {
highlighted: highlighted,
has_next: has_next,
previous: highlighted,
before_previous: previous
}
Shiny.setInputValue(id + "_cicerone_next", data);
}
const on_previous = (id) => {
highlighted = driver[id].getHighlightedElement();
previous = driver[id].getLastHighlightedElement();
has_next = driver[id].hasNextStep();
try{
highlighted = highlighted.options.element.substr(1);
}
catch(err){
highlighted = null;
}
try{
previous = previous.options.element.substr(1);
}
catch(err){
previous = null;
}
var data = {
highlighted: highlighted,
has_next: has_next,
previous: highlighted,
before_previous: previous
}
Shiny.setInputValue(id + "_cicerone_previous", data);
}
const make_previous = (id) => {
return function() {
return on_previous(id);
}
}
const make_next = (id) => {
return function() {
return on_next(id);
}
}
Shiny.addCustomMessageHandler('cicerone-init', function(opts) {
var id = opts.globals.id;
var next_func = make_next(id);
var prev_func = make_previous(id);
opts.globals.onNext = next_func;
opts.globals.onPrevious = prev_func;
opts.globals.onReset = function(){
Shiny.setInputValue('cicerone_reset', true, {priority: 'event'})
}
driver[id] = new Driver(opts.globals);
opts.steps.forEach((step, index) => {
if(opts.steps[index].tab_id){
opts.steps[index].onHighlightStarted = function(element){
var tabs = $('#' + step.tab_id);
Shiny.inputBindings.bindingNames['shiny.bootstrapTabInput'].binding.setValue(tabs, step.tab);
};
}
if(opts.steps[index].onHighlighted){
opts.steps[index].onHighlighted = new Function("return " + opts.steps[index].onHighlighted)();
}
if(opts.steps[index].onHighlightStarted){
opts.steps[index].onHighlightStarted = new Function("return " + opts.steps[index].onHighlightStarted)();
}
if(opts.steps[index].onNext){
opts.steps[index].onNext = new Function("return " + opts.steps[index].onNext)();
}
});
if(opts.steps)
driver[id].defineSteps(opts.steps);
});
Shiny.addCustomMessageHandler('cicerone-start', function(opts) {
driver[opts.id].start(opts.step);
});
Shiny.addCustomMessageHandler('cicerone-reset', function(opts) {
driver[opts.id].reset();
});
Shiny.addCustomMessageHandler('cicerone-next', function(opts) {
driver[opts.id].moveNext();
});
Shiny.addCustomMessageHandler('cicerone-previous', function(opts) {
driver[opts.id].movePrevious();
});
Shiny.addCustomMessageHandler('cicerone-highlight-man', function(opts) {
driver[opts.id].highlight(opts);
});
Shiny.addCustomMessageHandler('cicerone-highlight', function(opts) {
driver[opts.id].highlight(opts.el);
});