now using new plusminusbutton.js
parent
675260272f
commit
65592d8ffc
|
@ -1,37 +1,89 @@
|
|||
jQuery(document).ready(function(){
|
||||
// This button will increment the value
|
||||
$('[data-quantity="plus"]').click(function(e){
|
||||
// Stop acting like a button
|
||||
e.preventDefault();
|
||||
// Get the field name
|
||||
fieldName = $(this).attr('data-field');
|
||||
// Get its current value
|
||||
var currentVal = parseInt($('input[name='+fieldName+']').val());
|
||||
// If is not undefined
|
||||
if (!isNaN(currentVal)) {
|
||||
// Increment
|
||||
$('input[name='+fieldName+']').val(currentVal + 1);
|
||||
} else {
|
||||
// Otherwise put a 0 there
|
||||
$('input[name='+fieldName+']').val(0);
|
||||
}
|
||||
});
|
||||
// This button will decrement the value till 0
|
||||
$('[data-quantity="minus"]').click(function(e) {
|
||||
// Stop acting like a button
|
||||
e.preventDefault();
|
||||
// Get the field name
|
||||
fieldName = $(this).attr('data-field');
|
||||
// Get its current value
|
||||
var currentVal = parseInt($('input[name='+fieldName+']').val());
|
||||
// If it isn't undefined or its greater than 0
|
||||
if (!isNaN(currentVal) && currentVal > 0) {
|
||||
// Decrement one
|
||||
$('input[name='+fieldName+']').val(currentVal - 1);
|
||||
} else {
|
||||
// Otherwise put a 0 there
|
||||
$('input[name='+fieldName+']').val(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
var inputNumber = document.getElementsByClassName('input-group-field');
|
||||
|
||||
if (window.location.pathname.includes("/warenkorb.html")) {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
$(window).on('load',function() {
|
||||
for(var y = 0;y<inputNumber.length;y++)
|
||||
{
|
||||
showValue(inputNumber[y]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var minusButton = document.getElementsByClassName("fa fa-minus");
|
||||
|
||||
var plusButton = document.getElementsByClassName("fa fa-plus");
|
||||
|
||||
|
||||
//Dieser Code Block gehört zur Warenkorb Datei
|
||||
for(var i = 0;i<plusButton.length;i++)
|
||||
{
|
||||
|
||||
var button = plusButton[i]
|
||||
|
||||
button.addEventListener('click', incrmenetValue)
|
||||
|
||||
|
||||
}
|
||||
|
||||
for(var j = 0;j<minusButton.length;j++)
|
||||
{
|
||||
var button1 = minusButton[j]
|
||||
|
||||
button1.addEventListener('click', decrmenetValue)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
//<input class="input-group-field" type="number" name="quantity" value="1">
|
||||
//var addItemButton = document.getElementsByClassName("input-group-field");
|
||||
|
||||
function showValue(event)
|
||||
{
|
||||
|
||||
var shopItem = event.parentElement.parentElement.parentElement
|
||||
|
||||
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
|
||||
var getValue = localStorage.getItem(title) || 0;
|
||||
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
|
||||
|
||||
}
|
||||
|
||||
function incrmenetValue(event)
|
||||
{
|
||||
|
||||
|
||||
var buttony = event.target
|
||||
var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
|
||||
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
|
||||
var getValue= localStorage.getItem(title) || 0;
|
||||
// var getValue = shopItem.getElementsByClassName('input-group-field')[0].value;
|
||||
if(getValue < 10){
|
||||
getValue++;
|
||||
}
|
||||
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
|
||||
localStorage.setItem(title, getValue)
|
||||
|
||||
|
||||
}
|
||||
function decrmenetValue(event)
|
||||
{
|
||||
var buttony = event.target
|
||||
var shopItem = buttony.parentElement.parentElement.parentElement.parentElement.parentElement
|
||||
var title = shopItem.getElementsByTagName('h3')[0].innerHTML
|
||||
var getValue= localStorage.getItem(title) || 0;
|
||||
if(getValue > 0){
|
||||
getValue--;
|
||||
}
|
||||
shopItem.getElementsByClassName('input-group-field')[0].value = getValue;
|
||||
localStorage.setItem(title, getValue)
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue