check-footer.js 2.24 KB
Newer Older
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
var CHK_Footer = {};

CHK_Footer.showPage = function(pageId) {
    var i, pages;
    pages = document.getElementsByClassName("page-content");
    for (i = 0; i < pages.length; i++) {
        if (pages[i].id == pageId) {
            pages[i].style.display = "block";
        } else {
            pages[i].style.display = "none";
        }
    }
    if (pageId == 'dashboard') {
        CHK_Dashboard.init();
    }
}

CHK_Footer.activeBottomNav = function(bottomNavId) {
    var elm = $("#" + bottomNavId);
    if (typeof elm !== 'object') {
        console.log('CHK_Footer.activeBottomNav:elm !== object:' + bottomNavId);
        return;
    }
    elm.removeClass('text-secondary');
    elm.addClass("text-primary");
    let img = elm.find("img")[0];
    if (img && img.getAttribute("data-src")) {
        img.src = img.getAttribute("data-src");
    }
}

CHK_Footer.inactiveAllBottomNav = function() {
    let navs = document.getElementsByClassName("bottom-nav");
    for (i = 0; i < navs.length; i++) {
        navs[i].className = navs[i].className.replace("text-primary", "text-secondary");
        var img = navs[i].querySelector("img");
        if (img && img.getAttribute('data-inactive-src')) {
            img.src = img.getAttribute('data-inactive-src');
        } 
    }
}

CHK_Footer.isIndexPage = function() {
    if (typeof location === 'object' && typeof location.pathname === 'string') {
        if (location.pathname.includes('index.html') == true) {
            return true;
        }
    }
    return false;
}

52 53 54
CHK_Footer.goIndexPage = function(param) {
    var href = 'index.html' + param;
    location.href = href;
55 56 57 58 59 60 61 62 63 64 65 66 67
}

CHK_Footer.activeDashboardBottomNav = function() {
    CHK_Footer.inactiveAllBottomNav();
    CHK_Footer.activeBottomNav('dashboardBottomNav');
}

CHK_Footer.goDashboard = function() {
    CHK_Footer.activeDashboardBottomNav();
    if (CHK_Footer.isIndexPage()) {
        CHK_Footer.showPage('dashboard');
        return;
    }
68
    CHK_Footer.goIndexPage('#dashboard');
69 70 71 72 73 74 75 76 77
}

CHK_Footer.goOperationList = function() {
    CHK_Footer.inactiveAllBottomNav();
    CHK_Footer.activeBottomNav('operationListBottomNav');
    if (CHK_Footer.isIndexPage()) {
        CHK_Footer.showPage('operationList');
        return;
    }
78
    CHK_Footer.goIndexPage('#operationList');
79
}