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