Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

+ 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...
commit d6856f89476b23bb63862457434d65cffafe4320 1 parent b595316
Scott Schiller authored March 03, 2012
1  .gitignore
@@ -9,3 +9,4 @@ image/badguy-boom.png
9 9
 image/explosion*.*
10 10
 image/spaceball.png
11 11
 audio
  12
+shorturl
14  index.html
@@ -21,6 +21,15 @@
21 21
   * http://creativecommons.org/licenses/by-nc/3.0/
22 22
   *
23 23
   */
  24
+
  25
+  /**
  26
+   * ADDITIONAL PAGE DEBUG OPTIONS / PARAMETERS
  27
+   * ?html5audio=1 - prefer HTML5 audio, if available (at own risk)
  28
+   * ?profile=1 - shows a performance panel with live DOM stats, options to show/hide groups of DOM elements
  29
+   * ?debug=1 - green blocks everywhere on the grid.
  30
+   * ?mute=1 - I hate sound
  31
+   * ?interval=1 - force setInterval() instead of requestAnimationFrame (if available)
  32
+   */
24 33
  -->
25 34
  <link rel="stylesheet" href="css/survivor.css" />
26 35
  <script src="script/soundmanager2-nodebug-jsmin.js"></script>
@@ -37,6 +46,7 @@
37 46
   }
38 47
  </script>
39 48
  <script src="script/survivor.js"></script>
  49
+ <script src="/common/stats.js"></script>
40 50
 </head>
41 51
 
42 52
 <body>
@@ -240,7 +250,7 @@
240 250
       <span class="divider">|</span>
241 251
       <span id="original">
242 252
        <span id="tweeter">
243  
-        <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>
  253
+        <a href="#" title="Looks like you designed something. Challenge your friends to beat it!" onclick="return false" class="cta tweeter">twitter</a>
244 254
         <span class="divider">|</span>
245 255
        </span>
246 256
        <a href="./" title="Play the default level from the original game">Play the original level</a>
@@ -265,4 +275,4 @@
265 275
 
266 276
 </body>
267 277
 
268  
-</html>
  278
+</html>
86  script/survivor.js
@@ -314,7 +314,7 @@ function Survivor() {
314 314
 
315 315
     events: (function() {
316 316
 
317  
-      var add, remove;
  317
+      var add, remove, preventDefault;
318 318
 
319 319
       add = (typeof window.addEventListener !== 'undefined' ? function(o, evtName, evtHandler) {
320 320
         return o.addEventListener(evtName,evtHandler,false);
@@ -328,8 +328,18 @@ function Survivor() {
328 328
         return o.detachEvent('on'+evtName,evtHandler);
329 329
       });
330 330
 
  331
+      preventDefault = function(e) {
  332
+        if (e.preventDefault) {
  333
+          e.preventDefault();
  334
+        } else {
  335
+          e.returnValue = false;
  336
+          e.cancelBubble = true;
  337
+        }
  338
+      };
  339
+
331 340
       return {
332 341
         add: add,
  342
+        preventDefault: preventDefault,
333 343
         remove: remove
334 344
       };
335 345
 
@@ -8227,6 +8237,8 @@ function go_go_go() {
8227 8237
 
8228 8238
   // hackish: bypass loading / intro screens if noIntro, or if mapData and offline (file://) etc.
8229 8239
 
  8240
+  var tweeter = document.getElementById('tweeter');
  8241
+
8230 8242
   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)))),
8231 8243
       l0 = document.getElementById('loading0'),
8232 8244
       l1 = document.getElementById('loading1'),
@@ -8253,8 +8265,76 @@ function go_go_go() {
8253 8265
     startGame();
8254 8266
 
8255 8267
     // and show the "tweeter" link, encouraging creators to share (maybe)
8256  
-    if (document.getElementById('tweeter') && !window.location.href.match(/temp/i)) {
8257  
-      document.getElementById('tweeter').style.display = 'inline';
  8268
+    if (tweeter && !window.location.href.match(/temp/i)) {
  8269
+
  8270
+      tweeter.style.display = 'inline';
  8271
+
  8272
+      // old-skool.
  8273
+      tweeter.onclick = function(e) {
  8274
+
  8275
+        var webCirca1999,
  8276
+            msg,
  8277
+            serviceURL,
  8278
+            url,
  8279
+            str,
  8280
+            mapData,
  8281
+            xhr;
  8282
+
  8283
+        str = decodeURI(window.location.toString());
  8284
+
  8285
+        mapData = str.substr(str.indexOf('mapData')+8);
  8286
+
  8287
+        serviceURL = 'https://twitter.com/share/?text=';
  8288
+
  8289
+        msg = 'I designed an 80\'s-era arcade game level. Think you can beat it? Play and remix it here.';
  8290
+
  8291
+        xhr = new XMLHttpRequest();
  8292
+
  8293
+        xhr.onreadystatechange = function() {
  8294
+
  8295
+          var json;
  8296
+
  8297
+          if (xhr.readyState != 4) {
  8298
+            return;
  8299
+          }
  8300
+
  8301
+          if (xhr.status != 200 && xhr.status != 304) {
  8302
+            console('HTTP error ' + xhr.status);
  8303
+            return;
  8304
+          }
  8305
+
  8306
+          json = JSON.parse(xhr.responseText);
  8307
+
  8308
+          if (json && json.data && json.data.url) {
  8309
+
  8310
+            // go to the proper sharing URL
  8311
+            webCirca1999.location.replace(serviceURL + encodeURI(msg) + '&url=' + json.data.url);
  8312
+
  8313
+          }
  8314
+
  8315
+        }
  8316
+
  8317
+        // open ze window
  8318
+        webCirca1999 = window.open('about:blank', 'survivorTweetWindow', 'width=640,height=250');
  8319
+
  8320
+        // get the short URL
  8321
+        xhr.open('GET', 'shorturl/?url=' + mapData, true);
  8322
+
  8323
+        // true = post? I forget.
  8324
+        xhr.send();
  8325
+
  8326
+        // hack?
  8327
+        if (e.preventDefault) {
  8328
+          e.preventDefault();
  8329
+        } else {
  8330
+          e.returnValue = false;
  8331
+          e.cancelBubble = true;
  8332
+        }
  8333
+
  8334
+        return false;
  8335
+
  8336
+      }
  8337
+
8258 8338
     }
8259 8339
 
8260 8340
     return false;

0 notes on commit d6856f8

Please sign in to comment.
Something went wrong with that request. Please try again.