Last active
October 8, 2015 19:28
-
-
Save SethHamilton/2201f4ed6c3c69af7f2d to your computer and use it in GitHub Desktop.
Embedding SurveyMonkey in a Ghost Blog
This file contains 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
<!-- this is the take survey button --> | |
<div id="take-my-survey" style="display:none;"><a onclick="PopSurvey();" class="smallbutton blue">Take my survey</a></div> | |
<!-- this is the thank-you note --> | |
<div id="thanks-boss" style="display:none;"><h3>Thanks for taking my survey!</h3></div> | |
<!-- the outer that makes up our full screen pop-up div --> | |
<div id="surveyOuter" style="background:#d4d4d4;z-index:999;overflow:hidden;position:fixed;display:none;top:0;left:0;right:0;bottom:0;"> | |
<!-- a holder for our two buttons in the upper right --> | |
<div style="display:block;position:fixed;right:16px;top:16px;overflow:none;"> | |
<div style="display:block;float:left;"><a onclick="HideSurvey(true);" class="smallbutton blue">Take Later</a></div> | |
<div style="display:block;float:left;margin-left:8px;"><a onclick="HideSurvey(false);" class="smallbutton blue">Close Survey</a></div> | |
</div> | |
<div style="position:fixed;display:block;border-top:4px solid white;top:64px;left:0;bottom:0;right:0;overflow-y:auto;-webkit-overflow-scrolling:touch;"><iframe id="monkeyframe" style="z-index:1000;width:100%;height:100%;padding:0;margin:0;display:none;position:absolute;border:0;overflow:hidden;" src="about:blank"> | |
</iframe></div><!-- close inner --></div> <!-- close outer --> | |
<script> | |
// this is the script that makes it go | |
// | |
// Change these variables: | |
// | |
// make up an ID for your survey, it's used to cookie | |
// the site so we don't ask for the same survey twice. | |
// note: no spaces, just text and numbers and dashes are good. | |
var thisSurveyID = "content-questionaire"; | |
var SurveyMonkeyURL = "<your survey URL as provided by SurveyMonkey>"; | |
var outerDiv = document.getElementById( "surveyOuter" ); | |
var monkeyFrame = document.getElementById( "monkeyframe" ); | |
function PopSurvey() { | |
outerDiv.style.display = "block"; | |
// turn off the scroll bar on the blog page (double scrolls are horrible) | |
document.body.style.overflow = "hidden"; | |
window.scrollTo(0,0); | |
monkeyFrame.src = SurveyMonkeyURL; | |
monkeyFrame.onload= function () { | |
monkeyFrame.style.display = "block"; | |
} | |
}; | |
function HideSurvey( doLater ) { | |
outerDiv.style.display = "none"; | |
// turn off the scroll bar back on! | |
document.body.style.overflow = "auto"; | |
if (doLater) { | |
// hide "thanks" and display "take survey" button | |
document.getElementById( "take-my-survey" ).style.display = "block"; | |
document.getElementById( "thanks-boss" ).style.display = "none"; | |
} else { | |
// hide "take survey" button and show "thanks"! | |
document.getElementById( "take-my-survey" ).style.display = "none"; | |
document.getElementById( "thanks-boss" ).style.display = "block"; | |
// set cookie | |
CookieThisSurvey(); | |
} | |
}; | |
function CookieThisSurvey() { | |
document.cookie = "did-survey-" + thisSurveyID + "=true; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/"; | |
}; | |
var cookie = document.cookie || ""; | |
// do we have a cookie with this ID? | |
if (cookie.indexOf( "did-survey-" + thisSurveyID ) != -1) { | |
document.getElementById( "thanks-boss" ).style.display = "block"; | |
} else { // we don't have this cookie, so show the "Take Survey" button | |
document.getElementById( "take-my-survey" ).style.display = "block"; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment