-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathelement.step.ts
More file actions
executable file
·119 lines (115 loc) · 3.15 KB
/
element.step.ts
File metadata and controls
executable file
·119 lines (115 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
import { TourStep } from './tourstep';
/**
* Tour step that highlights an element on the page with some explanation
*/
export class ElementTourStep extends TourStep {
/**
* Element to highlight
*/
public domElement: Element;
/**
* HTML to display in this step
*/
public body: string;
public constructor(selector: string, body: string, async?: boolean) {
super();
this.domElement = window.document.querySelector(selector);
if (!(this.domElement instanceof Element)) {
if (async) {
let timeout = 100;
var retry = () => {
// Give up eventually
if (timeout <= 2000) {
this.domElement = window.document.querySelector(selector);
if (!(this.domElement instanceof Element)) {
timeout *= 2;
setTimeout(retry, timeout);
}
}
};
setTimeout(retry, timeout);
} else {
throw new Error("Couldn't find the element you selected");
}
}
this.body = body;
}
//region DOM position helpers
get top(): string {
if (!this.domElement) {
return '0';
}
return (this.domElement.getBoundingClientRect().top + window.pageYOffset) + 'px';
}
get bottom(): string {
if (!this.domElement) {
return '0';
}
return (this.domElement.getBoundingClientRect().bottom + window.pageYOffset) + 'px';
}
get left(): string {
if (!this.domElement) {
return '0';
}
return (this.domElement.getBoundingClientRect().left + window.pageXOffset) + 'px';
}
get leftContent(): string {
if (!this.domElement) {
return '0';
}
if (((this.domElement.getBoundingClientRect().left + window.pageXOffset) - window.innerWidth) >= -700) {
return ((window.innerWidth - 720) + 'px');
}
console.log(((this.domElement.getBoundingClientRect().left + window.pageXOffset) - window.innerWidth));
return (this.domElement.getBoundingClientRect().left + window.pageXOffset) + 'px';
}
get right(): string {
if (!this.domElement) {
return '0';
}
return (this.domElement.getBoundingClientRect().right + window.pageXOffset) + 'px';
}
get documentHeight(): string {
return document.body.scrollHeight + 'px';
}
get documentWidth(): string {
return document.body.scrollWidth + 'px';
}
get toBottom(): string {
if (!this.domElement) {
return '0';
}
return (document.body.scrollHeight - (this.domElement.getBoundingClientRect().bottom + window.pageYOffset)) + 'px';
}
get toRight(): string {
if (!this.domElement) {
return '0';
}
return (document.body.scrollWidth - (this.domElement.getBoundingClientRect().right + window.pageXOffset)) + 'px';
}
get fromLeft(): string {
if (!this.domElement) {
return '0';
}
return (document.body.scrollWidth - (this.domElement.getBoundingClientRect().left + window.pageXOffset)) + 'px';
}
get fromTop(): string {
if (!this.domElement) {
return '0';
}
return (document.body.scrollHeight - (this.domElement.getBoundingClientRect().top + window.pageYOffset)) + 'px';
}
get height(): string {
if (!this.domElement) {
return '0';
}
return this.domElement.getBoundingClientRect().height + 'px';
}
get width(): string {
if (!this.domElement) {
return '0';
}
return this.domElement.getBoundingClientRect().width + 'px';
}
//endregion
}