File size: 2,445 Bytes
2fcec7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// IE polyfill
if (!String.prototype.startsWith) {
    String.prototype.startsWith = function(searchString, position){
        position = position || 0;
        return this.substr(position, searchString.length) === searchString;
    };
}

(function(website, $, undefined) {

    function pageUrl(pageName) {
        return encodeURI("page/" + pageName + ".html");
    }

    function safariHacks() {
        var userAgent = window.navigator.userAgent;
        if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
            $("body").addClass("safari");
        }
    }

    function adjustViewTopMargin() {
        var topNavHeight = $("nav.navbar-fixed-top").height();
        $("div.view").css("margin-top", topNavHeight + "px");
    }

    function renderView() {
        $("div.view").hide();
        $("#mainNav ul.nav li.active").removeClass("active");
        $("#mainNav ul.nav li").each(function() {
            var $this = $(this);
            if ($this.find("a").attr("href") == (window.location.hash || "#")) {
                $this.addClass("active");
            }
        });

        var view = window.location.hash.substring(1);
        if (view.startsWith("page-")) {
            var $pageView = $("#pageView");
            var pageName = view.substring(view.indexOf("-") + 1);
            $pageView.children().remove();
            $pageView.show();
            $pageView.load(pageUrl(pageName) + " #pageContent", function() {

            });
            $("html, body").animate({ scrollTop: 0 }, "fast");
        } else {
            $("#homeView").show();
            if (window.location.hash) {
                var $section = $(window.location.hash);
                $section[0].scrollIntoView();
            } else {
                $("html, body").animate({ scrollTop: 0 }, "fast");
            }
        }
    }

    window.onhashchange = renderView;
    $(window).resize(adjustViewTopMargin);

    $(document).ready(function() {
        safariHacks();
        renderView();
        adjustViewTopMargin();
        for (var i=1; i<6; i++) window.setTimeout(adjustViewTopMargin, i * 1000);
    });

    // hide expanded menu after click on small screens
    $(document).on('click','.navbar-collapse.in',function(e) {
        if( $(e.target).is('a') && $(e.target).attr('class') != 'dropdown-toggle' ) {
            $(this).collapse('hide');
        }
    });

})(window.website = window.website || {}, jQuery);