From 5358009e8e71182bcde1539b89936f2d73f04c7c Mon Sep 17 00:00:00 2001 From: somenath sarkar <43093724+somenath1435@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:06:26 +0530 Subject: [PATCH] JS code enhancement (#298) --- examples/demo.js | 16 ++++++++-------- examples/themes.js | 8 ++++---- examples/urlHash.js | 18 +++++++++--------- src/UI/contributorsUI.js | 4 ++-- src/UI/issuesUI.js | 4 ++-- src/scripts/chart.js | 10 +++++----- src/utils/contribsUtil/fetchAllRepoContribs.js | 6 +++--- src/utils/contribsUtil/storeAllContribsInDb.js | 2 +- src/utils/getRepoContributors.js | 12 ++++++------ 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/demo.js b/examples/demo.js index ad512bb9..731b8603 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', function () { /*Scroll to top when arrow up clicked BEGIN*/ $(window).scroll(function() { - var height = $(window).scrollTop(); + let height = $(window).scrollTop(); if (height > 100) { $('#back2Top').fadeIn(); } else { @@ -28,16 +28,16 @@ document.addEventListener('DOMContentLoaded', function () { e.preventDefault(); }) - var toolbox; + let toolbox; (function() { - var org = urlHash().getUrlHashParameter('o') || 'publiclab'; - var repo = urlHash().getUrlHashParameter('r') || 'plots2'; - var ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only'; - var candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate'; - var recencyLabel = urlHash().getUrlHashParameter('l') || 'week'; - var leaderboardState = urlHash().getUrlHashParameter('s') || 'week'; + let org = urlHash().getUrlHashParameter('o') || 'publiclab'; + let repo = urlHash().getUrlHashParameter('r') || 'plots2'; + let ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only'; + let candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate'; + let recencyLabel = urlHash().getUrlHashParameter('l') || 'week'; + let leaderboardState = urlHash().getUrlHashParameter('s') || 'week'; toolbox = CommunityToolbox(org, repo); if (repo === 'all') { diff --git a/examples/themes.js b/examples/themes.js index fa60c993..7224ff24 100644 --- a/examples/themes.js +++ b/examples/themes.js @@ -2,9 +2,9 @@ // NIGHT MODE LOGIC //=============================================================== $(document).ready(() => { - var body=document.querySelector('body'); - var toggleButton=document.getElementById('myonoffswitch'); - var toggle = localStorage.getItem('currentToggle'); + let body=document.querySelector('body'); + let toggleButton=document.getElementById('myonoffswitch'); + let toggle = localStorage.getItem('currentToggle'); // Sets images' theme accordingly when the page is loaded setTimeout(()=> { @@ -105,7 +105,7 @@ buttonClickCallbackNightTheme = (e) => { e.preventDefault(); setTimeout(() => { - var recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img"); + let recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img"); let check=localStorage.getItem('currentToggle'); let images = [...recentContribsSectionImgs ]; if(check==="night") { diff --git a/examples/urlHash.js b/examples/urlHash.js index d926c449..f101bc9b 100644 --- a/examples/urlHash.js +++ b/examples/urlHash.js @@ -1,16 +1,16 @@ function urlHash() { function getUrlHashParameter(param) { - var params = getUrlHashParameters(); + let params = getUrlHashParameters(); return params[param]; } function getUrlHashParameters() { - var sPageURL = window.location.hash; + let sPageURL = window.location.hash; if (sPageURL) sPageURL = sPageURL.split('#')[1]; - var pairs = sPageURL.split('&'); - var object = {}; + let pairs = sPageURL.split('&'); + let object = {}; pairs.forEach(function(pair, i) { pair = pair.split('='); if (pair[0] != '') object[pair[0]] = pair[1]; @@ -22,19 +22,19 @@ function urlHash() { // and transforms to: url.com#paramName=value¶mName1=value function setUrlHashParameters(params) { - var keys = Object.keys(params); - var values = Object.values(params); - var pairs = []; + let keys = Object.keys(params); + let values = Object.values(params); + let pairs = []; keys.forEach(function(key, i) { if (key != '') pairs.push(keys[i] + '=' + values[i]); }); - var hash = pairs.join('&'); + let hash = pairs.join('&'); window.location.hash = hash; } function setUrlHashParameter(param, value) { - var params = getUrlHashParameters(); + let params = getUrlHashParameters(); params[param] = value; setUrlHashParameters(params); diff --git a/src/UI/contributorsUI.js b/src/UI/contributorsUI.js index fe0a97da..e1e79da2 100644 --- a/src/UI/contributorsUI.js +++ b/src/UI/contributorsUI.js @@ -6,10 +6,10 @@ function insertContributors(AllContributors){ document.getElementById("spinner-icon").style.display = "none"; let totalContributors = 0; - var usernames = AllContributors.map(function getContributorUsername(c) { + let usernames = AllContributors.map(function getContributorUsername(c) { return `@${c.login}`; }); - var avatars = AllContributors.map(function getContributorAvatarURL(c) { + let avatars = AllContributors.map(function getContributorAvatarURL(c) { return ``; }); totalContributors += AllContributors.length; diff --git a/src/UI/issuesUI.js b/src/UI/issuesUI.js index 4384117a..66dd5f1f 100644 --- a/src/UI/issuesUI.js +++ b/src/UI/issuesUI.js @@ -3,7 +3,7 @@ var moment = require('moment'); function generateIssueHtml(title, body, githubUrl, repo) { - var repoName = githubUrl.split('/')[4], + let repoName = githubUrl.split('/')[4], repoUrl = githubUrl.split('/').slice(0, 5).join('/'), html = '