Skip to content

Commit

Permalink
playgroud
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Ingrassia committed Feb 9, 2017
1 parent 16571eb commit 489db96
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gustavo</title>
</head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gustavo</title>
</head>

<body>
</body>
<body>
</body>
</html>
14 changes: 14 additions & 0 deletions stingray-playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stingray Playground</title>
<script src="index.js"></script>
</head>

<body>
<div id="checkout_widget" style="border-style:solid; border-color:#D3D3D3;"></div>
</body>
</html>
48 changes: 48 additions & 0 deletions stingray-playground/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function showWidget(eventId) {
EBWidgets.createWidget({
widgetType: 'checkout',
eventId: +eventId,
iframeContainerId: 'checkout_widget'
});
}

function parseUrlParams() {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function(s) {
return decodeURIComponent(s.replace(pl, " "));
},
query = window.location.search.substring(1);

var urlParams = {};
while (match = search.exec(query)) {
urlParams[decode(match[1])] = decode(match[2]);
}
return urlParams;
}

function downloadWidgetJs(urlParams) {
var widgetUrlMap = {
qa: 'https://www.evbqa.com/static/widgets/eb_widgets.js',
prod: 'https://www.eventbrite.com/static/widgets/eb_widgets.js'
};
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.src = widgetUrlMap[urlParams.env];
scriptElement.addEventListener('load', showWidget.bind(null, urlParams.eid))
document.getElementsByTagName('head')[0].appendChild(scriptElement);
}

function initApp() {
var urlParams = parseUrlParams();
downloadWidgetJs(urlParams);
}

if (window.addEventListener) {
window.addEventListener('load', initApp, false);
} else if (window.attachEvent) {
window.attachEvent('onload', initApp);
} else {
window.onload = initApp;
}

0 comments on commit 489db96

Please sign in to comment.