-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.go
More file actions
68 lines (52 loc) · 1.4 KB
/
widgets.go
File metadata and controls
68 lines (52 loc) · 1.4 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
package main
import "github.com/icza/gowut/gwu"
type Widgets struct {
gwu.Window
}
func MoreWidgets(w gwu.Window) Widgets {
return Widgets{Window:w}
}
//Disable the back button of the browser.
func (w Widgets) DisableBackButton() {
w.Window.Add(gwu.NewHTML(`
<script>
(function (global) {
if(typeof (global) === "undefined") {
throw new Error("window is undefined");
}
var _hash = "!";
var noBackPlease = function () {
global.location.href += "#";
// making sure we have the fruit available for juice (^__^)
global.setTimeout(function () {
global.location.href += "!";
}, 50);
};
global.onhashchange = function () {
if (global.location.hash !== _hash) {
global.location.hash = _hash;
}
};
global.onload = function () {
noBackPlease();
// disables backspace on page except on input fields and textarea..
document.body.onkeydown = function (e) {
var elm = e.target.nodeName.toLowerCase();
if (e.which === 8 && (elm !== 'input' && elm !== 'textarea')) {
e.preventDefault();
}
// stopping event bubbling up the DOM tree..
e.stopPropagation();
};
}
})(window);
</script>
`))
}
func NewSoundPlayer(url string) gwu.HTML {
return gwu.NewHTML(`
<audio controls preload="metadata" style=" width:300px;">
<source src="`+url+`" type="audio/ogg">
</audio><br />
`)
}