forked from gen2brain/dlgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_js.go
More file actions
65 lines (50 loc) · 1.11 KB
/
message_js.go
File metadata and controls
65 lines (50 loc) · 1.11 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
// +build js
package dlgs
import (
"github.com/gopherjs/gopherjs/js"
)
// Info displays information dialog.
func Info(title, text string) (ret bool, err error) {
return alertDialog(title, text, "\u24d8")
}
// Warning displays warning dialog.
func Warning(title, text string) (ret bool, err error) {
return alertDialog(title, text, "\u26a0")
}
// Error displays error dialog.
func Error(title, text string) (ret bool, err error) {
return alertDialog(title, text, "\u166e")
}
// Question displays question dialog.
func Question(title, text string, defaultCancel bool) (ret bool, err error) {
defer func() {
e := recover()
if e == nil {
return
}
if e, ok := e.(*js.Error); ok {
err = e
} else {
panic(e)
}
}()
ret = js.Global.Call("confirm", "\u2753 "+title+"\n\n"+text).Bool()
return
}
// alert displays alert.
func alertDialog(title, text, level string) (ret bool, err error) {
defer func() {
e := recover()
if e == nil {
return
}
if e, ok := e.(*js.Error); ok {
err = e
} else {
panic(e)
}
}()
ret = true
js.Global.Call("alert", level+" "+title+"\n\n"+text)
return
}