1- ' use strict' ;
1+ " use strict" ;
22
33// load more content
44function loadMore ( ) {
5- const paragraphs = document . querySelectorAll ( ' #projects_items .load_more' ) ;
5+ const paragraphs = document . querySelectorAll ( " #projects_items .load_more" ) ;
66 for ( let i = 0 ; i < paragraphs . length ; i ++ ) {
7- paragraphs [ i ] . classList . add ( ' show' ) ;
7+ paragraphs [ i ] . classList . add ( " show" ) ;
88 }
9- const hr = document . querySelectorAll ( ' .line_hr' ) ;
9+ const hr = document . querySelectorAll ( " .line_hr" ) ;
1010 for ( let i = 0 ; i < hr . length ; i ++ ) {
11- hr [ i ] . classList . add ( 'sh' ) ;
11+ hr [ i ] . classList . add ( "sh" ) ;
1212 }
13- document . getElementById ( ' load-more-button' ) . style . display = ' none' ;
14- document . getElementById ( ' hide-button' ) . style . display = ' block' ;
13+ document . getElementById ( " load-more-button" ) . style . display = " none" ;
14+ document . getElementById ( " hide-button" ) . style . display = " block" ;
1515}
1616
1717function hide ( ) {
18- const paragraphs = document . querySelectorAll ( ' #projects_items .load_more' ) ;
18+ const paragraphs = document . querySelectorAll ( " #projects_items .load_more" ) ;
1919 for ( let i = 0 ; i < paragraphs . length ; i ++ ) {
20- paragraphs [ i ] . classList . remove ( ' show' ) ;
20+ paragraphs [ i ] . classList . remove ( " show" ) ;
2121 }
22- const hr = document . querySelectorAll ( ' .line_hr' ) ;
22+ const hr = document . querySelectorAll ( " .line_hr" ) ;
2323 for ( let i = 0 ; i < hr . length ; i ++ ) {
24- hr [ i ] . classList . remove ( 'sh' ) ;
24+ hr [ i ] . classList . remove ( "sh" ) ;
2525 }
26- document . getElementById ( ' load-more-button' ) . style . display = ' block' ;
27- document . getElementById ( ' hide-button' ) . style . display = ' none' ;
26+ document . getElementById ( " load-more-button" ) . style . display = " block" ;
27+ document . getElementById ( " hide-button" ) . style . display = " none" ;
2828}
2929
30- const members_url = "https://api.github.com/orgs/move-fast-and-break-things/members" ;
30+ const members_url =
31+ "https://api.github.com/orgs/move-fast-and-break-things/members" ;
3132
3233// fetch authors data
3334async function getAuthors ( apiURL ) {
34-
3535 const response = await fetch ( apiURL ) ;
3636 if ( ! response . ok ) {
3737 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
3838 }
3939 const data = await response . json ( ) ;
40- return Promise . all ( data . map ( async ( element ) => {
41- const userResponse = await fetch ( element . url ) ;
42- if ( ! userResponse . ok ) {
43- throw new Error ( `HTTP error! status: ${ userResponse . status } ` ) ;
44- }
45- const userData = await userResponse . json ( ) ;
46- return {
47- name : userData . name || userData . login ,
48- bio : userData . bio ,
49- avatar : userData . avatar_url ,
50- html_url : userData . html_url ,
51- } ;
52- } ) ) ;
40+ return Promise . all (
41+ data . map ( async ( element ) => {
42+ const userResponse = await fetch ( element . url ) ;
43+ if ( ! userResponse . ok ) {
44+ throw new Error ( `HTTP error! status: ${ userResponse . status } ` ) ;
45+ }
46+ const userData = await userResponse . json ( ) ;
47+ return {
48+ name : userData . name || userData . login ,
49+ bio : userData . bio ,
50+ avatar : userData . avatar_url ,
51+ html_url : userData . html_url ,
52+ } ;
53+ } )
54+ ) ;
5355}
5456
5557// set authors in the DOM
5658async function setAuthors ( apiURL ) {
5759 const authors = await getAuthors ( apiURL ) ;
58- const container = document . querySelector ( "#creators > div > div " ) ;
60+ const container = document . querySelector ( "#creators .persons " ) ;
5961 if ( ! container ) {
6062 throw new Error ( "Container element not found" ) ;
6163 }
62- authors . forEach ( author => {
63- const personDiv = document . createElement ( 'div' ) ;
64- personDiv . className = 'person' ;
64+ console . log ( container ) ;
65+ authors . forEach ( ( author ) => {
66+ const personDiv = document . createElement ( "div" ) ;
67+ personDiv . className = "person" ;
6568 personDiv . innerHTML = `
6669 <div class="name_and_img">
6770 <a href="${ author . html_url } " class="tooltip" target="_blank">
@@ -70,67 +73,94 @@ async function setAuthors(apiURL) {
7073 </a>
7174 </div>
7275
73- <p class="about_person">${ author . bio || 'No biography available' } </p>
76+ <p class="about_person">${
77+ author . bio || "No biography available"
78+ } </p>
7479 ` ;
7580 container . appendChild ( personDiv ) ;
7681 } ) ;
77-
7882}
7983
8084// set contributors in the DOM
8185async function setContributors ( apiURL , element ) {
8286 try {
8387 const contributors = await getAuthors ( apiURL ) ;
84- element . innerHTML = contributors . length === 0 ? "No developers found" :
85- contributors . map ( contributor => `
88+ element . innerHTML =
89+ contributors . length === 0
90+ ? "No developers found"
91+ : contributors
92+ . map (
93+ ( contributor ) => `
8694 <span class="developer-name">
8795 <a href="${ contributor . html_url } " class="tooltip" target="_blank">
8896 <img src="${ contributor . avatar } " alt="${ contributor . name } 's avatar" class="shining-image">
8997 <span class="tooltip-text">${ contributor . name } </span>
9098 </a>
9199 </span>
92- ` ) . join ( '' ) ;
100+ `
101+ )
102+ . join ( "" ) ;
93103 } catch ( error ) {
94104 console . error ( "Error setting contributors:" , error ) ;
95- element . innerHTML = "Can't load the developer list. Check out the repository page to see all of the contributors 😅" ;
105+ element . innerHTML =
106+ "Can't load the developer list. Check out the repository page to see all of the contributors 😅" ;
96107 }
97108}
98109
99110// load all contributors
100111async function loadAllContributors ( ) {
101112 const developerLists = document . querySelectorAll ( ".developers-list" ) ;
102- const promises = Array . from ( developerLists ) . map ( devList => {
113+ const promises = Array . from ( developerLists ) . map ( ( devList ) => {
103114 const apiURL = devList . getAttribute ( "data-value" ) ;
104115 return setContributors ( apiURL , devList ) ;
105116 } ) ;
106117 await Promise . all ( promises ) ;
118+ renderCreators ( Array . from ( allContributors . values ( ) ) ) ;
107119}
108120
109121// Scroll-to-top functionality
110122function setupScrollToTop ( ) {
111- const toTopButton = document . getElementById ( ' toTop' ) ;
123+ const toTopButton = document . getElementById ( " toTop" ) ;
112124 if ( ! toTopButton ) return ;
113125
114- window . addEventListener ( ' scroll' , ( ) => {
126+ window . addEventListener ( " scroll" , ( ) => {
115127 if ( window . scrollY > 100 ) {
116- toTopButton . style . display = ' block' ;
128+ toTopButton . style . display = " block" ;
117129 } else {
118- toTopButton . style . display = ' none' ;
130+ toTopButton . style . display = " none" ;
119131 }
120132 } ) ;
121133
122- toTopButton . addEventListener ( ' click' , ( e ) => {
134+ toTopButton . addEventListener ( " click" , ( e ) => {
123135 e . preventDefault ( ) ;
124136 window . scrollTo ( {
125137 top : 0 ,
126- behavior : ' smooth'
138+ behavior : " smooth" ,
127139 } ) ;
128140 } ) ;
129141}
130142
143+ function initCarousel ( ) {
144+ const persons = document . querySelector ( ".persons" ) ;
145+ const nextBtn = document . querySelector ( ".carousel-btn.next" ) ;
146+ const prevBtn = document . querySelector ( ".carousel-btn.prev" ) ;
147+
148+ if ( ! persons || ! nextBtn || ! prevBtn ) return ;
149+
150+ nextBtn . addEventListener ( "click" , ( ) => {
151+ persons . scrollBy ( { left : 260 , behavior : "smooth" } ) ;
152+ } ) ;
153+
154+ prevBtn . addEventListener ( "click" , ( ) => {
155+ persons . scrollBy ( { left : - 260 , behavior : "smooth" } ) ;
156+ } ) ;
157+ }
158+
131159// Wait for DOM content to be loaded before executing scripts
132- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
133- setAuthors ( members_url ) . catch ( console . error ) ;
160+ document . addEventListener ( "DOMContentLoaded" , async ( ) => {
161+ //since the creators are hardcoded, we can skip this step for now
162+ // setAuthors(members_url).catch(console.error);
134163 loadAllContributors ( ) ;
164+ initCarousel ( ) ;
135165 setupScrollToTop ( ) ;
136- } ) ;
166+ } ) ;
0 commit comments