Your IP : 18.224.61.184


Current Path : /home/bitrix/ext_www/ballu.in.ua/about/js/
Upload File :
Current File : /home/bitrix/ext_www/ballu.in.ua/about/js/site.js

$(document).ready(function()
{
    initialize();
});

var window_was_resized = false, lines_were_painted = false;

function initialize()
{
    setTimeout(function() {
        // карусели
        $('.php-carousel-container--js').slick({
            dots: false,
            infinite: true,
            speed: 300,
            slidesToShow: 1,
            centerMode: true,
            variableWidth: true
        });

        $('.countdown--js').counterUp({
            delay: 300
            ,time: 2000
            //,offset: 30
            ,formatter: function (n) {
                return number_format(n, 0, '.', ' ');
            }
        });

    }, 500);

    var resizeTimer;

    var waypoint = new Waypoint({
        element: document.getElementById('popup-locations-id')
        ,handler: function(direction) {
            //console.log('Scrolled to waypoint!');
            // запускаем анимацию линий с городами мира
            paintLines();
        }
        ,offset: '10%'
    });

    $(window).on('resize', function(e) {
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(resizeWindow, 250);
    });
    resizeWindow();

    // .site-page-ul-slick--js
    /*
    $('.site-page-ul-slick--js').slick({
        dots: false,
        infinite: true,
        speed: 300,
        slidesToShow: 4,
        slidesToScroll: 4,
        responsive: [
            {
                breakpoint: 1280,
                settings: {
                    slidesToShow: 3,
                    slidesToScroll: 3,
                    infinite: true,
                }
            },{
                breakpoint: 1024,
                settings: {
                    slidesToShow: 2,
                    slidesToScroll: 2,
                    infinite: true,
                }
            },
            {
                breakpoint: 640,
                settings: {
                    slidesToShow: 1,
                    slidesToScroll: 1
                }
            },
            {
                breakpoint: 480,
                settings: {
                    slidesToShow: 1,
                    slidesToScroll: 1
                }
            }
            // You can unslick at a given breakpoint now by adding:
            // settings: "unslick"
            // instead of a settings object
        ]
    });
    */

    $('.text-animation-move--js').uniqueId().each(function() {
        var elId = $(this).attr('id');
        var waypoint = new Waypoint({
            element: document.getElementById(elId)
            ,handler: function(direction) {
                if ($('#'+this.element.id).hasClass('on')) {} else {
                    console.log('Scrolled to waypoint!');
                    $('#'+this.element.id).addClass('on');
                }
            }
            ,offset: '90%'
        });
    });

    $('.production-page .production-common-page .site-page-ul .site-page-li.title').on('click', function() {
        var a = $(this), p = a.parent();
        p.toggleClass('open');
        //console.log('resize mobile click menu');
        return false;
    });
}


function resizeWindow()
{
    var w = $(window).width();

    if (w < 1000)
    {
        // мобильно-плантештая версия
        $('.production-page .production-common-page .site-page-ul .site-page-li.title').on('click', function() {
            var a = $(this), p = a.parent();
            p.toggleClass('open');
            //console.log('resize mobile click menu');
            return false;
        });
    }

    // Run code here, resizing has "stopped"
    if (!window_was_resized)
    {
        window_was_resized = true;
    }
    else
    {
        if (lines_were_painted)
        {
            paintLines();
        }
    }

    if (w <= 1280) {
        $('.site-page-ul-slick--js').not('.slick-initialized').slick({
            dots: false,
            infinite: true,
            speed: 300,
            slidesToShow: 4,
            slidesToScroll: 4,
            responsive: [
                {
                    breakpoint: 1280,
                    settings: {
                        slidesToShow: 3,
                        slidesToScroll: 3,
                        infinite: true,
                    }
                },{
                    breakpoint: 1024,
                    settings: {
                        slidesToShow: 2,
                        slidesToScroll: 2,
                        infinite: true,
                    }
                },
                {
                    breakpoint: 640,
                    settings: {
                        slidesToShow: 1,
                        slidesToScroll: 1
                    }
                },
                {
                    breakpoint: 480,
                    settings: {
                        slidesToShow: 1,
                        slidesToScroll: 1
                    }
                }
                // You can unslick at a given breakpoint now by adding:
                // settings: "unslick"
                // instead of a settings object
            ]
        });
    } else {
        if ($('.site-page-ul-slick--js').hasClass('slick-initialized')) {
            $('.site-page-ul-slick--js').slick('unslick');
        }
    }

}


var superLines = [];

/**
 * Рисует линии к городам производства
 */
function paintLines()
{

    if ($('.site-city-canvas--js').length)
    {
        $('.site-city-canvas--js svg').remove();
        if (superLines.length == 0)
        {
            $('.site-city-canvas--js').each(function() {
                var d = $(this); dpath = d.data('path');
                var sl = new SuperLine(
                    d,
                    function() {
                        // анимировать появление элемента с городом
                        (function(){
                            if ($('.'+d.data('city')).hasClass('open'))
                            {

                            }
                            else
                            {
                                $('.'+d.data('city')).addClass('preopen');
                                setTimeout(function()
                                {
                                    $('.'+d.data('city')).removeClass('preopen').addClass('open');
                                }, 250);
                            }
                        })();
                    }
                    , 1000
                );
                superLines.push(sl);
            });
            //console.log('-');
        }

        //console.log('---');
        //console.log(superLines);
        for (var i = 0; i < superLines.length; i++)
        {
            var sl = superLines[i];
            sl.clear();
            sl.resize();
            sl.paint();
            if (i == superLines.length-1)
            {
                lines_were_painted = true;
                //console.log('lines_were_painted = true;')
            }
        }

    }

}

/**
 * Аналог PHP-функции number_format
 * @param number
 * @param decimals
 * @param dec_point
 * @param thousands_sep
 * @returns {string}
 */
function number_format(number, decimals, dec_point, thousands_sep) {
    var i, j, kw, kd, km;
    // очистка вводных значений
    if (isNaN(decimals = Math.abs(decimals))) {
        decimals = 2;
    }
    if (dec_point == undefined) {
        dec_point = ",";
    }
    if (thousands_sep == undefined) {
        thousands_sep = ".";
    }

    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

    if ((j = i.length) > 3) {
        j = j % 3;
    } else {
        j = 0;
    }

    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");

    return km + kw + kd;
};