Skip to content

Instantly share code, notes, and snippets.

@pvdz
Created January 29, 2015 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvdz/3cccc4f36c8319e09bb7 to your computer and use it in GitHub Desktop.
Save pvdz/3cccc4f36c8319e09bb7 to your computer and use it in GitHub Desktop.
JS1k 2015 bare shim. This is loaded in an iframe dynamically. You can opt for an empty DOM during submit, a 2d canvas, or a webgl canvas. You can also specify max canvas width/height during submit, defaults to 100%. If empty, `a`, `c`, and `g` will obviously not exist. `top.reload()` replaces the iframe containing your demo with a new instance, …
<!doctype html>
<html style="margin: 0; padding: 0; border: 0; width: 100%; height: 100%;">
<head>
<meta charset="utf-8">
</head>
<body style="margin: 0; padding: 0; border: 0; width: 100%; height: 100%;">
<canvas style="display: block; width: WIDTHpx; height: HEIGHTpx;" width="WIDTH" height="HEIGHT"></canvas>
<script>
// shim...
var a = canvas;
var b = body;
var c = context('2d');
var g = context('3d');
top.reload();
onorientationchange = top.reload; // optional
// unprefixed: AudioContext, requestAnimationFrame, canvas/body.requestPointerLock, getUserMedia
// if webgl, same shim setup as last year
// THIS IS WHERE YOUR DEMO GOES
</script>
</body>
</html>
@aemkei
Copy link

aemkei commented Jan 30, 2015

one request:

Can we have the script in it's own tag with an ID? This would make it easier to hack some cool quines:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body style="margin: 0; padding: 0; border: 0; width: 100%; height: 100%;">
    <canvas style="display: block; width: WIDTHpx; height: HEIGHTpx;" width="WIDTH" height="HEIGHT"></canvas>
    <script>
      // shim...
      var a = canvas;
      var b = body;
      var c = context('2d');
      var g = context('3d');
      top.reload();
      onorientationchange = top.reload; // optional

      // unprefixed: AudioContext, requestAnimationFrame, canvas/body.requestPointerLock, getUserMedia
      // if webgl, same shim setup as last year
     </script>
     <script id="s">// THIS IS WHERE YOUR DEMO GOES</script>
    </script>
  </body>
</html>

@srifqi
Copy link

srifqi commented Feb 8, 2016

Is this still valid for JS1k 2016?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment