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 upon click close button

0 votes
124 views
added Feb 14 in Javascript by lcjr Second Warrant Officer (3,200 points)
edited May 15 by lcjr
$(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(); 
    }
});

 

1 Response

0 votes
responded May 15 by lcjr Second Warrant Officer (3,200 points)
$(window).load(function() {
    var dfpElemPre           = '#div-gpt-ad-',
        dfpCatfishId         = 'xxx1111-0', // catfish prod id  
        cfEl =  $('.catfish-ads'),
        dfpCatfishFullId     = '.catfish-ads' + ' ' + dfpElemPre + dfpCatfishId,
        cfClose = $('.catfish-ads .slide-close'),
        cpDuration = 1440;
        // var catfishMinute = 1440; 24 hr, 720: 12hr, 480: 8hr, 360: 6hr,  180: 3hr,  0
    var expCfTime = new Date();
    expCfTime.setTime(expCfTime.getTime() + (cpDuration * 60 * 1000));
    $cfCookie = $.cookie('catfish-15may'); 

    function ShowCatfish(){  
        setTimeout(function(){
        $(cfEl).addClass('in');
        },600);
        $(cfEl).show();
    }
    function HideCatfish(){ 
        // $(cfEl).removeClass('in');
        setTimeout(function(){
        $(cfEl).removeClass('in');
        },600);
        // $(cfEl).hide();
    }

    if(($(dfpCatfishFullId).css('display') == 'none')){ 
        HideCatfish(); 
        console.log('catfish display none');
    }
    // else {
    //     ShowCatfish();
    //     console.log('catfish here');
    // }
    else {
        
        ShowCatfish();
        if ($cfCookie == null) { 
            //do here
            $(cfClose).on('click', function(){
              $(this).parent().parent().removeClass('in');
              $.cookie('catfish-15may', 'showed', { path: '/', expires: expCfTime });
              HideCatfish();
            });
        }
        else {
            // cookie at work
            HideCatfish(); 
            console.log('cookies work - top');
        }
    }

    
    $(cfClose).on('click', function(){
        $(this).parent().parent().removeClass('in'); 
        $.cookie('catfish-15may', 'showed', { path: '/', expires: expCfTime });
        // HideCatfish();
        console.log('cookies work - bottom');
    });
});

 

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