AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.112
Web Server : Apache
System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/components/com_djcatalog2/themes/default/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/components/com_djcatalog2/themes/default/js/calculator.js
jQuery(document).ready(function () {


    let calculators = document.querySelectorAll('.djc2-item-calculator');
    if (calculators.length) {
        calculators.forEach(function (calculator) {


            console.log(calculator);


            let form = calculator.closest('form.djc_form_addtocart');
            let inputs = form.querySelectorAll('input');
            let checkboxes = form.querySelectorAll('checkbox');


            form.addEventListener('reload-price', function (e) {

                calculator.setAttribute('base-price', e.detail.price);
                e.preventDefault();
                reloadCalculator(calculator, form);
                return false;
            });


            inputs.forEach(function (input) {
                input.addEventListener('change', function (e) {
                    if (e.target.value) {
                        reloadCalculator(calculator, form);
                    }
                })

                input.addEventListener('keyup', function (e) {
                    if (e.target.value) {
                        reloadCalculator(calculator, form);
                    }
                })
            });


        });

    }

    function reloadCalculator(calculator, form) {
        let basePrice = parseFloat(calculator.getAttribute('base-price'));

        let szerokosc = parseFloat(form.querySelector('#calculator_szerokosc').value);
        let dlugosc = parseFloat(form.querySelector('#calculator_dlugosc').value);
        let calculator_oklejanie = form.querySelector('#calculator_oklejanie');

        const pattern = calculator.getAttribute('data-pattern');
        const validPattern = DJCalculatorReplaceTags(pattern, calculator);
        console.log(validPattern);
        let newPrice = eval(DJCalculatorReplaceTags(pattern, calculator));


        if (newPrice >= 0) {
            let priceWraper = document.querySelector('.djc_price .djc_price_value');

            if (priceWraper) {
                console.log(pattern);
                newPrice = newPrice.toFixed(2);
                const taxRate = parseFloat(calculator.getAttribute('data-taxrate'))/100;
                if (taxRate) {
                    const tax = calculateBasePrice(newPrice, taxRate);

                    const taxWrapper = document.querySelector('.djc_price_with_tax .djc_price_value');
                    if (taxWrapper && tax >= 0) {
                        taxWrapper.innerHTML = tax;
                    }


                }


                priceWraper.innerHTML = newPrice;
            }
        }

    }

    function DJCalculatorReplaceTags(str, calculator) {
        const tagRegex = /\[\[(.*?)\]\]/g;
        let match;
        let extractedText = [];

        // Loop through all matches of the regex pattern

        newStr = str;

        while ((match = tagRegex.exec(str)) !== null) {

            let tag = match[1];
            let value = 0;
            if (tag === 'price') {
                const basePrice = calculator.getAttribute('base-price');
                newStr = newStr.replace('[[' + tag + ']]', basePrice)
            } else {
                const input = calculator.querySelector('#calculator_' + tag);
                if(input.type == 'checkbox' ) {
                    if(input.checked) value = getIntegerValueFromInput(input);
                }else {
                    value = getIntegerValueFromInput(input);
                }

            }

            newStr = newStr.replace('[[' + tag + ']]', value)
        }

        return newStr;
    }

    function calculateBasePrice(totalPrice, VAT) {
        // Check if the inputs are valid
        if (totalPrice < 0 || VAT < 0) {
            throw new Error("Total price and VAT rate must be non-negative.");
        }

        // Calculate the base price
        const basePrice = totalPrice / (1 + VAT);

        // Round the base price to two decimal places
        const roundedBasePrice = Math.round(basePrice * 100) / 100;

        // Return the base price
        return totalPrice -  roundedBasePrice.toFixed(2);
    }


    function getIntegerValueFromInput(inputElement) {
        const value = inputElement.value.trim();
        const integerValue = parseInt(value, 10);

        if (isNaN(integerValue)) {
            return 0;
        }

        return integerValue;
    }

    document.formvalidator.setHandler('minValue', function (value, elem) {

        let minValue = elem.getAttribute('data-min');
        let maxValue = elem.getAttribute('data-max');
        let isValid = (parseFloat(minValue) <= parseFloat(value)) && (parseFloat(maxValue) >= parseFloat(value));

        if (!isValid) {
            let label = document.querySelector('label[for="' + elem.getAttribute('id') + '"] .djcx-label-value');
            alert("Prawidłowy zakres wartości dla pola " + label.innerHTML + " to " + minValue + "-" + maxValue);
        }

        return isValid;
    });
    document.formvalidator.setHandler('maxValue', function (value, elem) {


        let minValue = elem.getAttribute('data-max');
        let isValid = parseFloat(value) < parseFloat(minValue);

        console.log(minValue, value);


        if (!isValid) {
            let label = document.querySelector('label[for="' + elem.getAttribute('id') + '"] .djcx-label-value');
            alert("Maksymalna wartość dla pola " + label.innerHTML + " to " + minValue);
        }

        return isValid;
    });



});

Anon7 - 2022
AnonSec Team