-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDriverJs.razor.js
More file actions
151 lines (132 loc) · 3.15 KB
/
DriverJs.razor.js
File metadata and controls
151 lines (132 loc) · 3.15 KB
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
147
148
149
150
151
import { driver } from "../driver.js"
import { addLink } from '../../BootstrapBlazor/modules/utility.js'
import Data from "../../BootstrapBlazor/modules/data.js"
export async function init(id, invoke) {
await addLink('./_content/BootstrapBlazor.DriverJs/driver.css')
Data.set(id, { invoke });
}
export function start(id, options, config) {
const el = document.getElementById(id);
if (el === null) {
return;
}
const d = Data.get(id);
if (d) {
d.config = config;
const { index } = config;
const { hookDestroyStarted, hookDestroyed } = options;
if (hookDestroyStarted) {
delete options.hookDestroyStarted;
options.onDestroyStarted = async (el, step, { state }) => {
const content = await d.invoke.invokeMethodAsync("OnBeforeDestroy", state.activeIndex);
if (content === null || confirm(content)) {
d.driver.destroy();
}
}
}
if (hookDestroyed) {
delete options.hookDestroyed;
options.onDestroyed = () => {
d.invoke.invokeMethodAsync("OnDestroyed");
};
}
const driverObj = driver(options);
d.driver = driverObj;
driverObj.drive(index);
}
}
export function dispose(id) {
const d = Data.get(id);
Data.remove(id);
if (d && d.driver) {
d.driver.destroy();
}
}
export function drive(id, index = 0) {
const d = Data.get(id);
if (d) {
d.driver.drive(index);
}
}
export function moveNext(id) {
const d = Data.get(id);
if (d) {
d.driver.moveNext();
}
}
export function movePrevious(id) {
const d = Data.get(id);
if (d) {
d.driver.movePrevious();
}
}
export function moveTo(id, index = 0) {
const d = Data.get(id);
if (d) {
d.driver.moveTo(index);
}
}
export function hasNextStep(id) {
let ret = false;
const d = Data.get(id);
if (d) {
d.driver.hasNextStep();
}
return ret;
}
export function hasPreviousStep(id) {
let ret = false;
const d = Data.get(id);
if (d) {
d.driver.hasPreviousStep();
}
return ret;
}
export function isFirstStep(id) {
let ret = false;
const d = Data.get(id);
if (d) {
ret = d.driver.isFirstStep();
}
return ret;
}
export function isLastStep(id) {
let ret = false;
const d = Data.get(id);
if (d) {
ret = d.driver.isLastStep();
}
return ret;
}
export function getActiveIndex(id) {
let index = -1;
const d = Data.get(id);
if (d) {
index = d.driver.getActiveIndex();
}
return index;
}
export function isActive(id) {
let ret = false;
const d = Data.get(id);
if (d) {
ret = d.driver.isActive();
}
return ret;
}
export function refresh(id) {
const d = Data.get(id);
if (d) {
d.driver.refresh();
}
}
export function destroy(id) {
const d = Data.get(id);
if (d) {
d.driver.destroy();
}
}
export function highlight(id, options, config) {
const driverObj = driver(options);
driverObj.highlight(config);
}