This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
message_js.go
70 lines (54 loc) · 1.26 KB
/
message_js.go
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
// +build js
package dlgs
import (
"github.com/gopherjs/gopherjs/js"
)
// MessageBox displays message box and ok button without icon.
func MessageBox(title, text string) (bool, error) {
return alertDialog(title, text, "")
}
// 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
}