Removed unused code
This commit is contained in:
parent
a261c43119
commit
88efebc971
2 changed files with 38 additions and 85 deletions
68
dist/js/bootstrap-plusmin.js
vendored
68
dist/js/bootstrap-plusmin.js
vendored
|
@ -1,68 +0,0 @@
|
||||||
$('.btn-number').click(function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
let fieldName = $(this).attr('data-field');
|
|
||||||
let type = $(this).attr('data-type');
|
|
||||||
const input = $("input[name='" + fieldName + "']");
|
|
||||||
const currentVal = parseInt(input.val());
|
|
||||||
|
|
||||||
if (!isNaN(currentVal)) {
|
|
||||||
if (type === 'minus') {
|
|
||||||
if (currentVal > input.attr('min')) {
|
|
||||||
input.val(currentVal - 1).change();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.val() == input.attr('min')) {
|
|
||||||
$(this).attr('disabled', true);
|
|
||||||
}
|
|
||||||
} else if (type === 'plus') {
|
|
||||||
if (currentVal < input.attr('max')) {
|
|
||||||
input.val(currentVal + 1).change();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.val() == input.attr('max')) {
|
|
||||||
$(this).attr('disabled', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
input.val(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.input-number').focusin(function () {
|
|
||||||
$(this).data('oldValue', $(this).val());
|
|
||||||
}).change(function () {
|
|
||||||
minValue = parseInt($(this).attr('min'));
|
|
||||||
maxValue = parseInt($(this).attr('max'));
|
|
||||||
valueCurrent = parseInt($(this).val());
|
|
||||||
|
|
||||||
name = $(this).attr('name');
|
|
||||||
|
|
||||||
if (valueCurrent >= minValue) {
|
|
||||||
$(".btn-number[data-type='minus'][data-field='" + name + "']").removeAttr('disabled')
|
|
||||||
} else {
|
|
||||||
alert('Sorry, the minimum value was reached.');
|
|
||||||
$(this).val($(this).data('oldValue'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valueCurrent <= maxValue) {
|
|
||||||
$(".btn-number[data-type='plus'][data-field='" + name + "']").removeAttr('disabled')
|
|
||||||
} else {
|
|
||||||
alert('Sorry, the maximum value was reached.');
|
|
||||||
$(this).val($(this).data('oldValue'));
|
|
||||||
}
|
|
||||||
}).keydown(function (e) {
|
|
||||||
// Allow: backspace, delete, tab, escape, enter and .
|
|
||||||
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
|
|
||||||
// Allow: Ctrl+A
|
|
||||||
(e.keyCode === 65 && e.ctrlKey === true) ||
|
|
||||||
// Allow: home, end, left, right
|
|
||||||
(e.keyCode >= 35 && e.keyCode <= 39)) {
|
|
||||||
// let it happen, don't do anything
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Ensure that it is a number and stop the keypress
|
|
||||||
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
55
index.html
55
index.html
|
@ -67,7 +67,6 @@
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
|
||||||
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
|
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<script type="application/javascript" src="dist/js/bootstrap-plusmin.js"></script>
|
|
||||||
<script type="application/javascript" src="dist/js/calculator.js"></script>
|
<script type="application/javascript" src="dist/js/calculator.js"></script>
|
||||||
<script type="application/javascript" src="dist/js/beautify.js"></script>
|
<script type="application/javascript" src="dist/js/beautify.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -77,6 +76,7 @@
|
||||||
|
|
||||||
const item = $("#item");
|
const item = $("#item");
|
||||||
const itemCount = $("#itemcount");
|
const itemCount = $("#itemcount");
|
||||||
|
const itemCountButton = $('.btn-number');
|
||||||
const items = $("#items");
|
const items = $("#items");
|
||||||
|
|
||||||
const output = $("#content");
|
const output = $("#content");
|
||||||
|
@ -84,6 +84,43 @@
|
||||||
const copyButton = $("#copyButton");
|
const copyButton = $("#copyButton");
|
||||||
const downloadButton = $("#downloadButton");
|
const downloadButton = $("#downloadButton");
|
||||||
|
|
||||||
|
itemCountButton.click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
let fieldName = $(this).attr('data-field');
|
||||||
|
let type = $(this).attr('data-type');
|
||||||
|
const input = $("input[name='" + fieldName + "']");
|
||||||
|
const currentVal = parseInt(input.val());
|
||||||
|
|
||||||
|
if (!isNaN(currentVal)) {
|
||||||
|
if (type === 'minus') {
|
||||||
|
if (currentVal > input.attr('min')) {
|
||||||
|
input.val(currentVal - 1).change();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.val() == input.attr('min')) {
|
||||||
|
$(this).attr('disabled', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#iteminput" + currentVal).remove();
|
||||||
|
} else if (type === 'plus') {
|
||||||
|
if (currentVal < input.attr('max')) {
|
||||||
|
input.val(currentVal + 1).change();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.val() == input.attr('max')) {
|
||||||
|
$(this).attr('disabled', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.append("<div id=\"iteminput" + (currentVal + 1) + "\" class=\"mb-3 w-50\"><label for=\"item" + (currentVal + 1) + "\">Model for damage " + (currentVal + 1) + ":</label><input type=\"text\" class=\"form-control\" id=\"item" + (currentVal + 1) + "\" name=\"item" + (currentVal + 1) + "\" placeholder=\"cars/" + randomModel() + "\" required></div>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
input.val(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
item.change(function () {
|
item.change(function () {
|
||||||
if (this.value !== "") { //If value is not empty, show other options ...
|
if (this.value !== "") { //If value is not empty, show other options ...
|
||||||
formOptions.show();
|
formOptions.show();
|
||||||
|
@ -96,22 +133,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.btn-number').click(function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
//Get the item count and clicked type
|
|
||||||
const fieldName = $(this).attr('data-field');
|
|
||||||
const type = $(this).attr('data-type');
|
|
||||||
const input = $("input[name='" + fieldName + "']");
|
|
||||||
const currentVal = parseInt(input.val());
|
|
||||||
|
|
||||||
if (type === 'minus') { //If removed one, remove latest input.
|
|
||||||
$("#iteminput" + (currentVal + 1)).remove();
|
|
||||||
} else if (type === 'plus') { //If added one, append new input.
|
|
||||||
items.append("<div id=\"iteminput" + currentVal + "\" class=\"mb-3 w-50\"><label for=\"item" + currentVal + "\">Model for damage " + currentVal + ":</label><input type=\"text\" class=\"form-control\" id=\"item" + currentVal + "\" name=\"item" + currentVal + "\" placeholder=\"cars/" + randomModel() + "\" required></div>");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
form.on("submit", function(e){
|
form.on("submit", function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
Reference in a new issue