Skip to content
Permalink
Browse files

Add minification to JS, remove ES6 from JS

  • Loading branch information
zack committed Oct 14, 2018
1 parent 6d145c6 commit 86b6387584fe6286d7e956f9fc2f5ccd82967eb3
Showing with 46 additions and 45 deletions.
  1. +3 −0 Gruntfile.js
  2. +2 −5 package-lock.json
  3. +3 −1 package.json
  4. +38 −39 src/js/script.js
@@ -3,6 +3,9 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON('package.json'),
assets_inline: {
all: {
options: {
minify: true
},
files: {
"./dist/index.html": "./src/index.html"
}

Some generated files are not rendered by default. Learn more.

@@ -10,7 +10,9 @@
"author": "zack@youngren.io",
"license": "MIT",
"homepage": "https://rpe.youngren.io/",
"dependencies": {},
"dependencies": {
"uglify-js": "^3.4.9"
},
"devDependencies": {
"grunt": "^1.0.3",
"grunt-assets-inline": "^1.1.2"
@@ -1,5 +1,5 @@
(function() {
const RPEs = {
var RPEs = {
RPE: {
"10": {
REPS: {
@@ -85,16 +85,16 @@
};

function validateWeight(inputRow, errors) {
const input = inputRow.querySelector("input");
const inputValue = input.value;
var input = inputRow.querySelector("input");
var inputValue = input.value;
if (inputValue.length > 0 && inputValue <= 0) {
errors.push([input.getAttribute("id"), "Weight must be above 0"]);
}
}

function validateRPE(inputRow, errors) {
const input = inputRow.querySelector("input");
const inputValue = input.value;
var input = inputRow.querySelector("input");
var inputValue = input.value;
if (inputValue.length > 0 && inputValue < 6) {
errors.push([input.getAttribute("id"), "RPE must be 6 or above"]);
} else if (inputValue.length > 0 && inputValue > 10) {
@@ -103,8 +103,8 @@
}

function validateReps(inputRow, errors) {
const input = inputRow.querySelector("input");
const inputValue = input.value;
var input = inputRow.querySelector("input");
var inputValue = input.value;
if (inputValue.length > 0 && inputValue <= 0) {
errors.push([input.getAttribute("id"), "Reps must be above 0"]);
} else if (inputValue.length > 0 && inputValue > 12) {
@@ -116,9 +116,8 @@
}

function sanitizeAndGetInputErrors() {
const errors = [];
const inputRows = document.querySelectorAll(".input-row");
const inputRowsArr = [...inputRows];
var errors = [];
var inputRowsArr = [].slice.call(document.querySelectorAll(".input-row"));
inputRowsArr.forEach(function(inputRow) {
if (inputRow.className.indexOf("weight") > 0) {
validateWeight(inputRow, errors);
@@ -133,19 +132,20 @@
}

function clearAllErrors() {
const inputRows = document.querySelectorAll(".input-row");
const inputRowArr = [...inputRows];
inputRowArr.forEach(function(inputRow) {
var inputRowsArr = [].slice.call(document.querySelectorAll(".input-row"));
inputRowsArr.forEach(function(inputRow) {
inputRow.classList.remove("error");
inputRow.querySelector(".error").innerHTML = "";
});
}

function displayErrors(errors) {
errors.forEach(function([divName, errorText]) {
const inputRow = `.input-row.${divName}`;
errors.forEach(function(arr) {
var divName = arr[0];
var errorText = arr[1];
var inputRow = ".input-row." + divName;
document.querySelector(inputRow).classList.add("error");
document.querySelector(`${inputRow} .error`).innerHTML = errorText;
document.querySelector(inputRow + " .error").innerHTML = errorText;
});
}

@@ -161,37 +161,37 @@
}

function inputsEventHandler() {
const desiredRPE = document.querySelector("input#desired-rpe").value;
const desiredReps = document.querySelector("input#desired-reps").value;
const givenRPE = document.querySelector("input#given-rpe").value;
const givenReps = document.querySelector("input#given-reps").value;
const givenWeight = document.querySelector("input#given-weight").value;
var desiredRPE = document.querySelector("input#desired-rpe").value;
var desiredReps = document.querySelector("input#desired-reps").value;
var givenRPE = document.querySelector("input#given-rpe").value;
var givenReps = document.querySelector("input#given-reps").value;
var givenWeight = document.querySelector("input#given-weight").value;

clearAllErrors();
const errors = sanitizeAndGetInputErrors();
var errors = sanitizeAndGetInputErrors();

if (errors.length > 0) {
displayErrors(errors);
return false;
}

const haveAllGivens = givenWeight && givenRPE && givenReps;
var haveAllGivens = givenWeight && givenRPE && givenReps;

document.querySelector("input#desired-reps").disabled = !haveAllGivens;
document.querySelector("input#desired-rpe").disabled = !haveAllGivens;
const desiredWeightEl = document.querySelector("#solved-weight");
const e1RMEl = document.querySelector("#e1RM");
const ninetyFivePEl = document.querySelector("#ninetyFiveP");
const eightyFivePEl = document.querySelector("#eightyFiveP");
const eightyPEl = document.querySelector("#eightyP");
const seventyFivePEl = document.querySelector("#seventyFiveP");
const sixtyFivePEl = document.querySelector("#sixtyFiveP");
var desiredWeightEl = document.querySelector("#solved-weight");
var e1RMEl = document.querySelector("#e1RM");
var ninetyFivePEl = document.querySelector("#ninetyFiveP");
var eightyFivePEl = document.querySelector("#eightyFiveP");
var eightyPEl = document.querySelector("#eightyP");
var seventyFivePEl = document.querySelector("#seventyFiveP");
var sixtyFivePEl = document.querySelector("#sixtyFiveP");

if (haveAllGivens) {
const givenRPEDecimal = RPEs["RPE"][givenRPE]["REPS"][givenReps];
const estimated1RM = givenWeight / givenRPEDecimal;
var givenRPEDecimal = RPEs["RPE"][givenRPE]["REPS"][givenReps];
var estimated1RM = givenWeight / givenRPEDecimal;

const roundingValue = Number.parseFloat(document.querySelector("select#rounding").value);
var roundingValue = Number.parseFloat(document.querySelector("select#rounding").value);

e1RMEl.innerHTML = roundToFloat(estimated1RM, roundingValue);
ninetyFivePEl.innerHTML = roundToFloat(estimated1RM * 0.95, roundingValue);
@@ -201,7 +201,7 @@
sixtyFivePEl.innerHTML = roundToFloat(estimated1RM * 0.65, roundingValue);

if (desiredRPE && desiredReps) {
const desiredRPEDecimal = RPEs["RPE"][desiredRPE]["REPS"][desiredReps];
var desiredRPEDecimal = RPEs["RPE"][desiredRPE]["REPS"][desiredReps];
desiredWeightEl.innerHTML = roundToFloat(
parseInt(estimated1RM * desiredRPEDecimal), roundingValue
);
@@ -217,11 +217,10 @@
}
}

const inputs = document.querySelectorAll("input");
const inputsArr = [...inputs];
var inputsArr = [].slice.call(document.querySelectorAll("input"));
inputsArr.forEach(function(input) {
input.addEventListener("input", e => inputsEventHandler(), false);
input.addEventListener("input", inputsEventHandler, false);
});
const roundingSelect = document.querySelector("select#rounding");
roundingSelect.addEventListener("change", e => inputsEventHandler(), false);
var roundingSelect = document.querySelector("select#rounding");
roundingSelect.addEventListener("change", inputsEventHandler, false);
})();

0 comments on commit 86b6387

Please sign in to comment.
You can’t perform that action at this time.