-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdialog.js
127 lines (118 loc) · 3.19 KB
/
dialog.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
/**
* Very simple dialog to display info
*/
let d = new Dialog({
title: 'Example',
content: `Hello World!`,
buttons: {
ok: {
icon: '<i class="fas fa-check"></i>',
label: 'Ok',
},
}
}).render(true);
/* ---------------------------------------------------- */
/**
* Very simple dialog to prompt confirmation
* after user clicks button, confirmation will be boolean for yes/no
*/
let confirmation = await Dialog.confirm({
title: 'Example Confirm',
content: `<p>Are you sure?</p>`,
});
/* ---------------------------------------------------- */
/**
* Very simple dialog to request a user input
* Requires 0.7x
*/
let myValue = await Dialog.prompt({
content: `<input type="text">`,
callback: (html) => html.find('input').val()
})
/* ---------------------------------------------------- */
/**
* Example dialog that requests user input, then uses the value
*/
let d = new Dialog({
title: 'Example',
content: `
<form class="flexcol">
<div class="form-group">
<label for="exampleInput">Example Input</label>
<input type="text" name="exampleInput" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="exampleSelect">Example Select</label>
<select name="exampleSelect">
<option value="option1">Option One</option>
<option value="option2">Option Two</option>
<option value="option3">Option Three</option>
</select>
</div>
<div class="form-group">
<label for="exampleColor">Example Color</label>
<input class="color" type="text" name="exampleColor" value="#ff6400">
<input type="color" value="#ff6400" data-edit="exampleColor">
</div>
<div class="form-group">
<textarea name="exampleText" placeholder="Enter Text"></textarea>
</div>
</form>
`,
buttons: {
no: {
icon: '<i class="fas fa-times"></i>',
label: 'Cancel'
},
yes: {
icon: '<i class="fas fa-check"></i>',
label: 'Yes',
callback: (html) => {
let input = html.find('[name="exampleInput"]').val();
let select = html.find('[name="exampleSelect"]').val();
let color = html.find('[name="exampleColor"]').val();
let text = html.find('[name="exampleText"]').val();
console.log(input, select, color, text);
}
},
},
default: 'yes',
close: () => {
console.log('Example Dialog Closed');
}
}).render(true)
/* ---------------------------------------------------- */
/**
* Dialog that re-renders (stays open) when button is clicked
* rather than closing
*/
let myContent = function (val) {
return `
<div class="main">
<div class="headline">
Attack information:
</div>
<div class="plain-text">
<div class="actor" id="currentActor">${val}</div>
</div>
</div>
`
}
let myDialog = new Dialog({
title: `Example Dialog`,
content: myContent('Default Value'),
buttons: {
update: {
label: "Update",
callback: () => {
myValue = `Example random value: ${Math.random()*100}`;
myDialog.data.content = myContent(myValue);
myDialog.render(true);
}
}
},
},
{
id: 'test'
}
).render(true);