1- var languageNames = langs . map ( ( lang ) => lang . i ) ;
1+ const nav = document . querySelector ( "nav" ) ;
22
3- var iconFor = function ( iconName , uri ) {
3+ for ( let lang of langs ) {
4+ const item = document . createElement ( "div" ) ;
5+ item . appendChild ( document . createTextNode ( lang . n ) ) ;
6+ item . onclick = ( ) => show ( lang ) ;
7+ nav . appendChild ( item ) ;
8+ }
9+
10+ function iconFor ( iconName , uri ) {
411 return (
512 "<a href=" +
613 uri +
714 "><img src=resources/" +
815 iconName +
916 "-icon.png height=20></a>"
1017 ) ;
11- } ;
12-
13- document . getElementById ( "index" ) . onclick = ( ) => {
14- window . location . href = "" ;
15- } ;
18+ }
1619
1720langs . forEach ( ( lang , index ) => {
1821 lang . index = index ;
@@ -22,10 +25,7 @@ langs.forEach((lang, index) => {
2225 span . data = lang ;
2326 span . setAttributeNode ( attribute ) ;
2427 span . style . backgroundImage = "url(resources/" + lang . i + "-logo-64.png)" ;
25- document . getElementById ( "content" ) . appendChild ( span ) ;
26- span . onclick = function ( ) {
27- show ( lang ) ;
28- } ;
28+ document . querySelector ( "#index" ) . appendChild ( span ) ;
2929 if ( ( lang . h || lang . w || lang . g || lang . rc || lang . pp ) && lang . d ) {
3030 var icons = [ ] ;
3131 if ( lang . h ) icons . push ( iconFor ( "home" , lang . h ) ) ;
@@ -62,20 +62,15 @@ langs.forEach((lang, index) => {
6262 }
6363} ) ;
6464
65- var imageElement = document . getElementById ( " logo") ;
65+ var imageElement = document . querySelector ( "# logo img ") ;
6666var description = document . getElementById ( "description" ) ;
6767var info = document . getElementById ( "info" ) ;
6868var tags = document . getElementById ( "tags" ) ;
69- var prev = document . getElementById ( "prev" ) ;
70- var next = document . getElementById ( "next" ) ;
7169
72- var show = function ( language ) {
73- document . getElementById ( "content" ) . style . display = "none" ;
74- document . getElementById ( "single-language" ) . style . display = "block" ;
75- document . getElementById ( "bar" ) . innerHTML = language . n ;
76-
77- imageElement . style . backgroundImage =
78- "url(resources/" + language . i + "-logo-240.png)" ;
70+ function show ( language ) {
71+ document . querySelector ( "#index" ) . style . display = "none" ;
72+ imageElement . src = "resources/" + language . i + "-logo-240.png" ;
73+ imageElement . alt = `Logo for ${ language . n } ` ;
7974 if ( language . d ) {
8075 description . innerHTML = language . d ;
8176 description . style . display = "block" ;
@@ -113,44 +108,4 @@ var show = function (language) {
113108 } else {
114109 tags . style . display = "none" ;
115110 }
116-
117- var prevIndex = ( language . index + langs . length - 1 ) % langs . length ;
118- var nextIndex = ( language . index + 1 ) % langs . length ;
119- prev . innerHTML = "← " + langs [ prevIndex ] . n ;
120- next . innerHTML = langs [ nextIndex ] . n + " →" ;
121- prev . onclick = ( ) => show ( langs [ prevIndex ] ) ;
122- next . onclick = ( ) => show ( langs [ nextIndex ] ) ;
123- window . location . hash = "#" + language . i ;
124- } ;
125-
126- function home ( ) {
127- window . location . hash = "" ;
128- document . getElementById ( "single-language" ) . style . display = "none" ;
129- document . getElementById ( "content" ) . style . display = "block" ;
130- document . getElementById ( "bar" ) . innerHTML = "Programming Languages" ;
131111}
132-
133- addEventListener ( "keydown" , function ( event ) {
134- var key = window . location . hash . substring ( 1 ) ;
135- var index = languageNames . indexOf ( key ) ;
136- if ( isNaN ( index ) || index < 0 || index >= langs . length ) {
137- return ;
138- }
139- if ( event . keyCode === 37 ) {
140- show ( langs [ ( index + langs . length - 1 ) % langs . length ] ) ;
141- } else if ( event . keyCode === 39 ) {
142- show ( langs [ ( index + 1 ) % langs . length ] ) ;
143- } else if ( event . keyCode == 38 ) {
144- home ( ) ;
145- }
146- } ) ;
147-
148- window . onload = window . onpopstate = function ( ) {
149- var key = window . location . hash . substring ( 1 ) ;
150- var index = languageNames . indexOf ( key ) ;
151- if ( index >= 0 ) {
152- show ( langs [ index ] ) ;
153- } else {
154- home ( ) ;
155- }
156- } ;
0 commit comments