adrigm
10/1/2018 - 6:37 AM

Configurator

export function openConf() {
    $("#ms-configurator").animate({
        "right": '0px'
    }, 400);
    $(".ms-configurator-btn").animate({
        "right": '-60px'
    }, 200);
}

export function closeConf() {
    $("#ms-configurator").animate({
        "right": '-310px'
    }, 200);
    $(".ms-configurator-btn").animate({
        "right": '20px'
    }, 400);
}

export function slidebarConf(param) {
    // Get initial values
    setSlidebarValue('ms-slidebar-contrast', 'ms-slidebar-contrast', changeContrastMode, false);
    setSlidebarValue('ms-slidebar-fixed', 'ms-slidebar-fixed', changeFixedMode, true);
    setSlidebarValue('ms-slidebar-dark', 'ms-slidebar-dark', changeDarkMode, false);
    setSlidebarValue('ms-slidebar-compact', 'ms-slidebar-compact', changeCompactMode, false);
    setSlidebarValue('ms-slidebar-icons-mode', 'ms-slidebar-icons-mode', changeIconsMode, false);
    setSlidebarValue('ms-slidebar-icons-mode-slidebar', 'ms-slidebar-icons-mode', changeIconsMode, false);
}

export function setSlidebarValue(option, localOption, changeFunction, reload = false) {
    if (!localStorage.getItem(localOption)) {
        localStorage.setItem(localOption, $('#' + option)[0].checked);
    }

    let value = localStorage.getItem(localOption) === 'true';     
    $('#' + option)[0].checked = value;
    changeFunction(value);

    $('#' + option).click(function() {
        if (reload) {
            localStorage.setItem(localOption, $('#' + option)[0].checked);
            location.reload();
        }
        else
            changeFunction(this.checked);
    });
}

export function changeContrastMode(checked) {
    localStorage.setItem('ms-slidebar-contrast', checked);
    if (checked) {
        $('#ms-slidebar-logo').addClass('ms-logo-white');
        $('.ms-slidebar-header-container').addClass('ms-slidebar-header-primary');
    }
    else {
        $('#ms-slidebar-logo').removeClass('ms-logo-white');
        $('.ms-slidebar-header-container').removeClass('ms-slidebar-header-primary');
    }
    
}

export function changeFixedMode(checked) {
    localStorage.setItem('ms-slidebar-fixed', checked);
    if (checked) {
        $('#ms-slidebar').addClass('ms-slidebar-fixed');
        $('.ms-site-container').addClass('ms-fixed-slidebar');
        $('#first').addClass('ms-slidebar-scroll-1');
    }
    else {
        $('#ms-slidebar').removeClass('ms-slidebar-fixed');
        $('.ms-site-container').removeClass('ms-fixed-slidebar');
        $('#first').removeClass('ms-slidebar-scroll-1');
    }
}

export function changeDarkMode(checked) {
    localStorage.setItem('ms-slidebar-dark', checked);
    if (checked) {
        $('.ms-slidebar').removeClass('ms-slidebar-light');
    }
    else {
        $('.ms-slidebar').addClass('ms-slidebar-light');
    }
}

export function changeCompactMode(checked) {
    localStorage.setItem('ms-slidebar-compact', checked);
    if (checked) {
        $('.ms-slidebar').addClass('ms-slidebar-compact');
    }
    else {
        $('.ms-slidebar').removeClass('ms-slidebar-compact');
    }
}

export function changeIconsMode(checked) {
    localStorage.setItem('ms-slidebar-icons-mode', checked);
    if (checked) {
        $('.ms-slidebar').addClass('ms-slidebar-icons-mode');
        $('.ms-site-container').addClass('ms-icons-mode');
        $('#ms-slidebar-icons-mode-slidebar')[0].checked = true;
        $('#ms-slidebar-icons-mode')[0].checked = true;
    }
    else {
        $('.ms-slidebar').removeClass('ms-slidebar-icons-mode');
        $('.ms-site-container').removeClass('ms-icons-mode');
        $('#ms-slidebar-icons-mode-slidebar')[0].checked = false;
        $('#ms-slidebar-icons-mode')[0].checked = false;
    }

    $('body').trigger('changeWidth');
    
    // setTimeout(() => {
    //     $('.grid').packery();
    // }, 1000);
    
}