Skip to content

Commit

Permalink
Remove unused Contributor Card code (nodejs#4310)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored Dec 21, 2021
1 parent 9546a9a commit c51dc7b
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 200 deletions.
15 changes: 0 additions & 15 deletions layouts/css/page-modules/_jsfoundation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
18 changes: 0 additions & 18 deletions layouts/css/page-modules/spinner.scss

This file was deleted.

1 change: 0 additions & 1 deletion layouts/css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion layouts/partials/blm-html-head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<link rel="dns-prefetch" href="https://fonts.googleapis.com">
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link rel="dns-prefetch" href="https://api.github.com">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600&amp;display=fallback">
<link rel="stylesheet" href="https://nodejs.org/static/css/styles.css">
Expand Down
15 changes: 0 additions & 15 deletions layouts/partials/contributor-card.hbs

This file was deleted.

1 change: 0 additions & 1 deletion layouts/partials/html-head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<link rel="dns-prefetch" href="https://fonts.googleapis.com">
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link rel="dns-prefetch" href="https://api.github.com">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600&display=fallback">
<link rel="stylesheet" href="/static/css/styles.css">
Expand Down
149 changes: 0 additions & 149 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c51dc7b

Please sign in to comment.