Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save babatundebusari/feb23c8c822aef8dd6860ed82410904b to your computer and use it in GitHub Desktop.
Save babatundebusari/feb23c8c822aef8dd6860ed82410904b to your computer and use it in GitHub Desktop.

Revisions

  1. @chancesmith chancesmith created this gist Nov 7, 2016.
    48 changes: 48 additions & 0 deletions notification-bar-set-cookie.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/jquery.cookie/1.4.1/jquery.cookie.min.js"></script>

    <script>
    function createNotification(message, type) {
    var html = '<div class="alert alert-' + type + ' alert-dismissable page-alert">';
    html += '<button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
    html += message;
    html += '</div>';
    $('body').prepend('<div id="note-holder"></div>');
    $(html).hide().prependTo('#note-holder').slideDown();
    };

    function cookieExist(title){
    title = title + "-notify";
    if ($.cookie(title) === null ||
    $.cookie(title) === "" ||
    $.cookie(title) === "null" ||
    $.cookie(title) === undefined) {
    /* no cookie found */
    return false;
    } else {
    console.log('cookie is set, no ad this time');
    return true;
    }
    }

    function setCookie(days, title){
    var date = new Date();
    var minutes = 60 * 24 * days; //3 days
    date.setTime(date.getTime() + (minutes * 60 * 1000));
    /* set cookie */
    title = title + "-notify";
    $.cookie(title, "close", {
    expires: date
    });
    }

    // show ad if cookie does not exist
    if( !cookieExist("ADG") )
    createNotification('Custom Calendars - Coming Soon', 'info');

    $('.page-alert .close').click(function(e) {
    e.preventDefault();
    $(this).closest('.page-alert').slideUp();
    setCookie(3,"ADG");
    });
    </script>
    12 changes: 12 additions & 0 deletions styles.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #noty-holder{
    width: 100%;
    top: 0;
    font-weight: bold;
    z-index: 1031; /* Max Z-Index in Fixed Nav Menu is 1030*/
    text-align: center;
    position: fixed;
    .alert{
    margin-bottom: 2px;
    border-radius: 0px;
    }
    }