jQuery - Deeplink banner with cookies

0 votes
259 views
added Feb 13, 2020 in jQuery by lcjr First Warrant Officer (11,990 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://yoursitename.org/appstore'; 
        console.log(newsId);
        
    function ShowAppBanner(){ 
        AppBanner.show();
        pushDown.css({'margin-bottom':'40px'});
        topNav.addClass('normalize-fix');
        newScroller.addClass('app-news-scroller');
        sliderPosition.addClass('app-slider-position');
        iSearch.hide();
    }
    function HideAppBanner(){ 
        AppBanner.hide();
        topNav.removeClass('normalize-fix');
        newScroller.removeClass('app-news-scroller');
        sliderPosition.removeClass('app-slider-position');
        iSearch.show();
    }

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

    //Cookie configuration
    var expAppBanner = new Date();
    var exbMin = 1440; //a day
    expAppBanner.setTime(expAppBanner.getTime() + (exbMin * 60 * 1000));
    $abCookie = $.cookie('app-banner');
    if ($abCookie == null) {
        $.cookie('app-banner', 'showed', { path: '/', expires: expAppBanner });
        //do here
        if($('body').hasClass('page-news') || $('body').hasClass('page-content') || $('body').hasClass('page-node-29') || $('body').hasClass('page-edgeproptv')) {
            $(window).scroll(function() { 
                
                if (window.scrollY > 1) {
                    HideAppBanner();
                } else {
                    ShowAppBanner();
                } 
            });
        }
        $(AppClose).click(function () {
            HideAppBanner();
        });
    }
    else {
        // cookie at work
        HideAppBanner();
        console.log('app banner cookie working')
    }

});

 

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