Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-catalog/view/base/web/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-catalog/view/base/web/js/price-option-date.js
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

define([
    'jquery',
    'priceUtils',
    'priceOptions',
    'jquery-ui-modules/widget'
], function ($, utils) {
    'use strict';

    var globalOptions = {
            fromSelector: 'form',
            dropdownsSelector: '[data-role=calendar-dropdown]'
        },
        optionHandler = {};

    optionHandler.optionHandlers = {};

    /**
     * Custom handler for Date-with-Dropdowns option type.
     * @param  {jQuery} siblings
     * @return {Function} function that return object { optionHash : optionAdditionalPrice }
     */
    function onCalendarDropdownChange(siblings) {
        return function (element, optionConfig) {
            var changes = {},
                optionId = utils.findOptionId(element),
                overhead = optionConfig[optionId].prices,
                isNeedToUpdate = true,
                optionHash = 'price-option-calendar-' + optionId;

            siblings.each(function (index, el) {
                isNeedToUpdate = isNeedToUpdate && !!$(el).val();
            });

            overhead = isNeedToUpdate ? overhead : {};
            changes[optionHash] = overhead;

            return changes;
        };
    }

    /**
     * Returns number of days for special month and year
     * @param  {Number} month
     * @param  {Number} year
     * @return {Number}
     */
    function getDaysInMonth(month, year) {
        return new Date(year, month, 0).getDate();
    }

    /**
     * Adjusts the number of days in the day option element based on which month or year
     * is selected (changed). Adjusts the days to 28, 29, 30, or 31 typically.
     * @param {jQuery} dropdowns
     */
    function onDateChange(dropdowns) {
        var daysNodes,
            curMonth, curYear, expectedDays,
            options, needed,
            month = dropdowns.filter('[data-calendar-role=month]'),
            year = dropdowns.filter('[data-calendar-role=year]');

        if (month.length && year.length) {
            daysNodes = dropdowns.filter('[data-calendar-role=day]').find('option');

            curMonth = month.val() || '01';
            curYear = year.val() || '2000';
            expectedDays = getDaysInMonth(curMonth, curYear);

            if (daysNodes.length - 1 > expectedDays) { // remove unnecessary option nodes
                daysNodes.each(function (i, e) {
                    if (e.value > expectedDays) {
                        $(e).remove();
                    }
                });
            } else if (daysNodes.length - 1 < expectedDays) { // add missing option nodes
                options = [];
                needed = expectedDays - daysNodes.length + 1;

                while (needed--) { //eslint-disable-line max-depth
                    options.push(
                        '<option value="' + (expectedDays - needed) + '">' + (expectedDays - needed) + '</option>'
                    );
                }
                $(options.join('')).insertAfter(daysNodes.last());
            }
        }
    }

    $.widget('mage.priceOptionDate', {
        options: globalOptions,

        /**
         * Function-initializer of priceOptionDate widget
         * @private
         */
        _create: function initOptionDate() {
            var field = this.element,
                form = field.closest(this.options.fromSelector),
                dropdowns = $(this.options.dropdownsSelector, field),
                dateOptionId;

            if (dropdowns.length) {
                dateOptionId = this.options.dropdownsSelector + dropdowns.attr('name');

                optionHandler.optionHandlers[dateOptionId] = onCalendarDropdownChange(dropdowns);

                form.priceOptions(optionHandler);

                dropdowns.data('role', dateOptionId);
                dropdowns.on('change', onDateChange.bind(this, dropdowns));
            }
        }
    });

    return $.mage.priceOptionDate;
});

Spamworldpro Mini