{"size": 6353, "ext": "js", "max_stars_repo_path": "src/HCMS.Web/Themes/hayat-refactor/js/newScroll.js", "max_stars_repo_name": "m-esm/HCMS", "max_stars_repo_stars_event_min_datetime": "2017-12-26T13:01:07.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-06T19:02:31.000Z", "max_issues_repo_path": "src/HCMS.Web/Themes/hayat-refactor/js/newScroll.js", "max_issues_repo_name": "m-esm/HCMS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/HCMS.Web/Themes/hayat-refactor/js/newScroll.js", "max_forks_repo_name": "m-esm/HCMS", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.3971291866, "max_line_length": 107, "alphanum_fraction": 0.5121989611}
﻿/// <reference path="../lib/jquery/3.1.1/jquery3-1-1.js" />
var busy = false;

$(function () {

    var onHashArtChange = function () {
        if (!busy)
            changeArticlePage($(window.location.hash.toLowerCase()), "right");

    };

    if ($('article.page-child').first().attr('id') == undefined)
        return;

    if (window.location.hash == undefined || $(window.location.hash).length == 0)
    {
        var _first = $('article.page-child').first();

        window.location.hash = _first.attr('id');


        if (!$(_first).parent('section.page').hasClass('page-active'))
        {
            $(_first).parent('section.page').addClass('page-active')
            $(_first).addClass('page-active');
        }
        console.log($(_first).parent('section.page'));

    }
    else {
        if ($('section' + window.location.hash).length > 0) {
            if (!$('section' + window.location.hash).hasClass('page-active'))
                $('section' + window.location.hash).addClass('page-active')


            $('section' + window.location.hash + ' article').first().addClass('page-active');
        } else {
            if (!$(window.location.hash).hasClass('page-active'))
                $(window.location.hash).addClass('page-active');

            if(!$(window.location.hash).parent('section').hasClass('page-active'))
                $(window.location.hash).parent('section').addClass('page-active')
        }
      
    }
  


    $(document).keydown(function (e) {
        switch (e.which) {
            case 37:
                changeArticlePage(false, 'left');
                break;
            case 38:
                changeArticlePage(false, 'up');
                break;
            case 39:
                changeArticlePage(false, 'right');
                break;
            case 40:
                changeArticlePage(false, 'down');
                break;

            default: return; // exit this handler for other keys
        }
        e.preventDefault(); // prevent the default action (scroll / move caret)
    });

    $(window).scrollTop(0);


    $("body").swipe({
        //Generic swipe handler for all directions
        swipeStatus: function (e, phase, direction, duration, distance, fingerCount) {
            if (phase == "move" || phase == "start") {
                var $target = e.target.nodeName;
                if ($target.toLowerCase() === 'input') {
                    return false;
                } else {
                    if (duration > 30) {
                        //if ($(e.target).parents().hasClass('cscroll') || $(e.target).hasClass('cscroll'))
                        //    return;
                        changeArticlePage(false, direction == "left" ? "right" : "left");
                    }

                }
            }
        },
        excludedElements: "label, button, input, select, textarea, .noSwipe"
        //swipe: function (e, direction, distance, duration, fingerCount, fingerData) {
        //    console.log(e);
        //    if ($(e.target).parents().hasClass('cscroll') || $(e.target).hasClass('cscroll'))
        //        return;
        //    changePage(false, direction == "up" ? "down" : "up");

        //}
    });

    $(window).bind('hashchange', onHashArtChange);

});

var changeArticlePage = function (nextArticle, mode) {
    
    if (nextArticle)
        if (nextArticle.attr("id") != undefined)
            if ($('article[id=' + nextArticle.attr("id") + ']').length == 0)
                return;

    if (busy)
        return;

    busy = true;

    setTimeout(function () {
        busy = false;
    }, 1000);


    if ($('section.page-active article.page-child.page-active').length == 0) {
        var currentArticle = $('section.page-active article.page-child')[0];
        $(currentArticle).addClass('page-active');
    }

    //var currentArticle = $('article.page-child.page-active');
    var currentArticle = $('section.page-active article.page-child.page-active');

    if (!nextArticle)
        nextArticle = currentArticle.next('section.page-active article.page-child');
    //else
    //    if (currentArticle.attr('id') === nextArticle.attr('id'))
    //        return;

    var prevArticle = currentArticle.prev('article.page-child');
    setTimeout(function () {

        $('[data-aos]', nextArticle).addClass('aos-animate');
        $('[data-aos]', prevArticle).addClass('aos-animate');

    }, 1000);

    if (window.location.pathname !== "/") {

        $('header').addClass('navhide');
        $('.homelogo').fadeIn();

    }


    if (mode === "left") {
        if (prevArticle.length > 0) {

            currentArticle
              .addClass('page-deactive-top')
              .removeClass('page-active');

            prevArticle.parent('section.page')
                .removeClass('page-deactive-top')
                .removeClass('page-deactive-down')
                .addClass('page-active');

            prevArticle
                .addClass('page-active')
                .removeClass('page-deactive-top')
                .removeClass('page-deactive-down')

            if (window.location.pathname === "/")
                if (!prevArticle.parent('section.page').hasClass('page-slider'))
                    $('header').addClass('stick');


            if (prevArticle.attr('id'))
                window.location.hash = prevArticle.attr('id');
        } else {
            //back to main page
            window.location.href = "/#blocks";

        }
    }
    if (mode === "right") {
        if (nextArticle.length > 0) {

            currentArticle
                .addClass('page-deactive-down')
                .removeClass('page-active');

            nextArticle.parent('section.page')
                .removeClass('page-deactive-top')
                .removeClass('page-deactive-down')
                .addClass('page-active');

            nextArticle
                .addClass('page-active')
                .removeClass('page-deactive-top')
                .removeClass('page-deactive-down')

            if (window.location.pathname === "/")
                if (!nextArticle.parent('section.page').hasClass('page-slider'))
                    $('header').addClass('stick');


            if (nextArticle.attr('id'))
                window.location.hash = nextArticle.attr('id');
        }
    }


};
