JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<html>
<head>
<title>Barbell Calculator</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
</head>
<body>
<div class="main">
<h1>Barbell Calculator</h1>
<div class="plates-form">
<div class="plates-form--content" style="display: none;">
<div class="input-area">
<h2 class="input-head inline">Bar</h2>
<label for="bar">Weight</label>:
<input type="number" id="bar" value="45"> Lbs
</div>
<div class="input-area">
<h2 class="input-head">Plates</h2>
<div class="w-50">
<label for="plate-45">45</label>:
<input class="plate-calc" type="number" id="plate-45" data-plate="45" value="">
<label for="plate-35">35</label>:
<input class="plate-calc" type="number" id="plate-35" data-plate="35" value="">
</div>
<div class="w-50">
<label for="plate-25">25</label>:
<input class="plate-calc" type="number" id="plate-25" data-plate="25" value="">
<label for="plate-10">10</label>:
<input class="plate-calc" type="number" id="plate-10" data-plate="10" value="">
</div>
<div class="w-50">
<label for="plate-5">5</label>:
<input class="plate-calc" type="number" id="plate-5" data-plate="5" value="">
<label for="plate-2-5">2.5</label>:
<input class="plate-calc" type="number" id="plate-2-5" data-plate="2-5" value="">
</div>
</div>
</div>
<button class="hide hide-plates">Show Weight Inventory</button>
</div>
<div class="plates">
<div class="total-form">
<div class="total">
<p>Plate Weight: <span class="total-amount" id="total-available-amount-plates"></span> Lbs</p>
<p>Total Lift Max: <span class="total-amount" id="total-available-amount-all"></span> Lbs</p>
</div>
<div id="total-error" class="error" style="display: none;">Not enough weight available.</div>
<div id="min-error" style="display: none;">Please enter an amount over bar weight.</div>
<h2 class="input-head">Calculator</h2>
<label for="total">Amount</label>:
<input class="lift-input" type="number" id="total">
</div>
<div>Actual: <span class="total-amount" id="actual-amount"></span> Lbs</div>
<div>Remain: <span class="total-amount" id="amount-remain"></span> Lbs</div>
<div>Recommended: <span class="total-amount" id="rounded-amount"> Lbs</span></div>
<div class="bar">
<div class="side left-side">
</div>
<div class="side right-side">
</div>
</div>
<div class="content">
<h2 class="info-head"> Plates Per Side </h2>
<ul class="info">
<li class="plate-45">45 lbs: <span></span></li>
<li class="plate-35">35 lbs: <span></span></li>
<li class="plate-25">25 lbs: <span></span></li>
<li class="plate-10">10 lbs: <span></span></li>
<li class="plate-5">5 lbs: <span></span></li>
<li class="plate-2-5">2.5 lbs: <span></span></li>
</ul>
</div>
</div>
</div>
</body>
</html>
body {
height: auto;
}
.total-form {}
.main {
max-width: 960px;
}
input[type='text'],
input[type='number'],
textarea {
font-size: 16px;
}
.error {
color: red;
}
.hide-plates {
border-radius: 5px;
border: 2px solid #ccc;
}
.hide-plates.hide {
background-color: #333;
color: #fff;
}
.hide-plates.show {
background-color: #0ae;
color: #eee;
}
.total,
.input-area {
padding: 0.5em 0;
margin: auto;
}
.total {
margin: 1em auto;
}
.total-amount {
font-size: 1.05em;
font-weight: bold;
}
.input-head {
font-size: 1.1em;
padding: 0.25em 0;
}
.plates, .plates-form {
width: 100%;
}
.plates-form--content {
display: flex;
width: 100%;
}
.remainder-1 {
background-color: #fee;
}
.remainder-2 {
background-color: #fcc;
}
.remainder-3 {
background-color: #faa;
}
.remainder-4 {
background-color: #f88;
}
.w-50 {
width: 100%;
display: flex;
margin-bottom: 0.5em;
}
.w-50 label {
width: 2em;
margin: auto;
text-align: right;
}
.plates-form input {
width: 40px;
margin: auto;
}
.inline {
display: inline-block;
}
.bar {
position: relative;
max-width: 400px;
background-color: #333;
height: 4px;
margin: 95px 0px;
}
.bar .side {
position: absolute;
width: 40%;
}
.bar .left-side {
left: 0;
}
.bar .left-side span {
float: right;
}
.bar .right-side span {
float: left;
}
.bar .right-side {
right: 0;
}
.bar .side span {
width: 8%;
border: 1px solid #000;
margin-left: 1px;
}
.bar .plate-45 {
height: 90px;
background-color: #333;
margin-top: -43px;
border: 1px solid #000;
}
.bar .plate-35 {
height: 70px;
margin-top: -33px;
background-color: #666;
border: 1px solid #000;
}
.bar .plate-25 {
height: 50px;
margin-top: -23px;
background-color: #999;
border: 1px solid #000;
}
.bar .plate-10 {
height: 25px;
margin-top: -10px;
background-color: #ccc;
border: 1px solid #000;
}
.bar .plate-5 {
height: 20px;
margin-top: -6px;
background-color: #eee;
border: 1px solid #000;
}
.bar .plate-2-5 {
height: 10px;
margin-top: -3px;
background-color: #fff;
border: 1px solid #000;
}
.info {
display: block;
padding: 0;
margin: 0 1em;
list-style: none;
}
.info-head {
margin-top: 1em;
}
.info li {
padding-left: 0.5em;
padding-bottom: 0.5em;
font-size: 1.1em;
}
.info li span {
font-weight: bold;
font-size: 0.95em;
}
.content {
clear: both;
display: block;
width: 100%;
}
workoutCalculator = (function() {
var barWeight = 45,
plates = [45, 35, 25, 10, 5, 2.5],
// Default invetory, should be overriden by local storage.
plateObject = {
'45': 4,
'35': 4,
'25': 4,
'10': 4,
'5': 4,
'2-5': 4
},
total = 0,
sidePlates = [];
$('document').ready(function() {
if (localStorage) {
var LSPlates = localStorage.getItem('plateWeight');
if (LSPlates) {
plateObject = JSON.parse(LSPlates);
}
}
calculatePlateWeight();
$('.calc-plates').on('click', calculatePlateWeight);
$('.hide-plates').on('click', togglePlateCalc);
});
function togglePlateCalc() {
$('.plates-form--content').toggle();
$('.hide-plates').toggleClass('hide show');
return false;
}
$('.plate-calc').on('change', function(e) {
$plate = $(e.target);
plateObject[$plate.data('plate')] = $plate.val();
calculatePlateWeight();
if (localStorage) {
localStorage.setItem('plateWeight', JSON.stringify(plateObject));
}
});
function calculatePlateWeight() {
var total = null,
barWeight = $('#bar').val() * 1;
_.each(plateObject, function(value, key) {
var weight = key * 1;
$('#plate-' + key).val(value);
if (key === '2-5') {
weight = 2.5;
}
total += weight * value;
});
$("#total-available-amount-plates").text(total);
$("#total-available-amount-all").text(total + barWeight);
window.totalLiftAmount = total + barWeight;
window.barWeight = barWeight;
}
$('#total').on('keyup', function(e, v) {
var weight = $(e.target).val();
if ( weight > (window.totalLiftAmount)) {
$("#total-error").show();
return false;
} else {
$("#total-error").hide();
}
if ( weight < (window.barWeight)) {
$("#min-error").show();
return false;
} else {
$("#min-error").hide();
}
sidePlates = [];
getWeights(weight);
$('.bar .side').html('');
_.each(sidePlates, function(plate) {
var plateClass = 'plate-' + plate.weight.toString().replace('.', '-');
var $li = $('.' + plateClass),
$barLeft = $('.bar .left-side');
$barRight = $('.bar .right-side');
if (plate.multiplier > 0) {
$li.show();
$li.find('span').text(plate.multiplier);
for (i = 0; i < plate.multiplier; i++) {
$barLeft.append('<span class="' + plateClass + '">')
$barRight.append('<span class="' + plateClass + '">');
}
} else {
$li.hide();
}
});
});
getRealPlateKey = function(key) {
return key.toString().replace('.', '-');
}
getWeights = function(weight) {
$('.bar .side').html('Loading');
var plateWeight = weight - barWeight,
sideWeight = plateWeight / 2,
remain = sideWeight;
_.each(plates, function(plate) {
var num = 0,
iterationPlates = null,
plateWeightAvailable = plateObject[getRealPlateKey(plate)],
remainder;
if (plate <= remain && plateWeightAvailable > 0) {
num = _.parseInt(remain / plate);
if (num > (plateWeightAvailable / 2)) {
num = (plateWeightAvailable / 2);
}
remain -= (num * plate);
} else {
num = 0;
}
remainder = remain * 2;
if ((remainder + barWeight) > 0) {
var actual = weight - remainder;
$('#amount-remain').html(remainder).removeClass().addClass('remainder-' + remainder.toString());
$('#actual-amount').html(actual);
if (remainder > 2) {
$('#rounded-amount').html(actual*1 + 5);
} else {
$('#rounded-amount').html(actual);
}
}
iterationPlates = {
'weight': plate,
'multiplier': num
}
sidePlates.push(iterationPlates);
});
}
return {
getWeights
}
})();
Also see: Tab Triggers