Created
December 13, 2013 19:57
-
-
Save leekiernan/e4ab4a10e8ae829ce289 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
function setFixed(modal_element) { | |
modal_element.css({"-webkit-transition": "0", "-moz-transition": "0", "-ie-transition": "0", "-o-transition": "0", "transition": "0"}); | |
modal_element.css({top: "auto", position: "fixed", bottom: 0}); | |
$(window).unbind('scroll'); | |
} | |
function openModal(response) { | |
response.content = "<div class='flamedeer-contest'>" + response.content + "</div>"; | |
$('body').append(response.content); | |
var modal_element = $(".s-modal-flamedeer"); | |
modal_element.modal({ | |
overlay:{ | |
color: "#000", | |
opacity: "0.6" | |
}, | |
close:{ | |
className: "call-close" | |
}, | |
isCentered:'false', | |
onClose:function(){} | |
}); | |
var modalFlameDeer = modal_element.data("modal"); | |
setTimeout(function() { // need to ensure the screen has reloaded and re-scrolled to the final location | |
var $topPosition = ($(window).scrollTop()+$(window).height()-modal_element.height())+"px"; | |
var $mainContentContainer = $(".s-content"); | |
var $leftPosition = $mainContentContainer.width() + $mainContentContainer.offset().left-486; | |
var $initialTopPosition = $(document).scrollTop() + $(window).height() + 300; | |
//set the position below the viewport first | |
modal_element.css({left: $leftPosition, top: $initialTopPosition}); | |
setTimeout(function() { // have to delay this to give the modal time to move below the screen | |
modalFlameDeer.open(); | |
$("#modal-no-click-bg").unbind("click"); | |
setTimeout(function() { //have to delay this to get the transitions working correctly | |
modal_element.css({display: "block", top: $topPosition}); | |
$(window).scroll(function() {//stop the transition if scrolling | |
setFixed(modal_element); | |
}); | |
setTimeout(function() { //have to wait for the end of the transition...for the browsers that arent doing the transition and throwing the event being caught below | |
setFixed(modal_element); | |
}, 1000); | |
}, 100); | |
}, 100); | |
}, 500); | |
} | |
var attemptFD = function(ts) { | |
if( ts === undefined ) ts = Math.round((new Date()).getTime() / 1000) - 10; | |
console.log(ts); | |
$.ajax("/flamedeer", { | |
type: "POST", | |
data: { | |
findFlamedeer: true, | |
timestamp: ts | |
}, | |
dataType: "text", | |
success: function(response, status, jQueryResponse) { | |
response = parseResponse(response); | |
if (response.status == 'success' && !isMobileSite) { | |
openModal(response); | |
} else if(response.status == 'success' && isMobileSite){ | |
$(response.content).insertAfter($('div#header')); | |
$('div#flamedeer-alert span.call-close').click(function(e){ | |
e.preventDefault(); | |
$('div#flamedeer-alert').hide(); | |
}); | |
} | |
} | |
}); | |
} | |
setTimeout( function() { | |
setInterval("attemptFD()", 1000); | |
}, 10000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment