Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

$cookie - Hide app banner with cookie setting after click close button

0 votes
3 views
added 6 days ago in Javascript by lcjr Sergeant (2,120 points)
$(document).ready(function() { 
    // var AppArea = $('body').hasClass('one-sidebar'),
    var AppArea = 'body.one-sidebar',
        AppBanner = $('#app-banner'),
        AppClose = $(AppArea + ' .app-close'),
        pushDown = $(AppArea + ' .main-content'),
        topNav = $(AppArea + ' .top-nav'),
        newScroller = $(AppArea + ' .news-top-stories'),
        sliderPosition = $(AppArea + ' .slider-position'),
        iSearch = $(AppArea + ' .m-news-search i.fa.fa-search'),
        newsUrl = window.location.href,
        newsSplit = newsUrl.split('/'),
        newsId = newsSplit[newsSplit.length-2],
        AppUrl = 'https://www.yoursite.com/appstore'; 
        // console.log(newsId);
        
    function ShowAppBanner(){ 
        if ($(window).width() < 768) {
            var expAppBanner = new Date();
            var exbMin = 1440; //a day
            expAppBanner.setTime(expAppBanner.getTime() + (exbMin * 60 * 1000));
            $abCookie = $.cookie('app-banner'); 

            if ($abCookie == null) { 
                //do here
                AppBanner.show(); 
                pushDown.css({'margin-bottom':'40px'});
                topNav.addClass('normalize-fix');
                newScroller.addClass('app-news-scroller');
                sliderPosition.addClass('app-slider-position');
                iSearch.hide();
            }
            else {
                // cookie at work
                AppBanner.hide(); 
                console.log('app banner cookie at work')
            }

            }
        else {
            AppBanner.hide();
        }
    }
    function HideAppBanner(){ 
        AppBanner.hide();
        topNav.removeClass('normalize-fix');
        newScroller.removeClass('app-news-scroller');
        sliderPosition.removeClass('app-slider-position');
        iSearch.show();
    }

    function setCookie() {
        var expAppBanner = new Date();
        var exbMin = 1440; //a day
        expAppBanner.setTime(expAppBanner.getTime() + (exbMin * 60 * 1000));
        $abCookie = $.cookie('app-banner');
    }


    $(AppBanner).click(function () {
        if($('body').hasClass('page-content')) {
            window.location = 'yoursitecom://news/' + newsId;
        } else {
            setTimeout(function() {
                window.open(AppUrl);
            }, 100);
            window.location = 'yoursitecom://news/' + newsId;
        }
     });

    $(AppClose).click(function() {
        var expAppBanner = new Date();
        var exbMin = 1440; //a day
        expAppBanner.setTime(expAppBanner.getTime() + (exbMin * 60 * 1000));
        $abCookie = $.cookie('app-banner');
        $.cookie('app-banner', 'showed', { path: '/', expires: expAppBanner });
        HideAppBanner();
    });

    if($('body').hasClass('page-news') || $('body').hasClass('page-content') || $('body').hasClass('page-node-29') || $('body').hasClass('page-edgeproptv') || $('body').hasClass('page-pullout') || $('body').hasClass('page-events') ||  $('body').hasClass('node-type-tep-blogs') || $('body').hasClass('page-guides')) {
        $(window).scroll(function() { 
            if (window.scrollY > 1) {
                HideAppBanner();
            } else {
                ShowAppBanner(); 
            }     
        });
    } else {
        HideAppBanner(); 
    }
});

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...