2
2
3
3
let BeautifulJekyllJS = {
4
4
5
- bigImgEl : null ,
6
- numImgs : null ,
5
+ bigImgEl : null ,
6
+ numImgs : null ,
7
7
8
- init : function ( ) {
8
+ init : function ( ) {
9
9
setTimeout ( BeautifulJekyllJS . initNavbar , 10 ) ;
10
10
11
+ let navbar = document . querySelector ( ".navbar" ) ;
12
+
11
13
// Shorten the navbar after scrolling a little bit down
12
- $ ( window ) . scroll ( function ( ) {
13
- if ( $ ( ".navbar" ) . offset ( ) . top > 50 ) {
14
- $ ( ". navbar" ) . addClass ( "top-nav-short" ) ;
15
- } else {
16
- $ ( ". navbar" ) . removeClass ( "top-nav-short" ) ;
17
- }
14
+ window . addEventListener ( 'scroll' , function ( ) {
15
+ if ( window . scrollY > 50 ) {
16
+ navbar . classList . add ( "top-nav-short" ) ;
17
+ } else {
18
+ navbar . classList . remove ( "top-nav-short" ) ;
19
+ }
18
20
} ) ;
19
21
20
22
// On mobile, hide the avatar when expanding the navbar menu
21
- $ ( '# main-navbar') . on ( 'show.bs.collapse' , function ( ) {
22
- $ ( ". navbar" ) . addClass ( "top-nav-expanded" ) ;
23
+ document . getElementById ( ' main-navbar') . addEventListener ( 'show.bs.collapse' , function ( ) {
24
+ navbar . classList . add ( "top-nav-expanded" ) ;
23
25
} ) ;
24
- $ ( '# main-navbar') . on ( 'hidden.bs.collapse' , function ( ) {
25
- $ ( ". navbar" ) . removeClass ( "top-nav-expanded" ) ;
26
+ document . getElementById ( ' main-navbar') . addEventListener ( 'hidden.bs.collapse' , function ( ) {
27
+ navbar . classList . remove ( "top-nav-expanded" ) ;
26
28
} ) ;
27
29
28
30
// show the big header image
@@ -31,26 +33,30 @@ let BeautifulJekyllJS = {
31
33
BeautifulJekyllJS . initSearch ( ) ;
32
34
} ,
33
35
34
- initNavbar : function ( ) {
36
+ initNavbar : function ( ) {
35
37
// Set the navbar-dark/light class based on its background color
36
- const rgb = $ ( '.navbar' ) . css ( "background-color" ) . replace ( / [ ^ \d , ] / g, '' ) . split ( "," ) ;
38
+ const rgb = getComputedStyle ( document . querySelector ( '.navbar' ) ) . backgroundColor . replace ( / [ ^ \d , ] / g, '' ) . split ( "," ) ;
37
39
const brightness = Math . round ( ( // http://www.w3.org/TR/AERT#color-contrast
38
40
parseInt ( rgb [ 0 ] ) * 299 +
39
41
parseInt ( rgb [ 1 ] ) * 587 +
40
42
parseInt ( rgb [ 2 ] ) * 114
41
43
) / 1000 ) ;
44
+
45
+ let navbar = document . querySelector ( ".navbar" ) ;
42
46
if ( brightness <= 125 ) {
43
- $ ( ".navbar" ) . removeClass ( "navbar-light" ) . addClass ( "navbar-dark" ) ;
47
+ navbar . classList . remove ( "navbar-light" ) ;
48
+ navbar . classList . add ( "navbar-dark" ) ;
44
49
} else {
45
- $ ( ".navbar" ) . removeClass ( "navbar-dark" ) . addClass ( "navbar-light" ) ;
50
+ navbar . classList . remove ( "navbar-dark" ) ;
51
+ navbar . classList . add ( "navbar-light" ) ;
46
52
}
47
53
} ,
48
54
49
- initImgs : function ( ) {
50
- // If the page was large images to randomly select from, choose an image
51
- if ( $ ( "# header-big-imgs") . length > 0 ) {
52
- BeautifulJekyllJS . bigImgEl = $ ( "# header-big-imgs") ;
53
- BeautifulJekyllJS . numImgs = BeautifulJekyllJS . bigImgEl . attr ( "data-num-img" ) ;
55
+ initImgs : function ( ) {
56
+ // If the page has large images to randomly select from, choose an image
57
+ if ( document . getElementById ( " header-big-imgs") ) {
58
+ BeautifulJekyllJS . bigImgEl = document . getElementById ( " header-big-imgs") ;
59
+ BeautifulJekyllJS . numImgs = BeautifulJekyllJS . bigImgEl . getAttribute ( "data-num-img" ) ;
54
60
55
61
// 2fc73a3a967e97599c9763d05e564189
56
62
// set an initial image
@@ -69,19 +75,19 @@ let BeautifulJekyllJS = {
69
75
prefetchImg . src = src ;
70
76
// if I want to do something once the image is ready: `prefetchImg.onload = function(){}`
71
77
72
- setTimeout ( function ( ) {
73
- const img = $ ( "<div></div>" ) . addClass ( "big-img-transition" ) . css ( "background-image" , 'url(' + src + ')' ) ;
74
- $ ( ".intro-header.big-img" ) . prepend ( img ) ;
75
- setTimeout ( function ( ) { img . css ( "opacity" , "1" ) ; } , 50 ) ;
78
+ setTimeout ( function ( ) {
79
+ const img = document . createElement ( "div" ) ;
80
+ img . className = "big-img-transition" ;
81
+ img . style . backgroundImage = 'url(' + src + ')' ;
82
+ document . querySelector ( ".intro-header.big-img" ) . prepend ( img ) ;
83
+ setTimeout ( function ( ) { img . style . opacity = "1" ; } , 50 ) ;
76
84
77
85
// after the animation of fading in the new image is done, prefetch the next one
78
- //img.one("transitioned webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){
79
86
setTimeout ( function ( ) {
80
87
BeautifulJekyllJS . setImg ( src , desc ) ;
81
88
img . remove ( ) ;
82
89
getNextImg ( ) ;
83
90
} , 1000 ) ;
84
- //});
85
91
} , 6000 ) ;
86
92
} ;
87
93
@@ -92,46 +98,51 @@ let BeautifulJekyllJS = {
92
98
}
93
99
} ,
94
100
95
- getImgInfo : function ( ) {
101
+ getImgInfo : function ( ) {
96
102
const randNum = Math . floor ( ( Math . random ( ) * BeautifulJekyllJS . numImgs ) + 1 ) ;
97
- const src = BeautifulJekyllJS . bigImgEl . attr ( "data-img-src-" + randNum ) ;
98
- const desc = BeautifulJekyllJS . bigImgEl . attr ( "data-img-desc-" + randNum ) ;
103
+ const src = BeautifulJekyllJS . bigImgEl . getAttribute ( "data-img-src-" + randNum ) ;
104
+ const desc = BeautifulJekyllJS . bigImgEl . getAttribute ( "data-img-desc-" + randNum ) ;
99
105
100
106
return {
101
- src : src ,
102
- desc : desc
107
+ src : src ,
108
+ desc : desc
103
109
}
104
110
} ,
105
111
106
- setImg : function ( src , desc ) {
107
- $ ( ".intro-header.big-img" ) . css ( "background-image" , 'url(' + src + ')' ) ;
112
+ setImg : function ( src , desc ) {
113
+ document . querySelector ( ".intro-header.big-img" ) . style . backgroundImage = 'url(' + src + ')' ;
114
+
115
+ let imgDesc = document . querySelector ( ".img-desc" ) ;
108
116
if ( typeof desc !== typeof undefined && desc !== false ) {
109
- $ ( ".img-desc" ) . text ( desc ) . show ( ) ;
117
+ imgDesc . textContent = desc ;
118
+ imgDesc . style . display = "block" ;
110
119
} else {
111
- $ ( ".img-desc" ) . hide ( ) ;
120
+ imgDesc . style . display = "none" ;
112
121
}
113
122
} ,
114
123
115
- initSearch : function ( ) {
124
+ initSearch : function ( ) {
116
125
if ( ! document . getElementById ( "beautifuljekyll-search-overlay" ) ) {
117
126
return ;
118
127
}
119
128
120
- $ ( "# nav-search-link") . click ( function ( e ) {
129
+ document . getElementById ( " nav-search-link") . addEventListener ( 'click' , function ( e ) {
121
130
e . preventDefault ( ) ;
122
- $ ( "#beautifuljekyll-search-overlay" ) . show ( ) ;
123
- $ ( "#nav-search-input" ) . focus ( ) . select ( ) ;
124
- $ ( "body" ) . addClass ( "overflow-hidden" ) ;
131
+ document . getElementById ( "beautifuljekyll-search-overlay" ) . style . display = "block" ;
132
+ const searchInput = document . getElementById ( "nav-search-input" ) ;
133
+ searchInput . focus ( ) ;
134
+ searchInput . select ( ) ;
135
+ document . body . classList . add ( "overflow-hidden" ) ;
125
136
} ) ;
126
- $ ( "# nav-search-exit") . click ( function ( e ) {
137
+ document . getElementById ( " nav-search-exit") . addEventListener ( 'click' , function ( e ) {
127
138
e . preventDefault ( ) ;
128
- $ ( "# beautifuljekyll-search-overlay") . hide ( ) ;
129
- $ ( " body" ) . removeClass ( "overflow-hidden" ) ;
139
+ document . getElementById ( " beautifuljekyll-search-overlay") . style . display = "none" ;
140
+ document . body . classList . remove ( "overflow-hidden" ) ;
130
141
} ) ;
131
- $ ( document ) . on ( 'keyup' , function ( e ) {
132
- if ( e . key == "Escape" ) {
133
- $ ( "# beautifuljekyll-search-overlay") . hide ( ) ;
134
- $ ( " body" ) . removeClass ( "overflow-hidden" ) ;
142
+ document . addEventListener ( 'keyup' , function ( e ) {
143
+ if ( e . key === "Escape" ) {
144
+ document . getElementById ( " beautifuljekyll-search-overlay") . style . display = "none" ;
145
+ document . body . classList . remove ( "overflow-hidden" ) ;
135
146
}
136
147
} ) ;
137
148
}
0 commit comments