1/*----------------------------------------------------*/ 2/* Quantity Buttons with Total Value Counter 3/* 4/* Author: Vasterad 5/* Version: 1.0 6/*----------------------------------------------------*/ 7 8jQuery(document).ready(function ($) { 9 function qtySum() { 10 // Get adults count from qtyInput 11 var tot = parseInt($('input[name="qtyInput"]').val()) || 0; 12 13 // Check if children input exists and add to total if it does 14 var $childrenInput = $('input[name="childrenQtyInput"]'); 15 if ($childrenInput.length > 0) { 16 tot += parseInt($childrenInput.val()) || 0; 17 } 18 19 var cardQty = $(".qtyTotal"); 20 cardQty.html(tot); 21 } 22 qtySum(); 23 24 $(".qtyButtons input").after('<div class="qtyInc"></div>'); 25 $(".qtyButtons input").before('<div class="qtyDec"></div>'); 26 27 $(".qtyDec, .qtyInc").on("click", function () { 28 var $button = $(this); 29 var oldValue = $button.parent().find("input").val(); 30 var max = $button.parent().find("input").data("max"); 31 var min = $button.parent().find("input").data("min"); 32 33 if ($button.hasClass("qtyInc")) { 34 // Get the panel and its max guests limit 35 var $panel = $button.closest(".panel-guests-dropdown"); 36 if ($panel.data("maxguests")) { 37 var maxGuests = parseInt($panel.data("maxguests")); 38 } else { 39 var maxGuests = 999; 40 } 41 42 // Calculate current total guests (adults + children) 43 var currentAdults = parseInt($('input[name="qtyInput"]').val()) || 0; 44 var currentChildren = 45 parseInt($('input[name="childrenQtyInput"]').val()) || 0; 46 var totalGuests = currentAdults + currentChildren; 47 48 // For adults or children, check if increasing would exceed maxGuests 49 var canIncrease = true; 50 if ( 51 $button 52 .parent() 53 .find("input") 54 .is('[name="qtyInput"], [name="childrenQtyInput"]') 55 ) { 56 canIncrease = totalGuests < maxGuests; 57 } 58 59 if (canIncrease) { 60 if (max) { 61 if (oldValue < max) { 62 var newVal = parseFloat(oldValue) + 1; 63 } else { 64 newVal = oldValue; 65 } 66 } else { 67 var newVal = parseFloat(oldValue) + 1; 68 } 69 } else { 70 newVal = oldValue; 71 } 72 } else { 73 var inputName = $button.parent().find("input").attr("name"); 74 if (min) { 75 if (oldValue > min) { 76 var newVal = parseFloat(oldValue) - 1; 77 } else { 78 newVal = oldValue; 79 } 80 } else { 81 if (inputName === "qtyInput") { 82 newVal = oldValue > 1 ? parseFloat(oldValue) - 1 : 1; 83 } else { 84 newVal = oldValue > 0 ? parseFloat(oldValue) - 1 : 0; 85 } 86 } 87 } 88 89 $button.parent().find("input").val(newVal).trigger("change");
90 qtySum(); 91 $(".qtyTotal").addClass("rotate-x"); 92 }); 93 94 // Total Value Counter Animation 95 function removeAnimation() { 96 $(".qtyTotal").removeClass("rotate-x"); 97 } 98 99 const counter = $(".qtyTotal"); 100 counter.on("animationend", removeAnimation); 101 102 // Adjusting Panel Dropdown Width 103 $(window).on("load resize", function () { 104 var panelTrigger = $(".booking-widget .panel-dropdown a"); 105 $(".booking-widget .panel-dropdown .panel-dropdown-content").css({ 106 width: panelTrigger.outerWidth(), 107 }); 108 }); 109});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.