//parse youtube id from url //source: http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/26758928#comment11747164_8260383 function youtube_id_parser(url){ var regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; var match = url.match(regExp); return (match&&match[1].length==11)? match[1] : false; } (function($) { var toutsBar = function(){ //only appear if cookie is not set up yet // var thg_touts_bar_opt_out = Cookies.get('thg_touts_bar_opt_out'); // if ( !!thg_touts_bar_opt_out ){ //alert bar was opted out of // return; // } //otherwise, touts bar not opted out of yet $(".touts-bar").css({ display: "block" }); //close slides the bar up $(".touts-bar .close").on("click", function(e){ e.preventDefault(); $(".touts-bar").slideUp( 250 ); Cookies.set('thg_touts_bar_opt_out', true, { expires: Infinity } ); }); } //contest form related functionality var contestForm = function(){ if ( $('form.contest-form').length < 1) { return; } //whenever users enter a new youtube url, set up an embed ifrmae and insert it to show a preview $(".youtubeurl").on("change", function(e){ var youtubeUrl = $(e.target).val(); var youtubeId = youtube_id_parser(youtubeUrl); jQuery('.video-embed').children().remove(); jQuery('.video-embed').append(jQuery('')) jQuery('.video-embed').fitVids(); }); }; var contestEmailsSignupForm = function(){ $('form.entry-email-signup').on('submit', function(e){ e.preventDefault(); var actionUrl = $(this).prop('action'); var formData = { email: $('form.entry-email-signup input[name=email]').val() }; //set up bsd request $.ajax({ type: 'POST', url: actionUrl, data: formData, // headers: { "Accept": "application/json"}, // crossDomain: true, // beforeSend: function(xhr){ // xhr.withCredentials = true; // }, }) .done(function(data){ //success }) .fail(function(jqXHR, textStatus, errorThrown){ console.log('error status returned: ', jqXHR, textStatus, errorThrown); }) .always(function(){ //TODO : need to address No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://thehuntinggroundfilm.dev' is therefore not allowed access. Then can move this success behaviors to .done rather than here //set cookie so that we don't show the signup form next time Cookies.set('thg_contest_signed_up', true, { expires: 30 * 24 * 60 * 60 } ); //reveal voting button $('form.entry-email-signup').slideUp(750, function(){ $('.contest-signup-form').fadeOut(); $('.contest-vote').fadeIn(); }); }); }); //on 'submit' }; //contestEmailsSignupForm // var contestEmailSignup = function(){ if ( $('form.entry-email-signup').length < 1) { return; } var thg_contest_signed_up = Cookies.get('thg_contest_signed_up'); if ( thg_contest_signed_up ){ //user already signed up? Show the votting button //reveal the vote. (TODO: insert it for more security?) $('.contest-signup-form').hide(); $('.contest-vote').show(); } else { //otherwise show the signup form $('form.entry-email-signup').show(); contestEmailsSignupForm(); } //else }; //contestEmailSignup var contestEntries = function(){ if ( $('.contest-entries-viewer').length < 1) { return; } //isotope filter/sort setup //adapted from http://codepen.io/desandro/pen/nFrte $('.contest-entries-viewer .blurb').matchHeight(); $('.contest-entries-viewer h4').matchHeight(); var $container = $('.contest-entries-viewer').isotope({ itemSelector: '.contest-entries-viewer .element-item', layoutMode: 'fitRows', getSortData: { byDateSubmitted: '[data-date-submitted]', byFbLikes: '[data-fb-likes] parseInt', byTitle: '[data-title]', }, sortAscending: { byDateSubmitted: false, //newest date first byFbLikes: false //largest number of votes first } }); // layout Isotope after each image loads $container.imagesLoaded().progress( function() { $container.isotope('layout'); $('.contest-entries-viewer .blurb').matchHeight(); $('.contest-entries-viewer h4').matchHeight(); }); //disabling filtering functions for now //should we need custom filter functions // var filterFns = {}; // bind filter button click // $('#filters').on( 'click', 'button', function() { // var filterValue = $( this ).attr('data-filter'); // // use filterFn if matches value // filterValue = filterFns[ filterValue ] || filterValue; // $container.isotope({ filter: filterValue }); // }); // // bind sort button click $('#sorts').on( 'click', 'button', function() { var sortByValue = $(this).attr('data-sort-by'); $container.isotope({ sortBy: sortByValue }); }); // change is-checked class on buttons $('#sorts.button-group').each( function( i, buttonGroup ) { var $buttonGroup = $( buttonGroup ); $buttonGroup.on( 'click', 'button', function() { $buttonGroup.find('.is-checked').removeClass('is-checked'); $( this ).addClass('is-checked'); }); }); }; $(function(){ //domready $(document).ready(function(){ contestForm(); toutsBar(); contestEmailSignup(); contestEntries(); //Size up a video/iframe child of .video-embed (using calculated padding percentage css) jQuery('.video-embed').fitVids(); }); }); })(jQuery); jQuery(function() { jQuery( ".ta-content" ).accordion({ collapsible: true, active: false, header: "h3" }); }); jQuery(document).ready(function() { var unslider = jQuery('#homepage-slider').unslider({ speed: 2000, // The speed to animate each slide (in milliseconds) delay: 5000, // The delay between slide animations (in milliseconds) complete: function() {}, // A function that gets called after every slide animation keys: false, // Enable keyboard (left, right) arrow shortcuts dots: false, // Display dot navigation fade: true, fluid: true // Support responsive design. May break non-responsive designs }); jQuery('.unslider-arrow').click(function() { var fn = this.className.split(' ')[1]; // Either do unslider.data('unslider').next() or .prev() depending on the className unslider.data('unslider')[fn](); }); jQuery("#nav-menu").click(function() { jQuery("#nav-window").toggleClass("open"); jQuery("#nav-window").hide(); jQuery("#nav-window").slideDown( "slow"); }); jQuery("#theclose").click(function() { jQuery("#nav-window").removeClass( "open" ).addClass( "close" ); jQuery("#nav-window").slideUp( "slow"); }); jQuery("#joinus-form").click(function() { jQuery("#joinus-signup-modal").toggleClass("open", 1200); jQuery("#msg").fadeOut(1200); }); jQuery("#joinus-close").click(function() { jQuery("#joinus-signup-modal").removeClass( "open" ).addClass( "close" ); }); jQuery('.twitter').click(function() { if (jQuery('.twitter span').is(":visible")) { jQuery('.twitter span').hide(); } else { jQuery('.twitter span').show().css({"left": "-20px"}); jQuery('.facebook span').hide(); jQuery('.youtube span').hide(); jQuery('.instagram span').hide(); } }); jQuery('.facebook').click(function() { if (jQuery('.facebook span').is(":visible")) { jQuery('.facebook span').hide(); } else { jQuery('.facebook span').show().css({"left": "-30px"}); jQuery('.twitter span').hide(); jQuery('.youtube span').hide(); jQuery('.instagram span').hide(); } }); jQuery('.youtube').click(function() { if (jQuery('.youtube span').is(":visible")) { jQuery('.youtube span').hide(); } else { jQuery('.youtube span').show().css({"left": "-45px"}); jQuery('.twitter span').hide(); jQuery('.facebook span').hide(); jQuery('.instagram span').hide(); } }); jQuery('.instagram').click(function() { if (jQuery('.instagram span').is(":visible")) { jQuery('.instagram span').hide(); } else { jQuery('.instagram span').show().css({"left": "-52px"}); jQuery('.twitter span').hide(); jQuery('.facebook span').hide(); jQuery('.youtube span').hide(); } }); var $container = jQuery('#all-posts'); // initialize Masonry after all images have loaded $container.imagesLoaded( function() { $container.masonry( { itemSelector: '#post-grid' }); }); jQuery('.popup').click(function(event) { var width = 575, height = 400, left = (jQuery(window).width() - width) / 2, top = (jQuery(window).height() - height) / 2, url = this.href, opts = 'status=1' + ',width=' + width + ',height=' + height + ',top=' + top + ',left=' + left; window.open(url, 'twitter', opts); return false; }); jQuery('#video_widget-2').fadeTo( 2500, 1, function() { }); jQuery('#sound-container').fadeTo( 2500, 1, function() { }); jQuery('#replay-container').fadeTo( 2500, 1, function() { }); jQuery('#video-title').animate({top: "5%",opacity:"show"}, { duration: 2600 }); jQuery('#access').on('click', function() { jQuery('#access').toggleClass('nav-open'); jQuery('#main').toggleClass('nav-open'); jQuery('#footer').toggleClass('nav-open'); }); });