11document . addEventListener ( 'DOMContentLoaded' , function ( ) {
2- // Menu search
2+ var $root = document . documentElement ;
3+ var template = $root . dataset . template ;
4+
5+ // Menu: Search
36 var $searchInput = document . getElementById ( 'menu-search-input' ) ;
47 var $menuList = document . getElementById ( 'menu-list' ) ;
58 var $menuItems = document . querySelectorAll ( '#menu-list li a' ) ;
@@ -59,16 +62,22 @@ document.addEventListener('DOMContentLoaded', function() {
5962 } ) ;
6063
6164 window . addEventListener ( 'keydown' , function ( event ) {
62- var key = event . key || false ;
65+ var key = event . code || event . key || false ;
6366
6467 switch ( key ) {
6568 case 'Enter' :
6669 if ( isSearching ) {
67- event . preventDefault ( ) ;
68- var $target = document . getElementById ( matches [ currentMatch ] . propertyName ) ;
70+ var propertyName = matches [ currentMatch ] . propertyName ;
6971
70- if ( $target ) {
71- $target . scrollIntoView ( ) ;
72+ if ( template === 'index' ) {
73+ event . preventDefault ( ) ;
74+ var $target = document . getElementById ( propertyName ) ;
75+
76+ if ( $target ) {
77+ $target . scrollIntoView ( ) ;
78+ }
79+ } else {
80+ window . location = window . location . origin + '/#' + propertyName ;
7281 }
7382 }
7483 break ;
@@ -108,7 +117,7 @@ document.addEventListener('DOMContentLoaded', function() {
108117 cleanMenu ( $menuItems , true , true ) ;
109118 }
110119
111- // Menu scroll
120+ // Menu: Shadows
112121 var $menuUl = document . getElementById ( 'menu-list-ul' ) ;
113122 var $menuShadowTop = document . getElementById ( 'menu-shadow-top' ) ;
114123 var $menuShadowBottom = document . getElementById ( 'menu-shadow-bottom' ) ;
@@ -148,7 +157,28 @@ document.addEventListener('DOMContentLoaded', function() {
148157 }
149158 setMenuShadows ( ) ;
150159
151- // Copy to clipboard
160+ // Menu: Mobile
161+ var $menuNav = document . getElementById ( 'menu-nav' ) ;
162+ var $menuNavOpen = document . getElementById ( 'menu-nav-open' ) ;
163+ var $menuNavClose = document . getElementById ( 'menu-nav-close' ) ;
164+
165+ $menuNavOpen . addEventListener ( 'click' , function ( event ) {
166+ $menuNav . classList . add ( 'is-active' ) ;
167+ } ) ;
168+
169+ $menuNavClose . addEventListener ( 'click' , function ( event ) {
170+ $menuNav . classList . remove ( 'is-active' ) ;
171+ } ) ;
172+
173+ Array . prototype . forEach . call ( $menuItems , function ( $menuItem , index ) {
174+ $menuItem . addEventListener ( 'click' , function ( event ) {
175+ if ( window . innerWidth < 800 ) {
176+ $menuNav . classList . remove ( 'is-active' ) ;
177+ }
178+ } ) ;
179+ } ) ;
180+
181+ // Property: Copy to clipboard
152182 var clipboard = new Clipboard ( '.example-value' ) ;
153183
154184 Array . prototype . forEach . call ( document . querySelectorAll ( '.example-value' ) , function ( $el ) {
@@ -162,7 +192,7 @@ document.addEventListener('DOMContentLoaded', function() {
162192 e . trigger . classList . add ( 'is-copied' ) ;
163193 } ) ;
164194
165- // Share property
195+ // Property: Share modal
166196 var $propertyShares = document . querySelectorAll ( '.property-share' ) ;
167197 var $modalInput = document . getElementById ( 'modal-input' ) ;
168198 var baseURL = '' + window . location . origin + window . location . pathname ;
@@ -233,20 +263,7 @@ document.addEventListener('DOMContentLoaded', function() {
233263 setTimeout ( function ( ) { e . trigger . innerHTML = 'Copy' ; } , 500 ) ;
234264 } ) ;
235265
236- // Mobile menu
237- var $menuNav = document . getElementById ( 'menu-nav' ) ;
238- var $menuNavOpen = document . getElementById ( 'menu-nav-open' ) ;
239- var $menuNavClose = document . getElementById ( 'menu-nav-close' ) ;
240-
241- $menuNavOpen . addEventListener ( 'click' , function ( event ) {
242- $menuNav . classList . add ( 'is-active' ) ;
243- } ) ;
244-
245- $menuNavClose . addEventListener ( 'click' , function ( event ) {
246- $menuNav . classList . remove ( 'is-active' ) ;
247- } ) ;
248-
249- // Launch animations
266+ // Property: Launch animations
250267 var $launchButtons = document . querySelectorAll ( '.property-animation-toggle' ) ;
251268
252269 Array . prototype . forEach . call ( $launchButtons , function ( $launchButton , index ) {
@@ -262,7 +279,7 @@ document.addEventListener('DOMContentLoaded', function() {
262279 } ) ;
263280 } ) ;
264281
265- // Enable fixed
282+ // Property: Enable fixed
266283 var $fixedButtons = document . querySelectorAll ( '.example-fixed-toggle' ) ;
267284
268285 Array . prototype . forEach . call ( $fixedButtons , function ( $fixedButton , index ) {
0 commit comments