Created
February 23, 2015 19:19
-
-
Save Oobert/bc7311d4242bd64b24d5 to your computer and use it in GitHub Desktop.
meetup.com raffle page
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
<html> | |
<head> | |
</head> | |
<body> | |
<div>And the winnder is <span id='winner'></span>!!!!</div> | |
<br/> | |
<br/> | |
<button id='pickWinner'>Pick Next Winner</button> | |
<script> | |
var queryString = function () { | |
// This function is anonymous, is executed immediately and | |
// the return value is assigned to QueryString! | |
var query_string = {}; | |
var query = window.location.search.substring(1); | |
var vars = query.split("&"); | |
for (var i=0;i<vars.length;i++) { | |
var pair = vars[i].split("="); | |
// If first entry with this name | |
if (typeof query_string[pair[0]] === "undefined") { | |
query_string[pair[0]] = pair[1]; | |
// If second entry with this name | |
} else if (typeof query_string[pair[0]] === "string") { | |
var arr = [ query_string[pair[0]], pair[1] ]; | |
query_string[pair[0]] = arr; | |
// If third or later entry with this name | |
} else { | |
query_string[pair[0]].push(pair[1]); | |
} | |
} | |
return query_string; | |
} (); | |
var rsvps | |
function myCallback(rsvpsJsonp){ | |
rsvps = rsvpsJsonp.results; | |
} | |
document.getElementById('pickWinner').onclick = function(e){ | |
var winnerIndex = Math.floor((Math.random() * rsvps.length) + 0); | |
var winnerLink = document.createElement("a"); | |
winnerLink.innerHTML = rsvps[winnerIndex].member.name; | |
winnerLink.href = 'http://www.meetup.com/milwaukeejs/members/' + rsvps[winnerIndex].member.member_id; | |
winnerLink.target = '_blank'; | |
document.getElementById('winner').innerHTML = winnerLink.outerHTML; | |
rsvps.splice(winnerIndex, 1); | |
} | |
function getRsvps() { | |
var baseUrl = 'https://api.meetup.com/2/rsvps?&sign=true&photo-host=public&rsvp=yes&event_id={0}&key={1}&callback=myCallback' | |
baseUrl = baseUrl.replace('{0}', queryString.eventId); | |
baseUrl = baseUrl.replace('{1}', queryString.key); | |
var head = document.head; | |
var script = document.createElement("script"); | |
script.setAttribute("src", baseUrl); | |
head.appendChild(script); | |
head.removeChild(script); | |
} | |
getRsvps(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment