Repository navigation
Expand file tree
/
Copy pathvisuals.js
More file actions
104 lines (88 loc) · 3.26 KB
/
Copy pathvisuals.js
File metadata and controls
104 lines (88 loc) · 3.26 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
import MicroModal from './micromodal.mjs'
import goodforms_css from './goodforms.less'
import styleInject from 'style-inject'
import log from "./logging"
import modal_html from './modal.html'
import bad_address_html from './bad_address.html'
import pin_input_html from './pin_input.html'
import bad_pin_html from './bad_pin.html'
export function ensure_css() {
if(typeof window.goodforms_css === 'undefined') {
log.verbose("Ensuring CSS is added!!!")
styleInject(goodforms_css, {insertAt: 'top'}) //insert at top so customer-generated styles will override
window.goodforms_css = true
} else {
log.verbose("CSS has already been added, doing nothing")
}
}
export class modal {
constructor(email_field) {
this.modal = null
this.css = false
this.email_field = email_field
}
show(challenge_key, message, button_callback) {
this.message = message
ensure_css()
this.get_modal(challenge_key)
this.set_modal_action(button_callback)
this.display_challenge_modal(challenge_key)
}
hide() {
if(this.modal) {
MicroModal.close('goodforms-modal')
//should we dispose of it as well? It could be junking up their DOM I guess?
// I *think* that this is subsumed by our code to automagically clean up the modal onClose (see display_challenge_modal.onClose)
//document.body.removeChild(this.modal)
//this.modal = null
}
}
set_modal_action(callback) {
this.button.onclick = callback
}
get_challenge_address() {
return document.getElementById('goodforms_challenge_address').value
}
get_pin_code() {
return document.getElementById('goodforms_pin').value
}
get_modal(challenge_key) {
log.verbose("Getting modal - challenge key is: "+challenge_key)
if(!this.modal) {
//UGH - so, we need the 'button' - that's aproblem.
// we also allegedly need a "messagE"?
let wrapper = document.createElement('body')
wrapper.innerHTML = modal_html
this.modal = wrapper.firstChild
document.body.appendChild(this.modal)
this.button = document.getElementById('goodforms-continue-button')
}
return this.modal
}
display_challenge_modal(challenge_key) {
this.get_modal(challenge_key)
MicroModal.show('goodforms-modal',{
debugMode: true,
awaitCloseAnimation: true,
onShow: modal => log.verbose(`${modal.id} is shown`),
onClose: modal => {
log.verbose(`${modal.id} is hidden`)
if(this.modal) {
document.body.removeChild(this.modal)
delete this.modal
} else {
log.debug("Modal's onClose method is invoked and yet 'this.modal' doesn't seem to exist? Ignoring...")
}
}
})
}
bad_address() {
document.getElementById("modal-1-content").innerHTML = bad_address_html
}
pin_input() {
document.getElementById("modal-1-content").innerHTML = pin_input_html
}
bad_pin() {
document.getElementById("modal-1-content").innerHTML = bad_pin_html
}
}