From c51dc7bc77227d37db15bd1352aee0d7b39cff1d Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 21 Dec 2021 08:49:48 +0200 Subject: [PATCH] Remove unused Contributor Card code (#4310) --- layouts/css/page-modules/_jsfoundation.scss | 15 -- layouts/css/page-modules/spinner.scss | 18 --- layouts/css/styles.scss | 1 - layouts/partials/blm-html-head.hbs | 1 - layouts/partials/contributor-card.hbs | 15 -- layouts/partials/html-head.hbs | 1 - static/js/main.js | 149 -------------------- 7 files changed, 200 deletions(-) delete mode 100644 layouts/css/page-modules/spinner.scss delete mode 100644 layouts/partials/contributor-card.hbs diff --git a/layouts/css/page-modules/_jsfoundation.scss b/layouts/css/page-modules/_jsfoundation.scss index 8b950eca5702c..959c9c6aee557 100644 --- a/layouts/css/page-modules/_jsfoundation.scss +++ b/layouts/css/page-modules/_jsfoundation.scss @@ -24,21 +24,6 @@ margin-left: auto; } -.thanking-contributor { - max-width: 300px; - display: flex; - align-items: center; - padding: .5em 1em; - margin-top: 1em; - border: 1px solid $white; - border-radius: 3px; - - img { - border-radius: 50%; - margin-right: 1em; - } -} - .help { margin-top: 3em; width: 40%; diff --git a/layouts/css/page-modules/spinner.scss b/layouts/css/page-modules/spinner.scss deleted file mode 100644 index b3756d56dc702..0000000000000 --- a/layouts/css/page-modules/spinner.scss +++ /dev/null @@ -1,18 +0,0 @@ -// borrowed from Bootstrap -@keyframes spinner-border { - to { - transform: rotate(360deg); - } -} - -.spinner-border { - box-sizing: border-box; - display: inline-block; - width: 2rem; - height: 2rem; - vertical-align: text-bottom; - border: .25em solid currentColor; - border-right-color: transparent; - border-radius: 50%; - animation: spinner-border .75s linear infinite; -} diff --git a/layouts/css/styles.scss b/layouts/css/styles.scss index 21066a2a7cb7c..ba0757fcf5666 100644 --- a/layouts/css/styles.scss +++ b/layouts/css/styles.scss @@ -22,7 +22,6 @@ @import "page-modules/prev-next-navigation"; @import "page-modules/release-schedule"; @import "page-modules/resources"; -@import "page-modules/spinner"; @import "vendor/prism-tomorrow"; article a { diff --git a/layouts/partials/blm-html-head.hbs b/layouts/partials/blm-html-head.hbs index 6751032c751b3..c57af762c8dd2 100644 --- a/layouts/partials/blm-html-head.hbs +++ b/layouts/partials/blm-html-head.hbs @@ -4,7 +4,6 @@ - diff --git a/layouts/partials/contributor-card.hbs b/layouts/partials/contributor-card.hbs deleted file mode 100644 index ea68ef996eb92..0000000000000 --- a/layouts/partials/contributor-card.hbs +++ /dev/null @@ -1,15 +0,0 @@ -
- -
- Loading... -
- -
- -

- Thank you username for being a Node.js contributor - - 0 contributions - -

-
diff --git a/layouts/partials/html-head.hbs b/layouts/partials/html-head.hbs index 3d96d8c97c38e..46917142e0c1e 100644 --- a/layouts/partials/html-head.hbs +++ b/layouts/partials/html-head.hbs @@ -4,7 +4,6 @@ - diff --git a/static/js/main.js b/static/js/main.js index 499797d4bbccf..3d99d34e9b0fc 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -91,156 +91,7 @@ window.scrollTo(0, 0); }); })(); -(function () { - var contributorCard = document.querySelector('.contributor-card'); - - if (!contributorCard) { - return; - } - - var contributorAvatar = contributorCard.querySelector('#contributor-avatar'); - var contributorUsername = contributorCard.querySelector( - '#contributor-username' - ); - var contributorContributions = contributorCard.querySelector( - '#contributor-contributions' - ); - var loadingSpinner = contributorCard.querySelector('.spinner-border'); - - if (window.IntersectionObserver) { - var observer = new window.IntersectionObserver( - function (entries) { - entries.forEach(function (entry) { - if (entry.intersectionRatio > 0.5) { - // In viewport, fetch a random contributor - fetchRandomContributor(); - - observer.unobserve(entry.target); - } - }); - }, - { threshold: 0.5 } - ); - - observer.observe(document.querySelector('footer')); - } else { - // Does not support IntersectionObserver - fetchRandomContributor(); - } - - function fetchRandomContributor() { - var maxContributors; - var fetchDate; - var needToRefetch = false; - - if (window.localStorage) { - maxContributors = window.localStorage.getItem('max_contributors'); - fetchDate = parseInt(window.localStorage.getItem('fetch_date'), 10); - } - - // If fetch date is a month old (2592000000 ms === 30 days) - if (Date.now() - fetchDate >= 2592000000) { - needToRefetch = true; - } - - // If localStorage and data is less than 1 month old, fetch 1 time - if (maxContributors && !needToRefetch) { - getContributor( - Math.floor(Math.random() * Math.floor(parseInt(maxContributors))) + 1 - ); - } else { - getMaxContributors(function (randomPage, lastPage) { - getContributor(randomPage); - - if (window.localStorage) { - window.localStorage.setItem('max_contributors', lastPage); - } - }); - } - } - - function getMaxContributors(callback) { - var xhr = new window.XMLHttpRequest(); - xhr.open( - 'GET', - 'https://api.github.com/repos/nodejs/node/contributors?per_page=1', - true - ); - - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - // Get Headers Links last page to generate a random contributor - var links = linkParser(xhr.getResponseHeader('Link')); - var randomPage = - Math.floor( - Math.random() * Math.floor(parseInt(links.last.page, 10)) - ) + 1; - - if (window.localStorage) { - window.localStorage.setItem('fetch_date', Date.now()); - } - callback(randomPage, links.last.page); - } else { - return contributorCard.parentNode.removeChild(contributorCard); - } - } - }; - - xhr.send(); - } - - function getContributor(randomPage) { - var xhr = new window.XMLHttpRequest(); - xhr.open( - 'GET', - 'https://api.github.com/repos/nodejs/node/contributors?per_page=1&page=' + - randomPage, - true - ); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - var contributor = JSON.parse(xhr.responseText)[0]; - - // Remove loading spinner and show avatar - loadingSpinner.parentNode.removeChild(loadingSpinner); - contributorAvatar.classList.remove('hidden'); - // Set new values - contributorAvatar.src = contributor.avatar_url + '&s=80'; - contributorAvatar.parentElement.href = contributor.html_url; - contributorUsername.textContent = contributor.login; - contributorUsername.href = contributor.html_url; - contributorContributions.textContent = - contributor.contributions + ' contributions'; - contributorContributions.parentElement.href = - 'https://github.com/nodejs/node/commits?author=' + - contributor.login; - } else { - return contributorCard.parentNode.removeChild(contributorCard); - } - } - }; - - xhr.send(); - } - - function linkParser(linkHeader) { - var regex = /<([^?]+\?per_page=1&[a-z]+=([\d]+))>;[\s]*rel="([a-z]+)"/g; - var array = []; - var object = {}; - - while ((array = regex.exec(linkHeader)) !== null) { - object[array[3]] = { - url: array[1], - page: array[2] - }; - } - - return object; - } -})(); (function () { 'use strict'; var userAgent = navigator.userAgent;