File tree 6 files changed +162
-19
lines changed
6 files changed +162
-19
lines changed Original file line number Diff line number Diff line change 2
2
3
3
document . addEventListener ( 'DOMContentLoaded' , function ( ) {
4
4
5
- // Dropdowns
5
+ // Dropdowns in navbar
6
6
7
7
var $dropdowns = getAll ( '.navbar-item.has-dropdown:not(.is-hoverable)' ) ;
8
8
@@ -25,6 +25,14 @@ document.addEventListener('DOMContentLoaded', function () {
25
25
} ) ;
26
26
}
27
27
28
+ // Close dropdowns if ESC pressed
29
+ document . addEventListener ( 'keydown' , function ( event ) {
30
+ var e = event || window . event ;
31
+ if ( e . keyCode === 27 ) {
32
+ closeDropdowns ( ) ;
33
+ }
34
+ } ) ;
35
+
28
36
// Toggles
29
37
30
38
var $burgers = getAll ( '.burger' ) ;
Original file line number Diff line number Diff line change @@ -18,28 +18,39 @@ func SetupNavbarBurgers() {
18
18
}
19
19
}
20
20
21
- func SetupDropdownsInNavbar () {
22
- dds := Document .QuerySelectorAll (".navbar-item.has-dropdown:not(.is-hoverable)" )
23
-
24
- if len (dds ) > 0 {
25
- for _ , dd := range dds {
26
- dd .AddEventListener ("click" , func (e Event ) {
27
- e .StopPropagation ()
28
- dd .ClassList ().Toggle ("is-active" )
29
- })
30
- }
21
+ func main () {
22
+ Document .AddEventListener ("DOMContentLoaded" , func (e Event ) {
23
+
24
+ // Dropdowns in navbar
25
+ dds := Document .QuerySelectorAll (".navbar-item.has-dropdown:not(.is-hoverable)" )
31
26
32
- Document . AddEventListener ( "click" , func (e Event ) {
27
+ closeDropdowns := func () {
33
28
for _ , dd := range dds {
34
29
dd .ClassList ().Remove ("is-active" )
35
30
}
31
+ }
32
+
33
+ if len (dds ) > 0 {
34
+ for _ , dd := range dds {
35
+ dd .AddEventListener ("click" , func (e Event ) {
36
+ e .StopPropagation ()
37
+ dd .ClassList ().Toggle ("is-active" )
38
+ })
39
+ }
40
+
41
+ Document .AddEventListener ("click" , func (e Event ) {
42
+ closeDropdowns ()
43
+ })
44
+ }
45
+
46
+ // Close dropdowns if ESC pressed
47
+ Document .AddEventListener ("keydown" , func (e Event ) {
48
+ if e .KeyCode () == 27 {
49
+ closeDropdowns ()
50
+ }
36
51
})
37
- }
38
- }
39
52
40
- func main () {
41
- Document .AddEventListener ("DOMContentLoaded" , func (e Event ) {
53
+ // Toggles
42
54
SetupNavbarBurgers ()
43
- SetupDropdownsInNavbar ()
44
55
})
45
56
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
4
+
5
+ // Dropdowns
6
+
7
+ var $dropdowns = getAll ( '.dropdown:not(.is-hoverable)' ) ;
8
+
9
+ if ( $dropdowns . length > 0 ) {
10
+ $dropdowns . forEach ( function ( $el ) {
11
+ $el . addEventListener ( 'click' , function ( event ) {
12
+ event . stopPropagation ( ) ;
13
+ $el . classList . toggle ( 'is-active' ) ;
14
+ } ) ;
15
+ } ) ;
16
+
17
+ document . addEventListener ( 'click' , function ( event ) {
18
+ closeDropdowns ( ) ;
19
+ } ) ;
20
+ }
21
+
22
+ function closeDropdowns ( ) {
23
+ $dropdowns . forEach ( function ( $el ) {
24
+ $el . classList . remove ( 'is-active' ) ;
25
+ } ) ;
26
+ }
27
+
28
+ // Close dropdowns if ESC pressed
29
+ document . addEventListener ( 'keydown' , function ( event ) {
30
+ var e = event || window . event ;
31
+ if ( e . keyCode === 27 ) {
32
+ closeDropdowns ( ) ;
33
+ }
34
+ } ) ;
35
+
36
+ // Functions
37
+
38
+ function getAll ( selector ) {
39
+ return Array . prototype . slice . call ( document . querySelectorAll ( selector ) , 0 ) ;
40
+ }
41
+ } ) ;
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ . "github.com/siongui/godom"
5
+ )
6
+
7
+ func main () {
8
+ Document .AddEventListener ("DOMContentLoaded" , func (e Event ) {
9
+
10
+ // Dropdowns
11
+ dds := Document .QuerySelectorAll (".dropdown:not(.is-hoverable)" )
12
+
13
+ closeDropdowns := func () {
14
+ for _ , dd := range dds {
15
+ dd .ClassList ().Remove ("is-active" )
16
+ }
17
+ }
18
+
19
+ if len (dds ) > 0 {
20
+ for _ , dd := range dds {
21
+ dd .AddEventListener ("click" , func (e Event ) {
22
+ e .StopPropagation ()
23
+ dd .ClassList ().Toggle ("is-active" )
24
+ })
25
+ }
26
+
27
+ Document .AddEventListener ("click" , func (e Event ) {
28
+ closeDropdowns ()
29
+ })
30
+ }
31
+
32
+ // Close dropdowns if ESC pressed
33
+ Document .AddEventListener ("keydown" , func (e Event ) {
34
+ if e .KeyCode () == 27 {
35
+ closeDropdowns ()
36
+ }
37
+ })
38
+ })
39
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
6
+ < title > Bulma dropdown with Go toggle</ title >
7
+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css ">
8
+ </ head >
9
+ < body >
10
+
11
+ < div class ="dropdown is-active ">
12
+ < div class ="dropdown-trigger ">
13
+ < button class ="button " aria-haspopup ="true " aria-controls ="dropdown-menu ">
14
+ < span > Dropdown button</ span >
15
+ < span class ="icon is-small ">
16
+ < i class ="fas fa-angle-down " aria-hidden ="true "> </ i >
17
+ </ span >
18
+ </ button >
19
+ </ div >
20
+ < div class ="dropdown-menu " id ="dropdown-menu " role ="menu ">
21
+ < div class ="dropdown-content ">
22
+ < a href ="# " class ="dropdown-item ">
23
+ Dropdown item
24
+ </ a >
25
+ < a class ="dropdown-item ">
26
+ Other dropdown item
27
+ </ a >
28
+ < a href ="# " class ="dropdown-item is-active ">
29
+ Active dropdown item
30
+ </ a >
31
+ < a href ="# " class ="dropdown-item ">
32
+ Other dropdown item
33
+ </ a >
34
+ < hr class ="dropdown-divider ">
35
+ < a href ="# " class ="dropdown-item ">
36
+ With a divider
37
+ </ a >
38
+ </ div >
39
+ </ div >
40
+ </ div >
41
+
42
+ < script src ="app.js "> </ script >
43
+ </ body >
44
+ </ html >
Original file line number Diff line number Diff line change @@ -7,9 +7,9 @@ ifndef TRAVIS
7
7
export PATH := $(GOROOT)/bin:$(GOPATH)/bin:$(PATH)
8
8
endif
9
9
10
- GO_VERSION =1.9.2
10
+ GO_VERSION =1.9.3
11
11
12
- WEBSITE_DIR =023-keyboard-event-gopherjs-vue
12
+ WEBSITE_DIR =024-bulma-dropdown
13
13
14
14
default : fmt js devserver
15
15
godom : fmt domjs devserver
You can’t perform that action at this time.
0 commit comments