Created
August 14, 2014 19:43
-
-
Save gabrysiak/16f07f36436d23951784 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GENERAL FUNCTIONS | |
function popupwindow(url, title, w, h) { | |
var left = (screen.width/2)-(w/2); | |
var top = (screen.height/2)-(h/2); | |
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); | |
} | |
$(function() { | |
// VIDEO | |
function resizeVideo(vid){ | |
// original video width and height | |
var origVidWidth = 1280; | |
var origVidHeight = 720; | |
// original video container width and height | |
var vidParentWidth = vid.parent().width(); | |
var vidParentHeight = vid.parent().height(); | |
if( vidParentWidth > vidParentHeight ){ | |
vidHeight = vidParentHeight; | |
vidWidth = vidHeight * origVidWidth / origVidHeight; | |
if(vidWidth < vidParentWidth){ | |
vidWidth = vidParentWidth; | |
vidHeight = vidWidth * origVidHeight / origVidWidth; | |
} | |
} else { | |
vidHeight = vidParentHeight; | |
vidWidth = vidHeight * origVidWidth / origVidHeight; | |
} | |
// resize video width and height | |
vid.width( vidWidth ); | |
vid.height( vidHeight ); | |
// modify video negative margins to keep centered | |
vid.css({ | |
'margin-top': -vidHeight/2, | |
'margin-left': -vidWidth/2 | |
}); | |
} | |
// resize video on resize | |
$(window).resize(function(){ | |
resizeVideo( $('.player-container #player') ) | |
}); | |
// resize video on load | |
$(window).load(function(){ | |
resizeVideo( $('.player-container #player') ); | |
// show player | |
$('.player-container').delay(2000).fadeIn(3000); | |
}); | |
// scroll video into view | |
$(window).scroll(function(){ | |
if(playerReady){ | |
if( $(window).scrollTop() < $('.player-container').offset().top + $('.player-container').height() ){ | |
player.playVideo(); | |
} else { | |
player.pauseVideo(); | |
} | |
} | |
}); | |
// CALENDAR | |
// equal heights | |
function calendarEqualHeights(){ | |
var calendarBtnHeight = 0; | |
$('.calendar ul li a').removeAttr('style').each(function(){ | |
if( $(this).height() > calendarBtnHeight ){ | |
calendarBtnHeight = $(this).height(); | |
} | |
}).height(calendarBtnHeight); | |
} | |
// init | |
$(window).load(function(){ | |
calendarEqualHeights(); | |
}); | |
// window resize | |
$(window).resize(function(){ | |
calendarEqualHeights(); | |
}); | |
// click | |
$('.calendar ul li a').click(function(e){ | |
// prevent default | |
e.preventDefault(); | |
if(!$(this).parent('li').hasClass('active')){ | |
// index number | |
var calendarIndex = $('.calendar ul li a').index($(this)) + 1; | |
// deactive previous active button | |
$('.calendar li.active').removeClass('active'); | |
// set new active button | |
$(this).parent('li').addClass('active'); | |
// fade out previous active itinerary item | |
$('.itinerary .day:visible').fadeOut(); | |
// fade in newly active itinerary item | |
$('.itinerary .day:eq('+ calendarIndex +')').fadeIn(); | |
// scroll to top of section | |
$('html, body').animate({ scrollTop: $('#prize').offset().top }, 'fast'); | |
} | |
}); | |
// PLACEHOLDER | |
$('input, textarea').placeholder(); | |
// MENU | |
$('.btn_menu').click(function(e){ | |
// prevent default | |
e.preventDefault(); | |
// toggle menu | |
$('.portal').toggle(); | |
}); | |
// Full BG img for itinerary area | |
//if(!isMobile){ | |
$('.player-container').backstretch("img/nikonaw1-landingpage-1.jpg"); | |
$(".day0").backstretch("img/photo-day-1.jpg"); | |
$(".day1").backstretch("img/Torres-del-Paine-National-Park-1.jpg"); | |
$(".day2").backstretch("img/Torres-del-Paine-National-Park-2.jpg"); | |
$(".day3").backstretch("img/Torres-del-Paine-National-Park-3.jpg"); | |
$(".day4").backstretch("img/Torres-del-Paine-National-Park-4.jpg"); | |
$(".day5").backstretch("img/Santiago-Edificios.jpg"); | |
$(".camera").backstretch("img/photo-rafting.jpg"); | |
$(".enter").backstretch("img/photo-rafting-close.jpg"); | |
//} | |
// OVERLAY | |
function closeOverlay(){ | |
$('body').removeClass('noscroll'); | |
$('#page_wrap').removeClass('behind'); | |
$('.overlay').removeClass('above'); | |
// play video | |
if( $(window).scrollTop() < $('.player-container').offset().top + $('.player-container').height() ){ | |
player.playVideo(); | |
} | |
} | |
$('.btn_overlay').click(function(e) { | |
// prevent default | |
e.preventDefault(); | |
// pause video | |
player.pauseVideo(); | |
$('body').addClass('noscroll'); | |
$('#page_wrap').addClass('behind'); | |
$('.overlay').addClass('above'); | |
}); | |
$('.btn_overlay_close').click(function(e) { | |
// prevent default | |
e.preventDefault(); | |
// close overlay | |
closeOverlay(); | |
}); | |
$(document).keyup(function(e) { | |
// escape key | |
if (e.keyCode == 27) { | |
// close overlay | |
closeOverlay(); | |
} | |
}); | |
// ACCORDION | |
$('.toggle_parent').click(function() { | |
$(this).toggleClass('active').next('.toggle_child').slideToggle('fast'); | |
}); | |
// FLEXSLIDER | |
$('.slider_product').flexslider({ | |
controlNav: "thumbnails", | |
directionNav: false, | |
slideshow: false | |
}); | |
// FANCYBOX | |
$(".no-touch .fancybox").fancybox(); | |
$('a[href*=#]').click(function(e){ | |
// id | |
var id = $(this).attr('href').split('#')[1]; | |
// if anchor id exists on current page | |
if($('#'+id).length){ | |
// prevent default | |
e.preventDefault(); | |
// close menu | |
$('.portal').hide(); | |
// animate scroll | |
$('html,body').animate({ | |
scrollTop: $('#'+id).offset().top | |
}); | |
} | |
}); | |
// MASKED INPUT | |
function maskedInput(){ | |
$('[name=phone]').inputmask({"mask": "(999)999-9999", "placeholder":"( ) - ", "showMaskOnHover": false}); | |
$('[name=dob]').inputmask({"mask": "99/99/9999", "placeholder":"MM/DD/YYYY", "showMaskOnHover": false}); | |
} | |
maskedInput(); | |
// SWEEPSTAKES SUBMIT FORM | |
$('.sweepstakes.form form').submit(function(e){ | |
// prevent default | |
e.preventDefault(); | |
// set form | |
var form = $(this); | |
// initiate masked input | |
maskedInput(); | |
// disable submit button | |
form.find('[type=submit]').prop('disabled',true); | |
// post form | |
$.ajax({ | |
type: $(this).attr('method'), | |
url: $(this).attr('action'), | |
data: $(this).serialize(), | |
dataType: 'json', | |
success: function(data){ | |
// reset errors | |
$('.error').removeClass('error'); | |
// loop through invalid fields | |
if(data.invalid_fields){ | |
if(isMobile){ | |
alert('Please fill out all required fields'); | |
} else { | |
$.each(data.invalid_fields, function(index,val){ | |
// current field | |
field = $('[name=' + data.invalid_fields[index] + ']'); | |
label = $('[name=' + data.invalid_fields[index] + ']').parents('label'); | |
// add error class to field | |
field.addClass('error'); | |
label.addClass('error'); | |
// focus first error | |
$('.error:first').focus(); | |
}); | |
} | |
// enable submit button | |
form.find('[type=submit]').prop('disabled',false); | |
} | |
// already entered | |
if(data.already_entered){ | |
$('.sweepstakes.form').load('inc/sorrry-already.php'); | |
} | |
// age | |
if(data.age){ | |
$('.sweepstakes.form').load('inc/sorrry-age.php'); | |
} | |
// success | |
if(data.valid){ | |
$('.sweepstakes.form').load('inc/thanks-1.php'); | |
} | |
}, | |
error: function(){ | |
alert('Something went wrong.'); | |
} | |
}); | |
}); | |
// THANKS | |
$(document).on('click','.form_step.thanks.one .btn_primary',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// load thanks 2 | |
$('.sweepstakes.form').load('inc/thanks-2.php',function(){ | |
FB.XFBML.parse(); | |
}); | |
}); | |
// SOCIAL NAV SHARE | |
$('.nav_social.share .twitter a').click(function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Nav Shares", "Click", "Twitter", , false]); | |
// variables | |
var text = 'Life is an %23AWDVENTURE. Enter to win a trip to Chile %26 a %23Nikon1 %23AW1 Camera package. @NikonUSA'; | |
var url = encodeURI('http://' + window.location.host); | |
// share | |
popupwindow('https://twitter.com/intent/tweet?text=' + text + '&url=' + url,'Nikon 1 AW1dventure','600','325'); | |
}); | |
$('.nav_social.share .facebook a').click(function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Nav", "Click", "Facebook"]); | |
var url = 'http://' + window.location.host; | |
var text = 'Life is an #AWDVENTURE. Enter to win a trip to Chile & a #Nikon1 #AW1 Camera package. @NikonUSA'; | |
var media = 'http://' + window.location.host + '/img/logo-nikon.png'; | |
// share | |
FB.ui({ | |
method: "stream.publish", | |
link: url, | |
description: text, | |
media:[{"type":"image","src":media,"href":url}], | |
}, function(response){ | |
if (response && response.post_id) { | |
// track share | |
_gaq.push(["_trackEvent", "Social Nav", "Share", "Facebook"]); | |
} else { | |
// track cancel share | |
_gaq.push(["_trackEvent", "Social Nav", "Cancel Share", "Facebook"]); | |
} | |
}); | |
}); | |
$('.nav_social.share .pinterest a').click(function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Nav", "Click", "Pinterest", , false]); | |
// variables | |
var url = encodeURI('http://' + window.location.host); | |
var media = encodeURI('http://' + window.location.host + '/img/logo-nikon.png'); | |
var description = 'Life is an %23AWDVENTURE. Enter to win a trip to Chile %26 a %23Nikon1 %23AW1 Camera package. @NikonUSA'; | |
// share | |
popupwindow('http://pinterest.com/pin/create/button/?url=' + url + '&media=' + media + '&description=' + description,'Nikon 1 AW1dventure','600','325'); | |
}); | |
// SOCIAL SHARE TABS | |
$(document).on('click','.social_tabs .links a',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// number link | |
var index = $('.social_tabs .links a').index($(this)); | |
// set active tab as inactive | |
$('.social_tabs .links a.active').removeClass('active'); | |
$('.social_tabs .tabs .tab.active').removeClass('active'); | |
// set current tab as active | |
$(this).addClass('active'); | |
$('.social_tabs .tabs .tab:eq(' + index + ')').addClass('active'); | |
}); | |
$(document).on('click','.tab.facebook .b-share',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Tabs", "Click", "Facebook"]); | |
var url = 'http://' + window.location.host; | |
var text = $(this).parent('.tab').find('textarea').val(); | |
var media = 'http://' + window.location.host + '/img/logo-nikon.png'; | |
// share | |
FB.ui({ | |
method: "stream.publish", | |
link: url, | |
description: text, | |
media:[{"type":"image","src":media,"href":url}], | |
}, function(response){ | |
if (response && response.post_id) { | |
// track share | |
_gaq.push(["_trackEvent", "Social Tabs", "Share", "Facebook"]); | |
} else { | |
// track cancel share | |
_gaq.push(["_trackEvent", "Social Tabs", "Cancel Share", "Facebook"]); | |
} | |
}); | |
}); | |
$(document).on('click','.tab.twitter .b-share',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Tabs", "Click", "Twitter"]); | |
// variables | |
var text = encodeURIComponent($(this).parent('.tab').find('textarea').val()); | |
// share | |
popupwindow('https://twitter.com/intent/tweet?text=' + text,'Nikon 1 AW1dventure','600','325'); | |
}); | |
$(document).on('click','.tab.pinterest .b-share',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Social Tabs", "Click", "Pinterest"]); | |
// variables | |
var url = encodeURI('http://' + window.location.host); | |
var media = encodeURI('http://' + window.location.host + '/img/logo-nikon.png'); | |
var description = encodeURIComponent($(this).parent('.tab').find('textarea').val()); | |
// share | |
popupwindow('http://pinterest.com/pin/create/button/?url=' + url + '&media=' + media + '&description=' + description,'Nikon 1 AW1dventure','600','325'); | |
}); | |
// SWEEPSTAKES SHARE | |
$(document).on('click','#enter .nav_social .twitter a',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Sweepstakes Confirmation", "Click", "Twitter"]); | |
// variables | |
var text = 'I just entered Nikon\'s Life is an %23AWDVENTURE sweepstakes for a chance to win a trip to Chile %26 a Nikon 1 %23AW1 Camera!'; | |
var url = encodeURI('http://' + window.location.host); | |
// share | |
popupwindow('https://twitter.com/intent/tweet?text=' + text + '&url=' + url,'Nikon 1 AW1dventure','600','325'); | |
}); | |
$(document).on('click','#enter .nav_social .facebook a',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Sweepstakes Confirmation", "Click", "Facebook"]); | |
var url = 'http://' + window.location.host; | |
var text = 'I just entered Nikon\'s Life is an #AWDVENTURE sweepstakes for a chance to win a trip to Chile & a Nikon 1 #AW1 Camera!'; | |
var media = 'http://' + window.location.host + '/img/logo-nikon.png'; | |
// share | |
FB.ui({ | |
method: "stream.publish", | |
link: url, | |
description: text, | |
media:[{"type":"image","src":media,"href":url}], | |
}, function(response){ | |
if (response && response.post_id) { | |
// track share | |
_gaq.push(["_trackEvent", "Sweepstakes Confirmation", "Share", "Facebook"]); | |
} else { | |
// track cancel share | |
_gaq.push(["_trackEvent", "Sweepstakes Confirmation", "Cancel Share", "Facebook"]); | |
} | |
}); | |
}); | |
$(document).on('click','#enter .nav_social .pinterest a',function(e){ | |
// prevent default | |
e.preventDefault(); | |
// track click | |
_gaq.push(["_trackEvent", "Sweepstakes Confirmation", "Click", "Pinterest"]); | |
// variables | |
var url = encodeURI('http://' + window.location.host); | |
var media = encodeURI('http://' + window.location.host + '/img/logo-nikon.png'); | |
var description = 'I just entered Nikon\'s Life is an %23AWDVENTURE sweepstakes for a chance to win a trip to Chile %26 a Nikon 1 %23AW1 Camera!'; | |
// share | |
popupwindow('http://pinterest.com/pin/create/button/?url=' + url + '&media=' + media + '&description=' + description,'Nikon 1 AW1dventure','600','325'); | |
}); | |
// ENTER SECTION REMOVE 100% HEIGHT FOR MOBILE | |
if (isMobile) { | |
$('.enter').removeClass('full'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment