$(document).ready(function () { $is_verified = getCookie("age_verified"); if( !$is_verified ) { //$('#agemodal').modal('show'); } }); $( "#check_age" ).on( "click", function() { $is_verified = getCookie("age_verified"); if( !$is_verified ) { $birth_month = $( "#birth_month" ).val(); $birth_day = $( "#birth_day" ).val(); $birth_year = $( "#birth_year" ).val(); $birth_month = ("0" + $birth_month).slice(-2); $birth_day = ("0" + $birth_day).slice(-2); $birth_date = $birth_year + "-" + $birth_month + "-" + $birth_day; dob = new Date($birth_date); var today = new Date(); var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000)); if( age >= 21 ) { setCookie("age_verified", "1", 30 ); $('#agemodal').modal('hide'); } else { $('#age_error').removeClass('hidden'); } } }); $(function () { $('.final-tiles-gallery').finalTilesGallery({ margin: 5, gridSize: 20, layout: 'final', minTileWidth: 400, autoLoadURL: "/gallery_images.php", onLoading: function () { loading = setTimeout(function () { $(".ftg-page-loader").fadeIn(); }, 100); }, onUpdate: function () { clearTimeout(loading); $(".ftg-page-loader").fadeOut(); } }); }); $( "#show_past_gallery" ).on( "click", function() { $( ".main_content_pane" ).addClass('hidden'); $( "#past_gallery" ).removeClass('hidden'); }); $( "#close_gallery_button" ).on( "click", function() { $( "#past_gallery" ).addClass('hidden'); $( ".main_content_pane" ).removeClass('hidden'); }); $( "#open_search" ).on( "click", function() { $( "#open_search" ).addClass('hidden'); $( "#close_search" ).removeClass('hidden'); $( "#search_module" ).removeClass('hidden'); }); $( "#close_search" ).on( "click", function() { $( "#search_module" ).addClass('hidden'); $( "#close_search" ).addClass('hidden'); $( "#open_search" ).removeClass('hidden'); }); $(function() { $( "#site_search" ).autocomplete({ source: function( request, response ) { $.ajax({ url: "/cmd.php", dataType: "json", data: { query: request.term, cmd: 'search', type: 'main' }, success: function( data ) { response( data.message ); } }); }, minLength: 3, select: function( e, ui ) { e.preventDefault(); if( ui.item.url != 'none' ) { $( "#site_search" ).val(''); window.location.replace(ui.item.url); } }, open: function() { $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); }, close: function() { $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); } }); }); $( "#login_button" ).on( "click", function() { $data = $("#login_form").serialize(); $username = $("#login_username_or_email").val(); $.ajax({ type: "POST", url: "/cmd.php", maxSelection: 3, maxEntryLength: 30, expandOnFocus: true, data: { cmd: "login", data: $data } }) .done(function( result ) { var data = jQuery.parseJSON( result ); if( data.status == "failure" ) { window.location.replace("/login/?bad_login="+$username ); } else { window.location.replace("/beer/source-series-apis"); } }); return false; }); $("#login_password").keypress(function(event) { if (event.which == 13) { event.preventDefault(); $( "#login_button" ).trigger( "click" ); } }); $('.no-action').click(function(){ return false; }); function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } $( "#resend_welcome" ).on( "click", function() { $message_type = $(this).attr('message_type'); $.ajax({ type: "POST", url: "/cmd.php", maxSelection: 3, maxEntryLength: 30, expandOnFocus: true, data: { cmd: "resend_welcome", type: $message_type } }) .done(function( result ) { var data = jQuery.parseJSON( result ); if( data.status == "failure" ) { alert('We were unable to send your message at this time. Please try again later.'); } else { if( data.message == "confirmed" ) { $( "#"+$message_type+"unconfirmed_div" ).addClass('hidden'); $( "#"+$message_type+"confirmed_div" ).removeClass('hidden'); } else if( data.message == "sent" ) { $( "#"+$message_type+"unconfirmed_div" ).addClass('hidden'); $( "#"+$message_type+"resent_div" ).removeClass('hidden'); } } }); return false; }); $( ".refresh_user" ).on( "click", function() { $message_type = $(this).attr('message_type'); $.ajax({ type: "POST", url: "/cmd.php", maxSelection: 3, maxEntryLength: 30, expandOnFocus: true, data: { cmd: "refresh_user", type: $message_type } }) .done(function( result ) { var data = jQuery.parseJSON( result ); if( data.status == "failure" ) { alert('We were unable to refresh user status. Please try again later.'); } else { if( data.message == true ) { $( "#"+$message_type+"_unconfirmed_div" ).addClass('hidden'); $( "#"+$message_type+"_confirmed_div" ).removeClass('hidden'); } else { $( "#"+$message_type+"_unconfirmed_div" ).html('Looks like there is a delay is updating. Please check back a little bit later.'); } } }); return false; });