Permalink
Browse files

+ URL shortening for share on twitter (Tweet link shows after you mak…

…e a level in the editor and are playing it.)
  • Loading branch information...
1 parent b595316 commit d6856f89476b23bb63862457434d65cffafe4320 @scottschiller committed Mar 4, 2012
Showing with 96 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +12 −2 index.html
  3. +83 −3 script/survivor.js
View
@@ -9,3 +9,4 @@ image/badguy-boom.png
image/explosion*.*
image/spaceball.png
audio
+shorturl
View
@@ -21,6 +21,15 @@
* http://creativecommons.org/licenses/by-nc/3.0/
*
*/
+
+ /**
+ * ADDITIONAL PAGE DEBUG OPTIONS / PARAMETERS
+ * ?html5audio=1 - prefer HTML5 audio, if available (at own risk)
+ * ?profile=1 - shows a performance panel with live DOM stats, options to show/hide groups of DOM elements
+ * ?debug=1 - green blocks everywhere on the grid.
+ * ?mute=1 - I hate sound
+ * ?interval=1 - force setInterval() instead of requestAnimationFrame (if available)
+ */
-->
<link rel="stylesheet" href="css/survivor.css" />
<script src="script/soundmanager2-nodebug-jsmin.js"></script>
@@ -37,6 +46,7 @@
}
</script>
<script src="script/survivor.js"></script>
+ <script src="/common/stats.js"></script>
</head>
<body>
@@ -240,7 +250,7 @@
<span class="divider">|</span>
<span id="original">
<span id="tweeter">
- <a href="https://twitter.com/share/?text=I%20designed%20an%2080's-era%20arcade%20game%20level.%20Think%20you%20can%20beat%20it%3F%20Play%20and%20remix%20it%20here." title="Looks like you designed something. Challenge your friends to beat it!" target="_blank" class="cta tweeter" data-via="schill">twitter</a>
+ <a href="#" title="Looks like you designed something. Challenge your friends to beat it!" onclick="return false" class="cta tweeter">twitter</a>
<span class="divider">|</span>
</span>
<a href="./" title="Play the default level from the original game">Play the original level</a>
@@ -265,4 +275,4 @@
</body>
-</html>
+</html>
View
@@ -314,7 +314,7 @@ function Survivor() {
events: (function() {
- var add, remove;
+ var add, remove, preventDefault;
add = (typeof window.addEventListener !== 'undefined' ? function(o, evtName, evtHandler) {
return o.addEventListener(evtName,evtHandler,false);
@@ -328,8 +328,18 @@ function Survivor() {
return o.detachEvent('on'+evtName,evtHandler);
});
+ preventDefault = function(e) {
+ if (e.preventDefault) {
+ e.preventDefault();
+ } else {
+ e.returnValue = false;
+ e.cancelBubble = true;
+ }
+ };
+
return {
add: add,
+ preventDefault: preventDefault,
remove: remove
};
@@ -8227,6 +8237,8 @@ function go_go_go() {
// hackish: bypass loading / intro screens if noIntro, or if mapData and offline (file://) etc.
+ var tweeter = document.getElementById('tweeter');
+
var bypassIntro = (document.location.href.match(/nointro/i) || (document.referrer && document.referrer.match(/editor/i) || (!document.location.protocol.match(/http/i) && document.location.href.match(/mapdata/i)))),
l0 = document.getElementById('loading0'),
l1 = document.getElementById('loading1'),
@@ -8253,8 +8265,76 @@ function go_go_go() {
startGame();
// and show the "tweeter" link, encouraging creators to share (maybe)
- if (document.getElementById('tweeter') && !window.location.href.match(/temp/i)) {
- document.getElementById('tweeter').style.display = 'inline';
+ if (tweeter && !window.location.href.match(/temp/i)) {
+
+ tweeter.style.display = 'inline';
+
+ // old-skool.
+ tweeter.onclick = function(e) {
+
+ var webCirca1999,
+ msg,
+ serviceURL,
+ url,
+ str,
+ mapData,
+ xhr;
+
+ str = decodeURI(window.location.toString());
+
+ mapData = str.substr(str.indexOf('mapData')+8);
+
+ serviceURL = 'https://twitter.com/share/?text=';
+
+ msg = 'I designed an 80\'s-era arcade game level. Think you can beat it? Play and remix it here.';
+
+ xhr = new XMLHttpRequest();
+
+ xhr.onreadystatechange = function() {
+
+ var json;
+
+ if (xhr.readyState != 4) {
+ return;
+ }
+
+ if (xhr.status != 200 && xhr.status != 304) {
+ console('HTTP error ' + xhr.status);
+ return;
+ }
+
+ json = JSON.parse(xhr.responseText);
+
+ if (json && json.data && json.data.url) {
+
+ // go to the proper sharing URL
+ webCirca1999.location.replace(serviceURL + encodeURI(msg) + '&url=' + json.data.url);
+
+ }
+
+ }
+
+ // open ze window
+ webCirca1999 = window.open('about:blank', 'survivorTweetWindow', 'width=640,height=250');
+
+ // get the short URL
+ xhr.open('GET', 'shorturl/?url=' + mapData, true);
+
+ // true = post? I forget.
+ xhr.send();
+
+ // hack?
+ if (e.preventDefault) {
+ e.preventDefault();
+ } else {
+ e.returnValue = false;
+ e.cancelBubble = true;
+ }
+
+ return false;
+
+ }
+
}
return false;

0 comments on commit d6856f8

Please sign in to comment.