base.js 2.21 KiB
$(function() {
    function scrollTo(top, duration) {
        top = top || 0;
        duration = duration || 1000;
        $('html,body').stop().animate({
            scrollTop: top
        }, duration);
    const $folder = $('[data-role="folder"]');
    $folder
        .on('click', '[data-role="folder-btn"]', function() {
            const $btn = $(this);
            const $parent = $btn.parents('[data-role="folder"]');
            const $body = $('[data-role="folder-body"]', $parent);
            $btn.toggleClass('open');
            if ($btn.hasClass('open')) {
                $body.slideDown(300);
            } else {
                $body.slideUp(300);
            return false;
        });
    const $anchor = $('[data-role="scroll-to-anchor"]');
    $anchor
        .on('click', function() {
            const $target = $($(this).attr('href'));
            if ($target.length) {
                const top = $target.offset().top;
                scrollTo(top);
                return false;
        });
    const $pSlider = $('#photo-slider');
    if ($pSlider.length) {
        $pSlider.slick({
            prevArrow:  '<div class="slider__prev"></div>',
            nextArrow:  '<div class="slider__next"></div>',
            responsive: [
                    breakpoint: 1200,
                    settings:   {
                        arrows: false
        });
    const $modal = $('#modal');
    $('[data-role="open-popup"]')
        .on('click', function() {
            const $target = $($(this).data('target'));
            if ($target.length) {
                $target.show();
                $('body,html').css('overflow', 'hidden');
                $modal.fadeIn(300);
                return false;
        });
    $('[data-role="close-popup"]')
        .on('click', function() {
            $modal.fadeOut(300, function() {
                $('.popup').hide();
                $('body,html').css('overflow', 'auto');
            });
            return false;
}); $('#popup') .on('click', function(e) { e.stopPropagation(); }); console.log('Document ready'); });