88b1d32b114e57821e0d6faec5bb8c158b46b4e4
1 /* The person who associated a work with this deed has dedicated the
2 work to the public domain by waiving all of his or her rights to
3 the work worldwide under copyright law, including all related and
4 neighboring rights, to the extent allowed by law.
6 You can copy, modify, distribute and perform the work, even for
7 commercial purposes, all without asking permission.
9 See https://creativecommons.org/publicdomain/zero/1.0/ for details.
14 function offsetTop (el
) {
16 for (offset
= 0; el
&& el
.offsetTop
!== undefined; el
= el
.offsetParent
) {
17 offset
+= el
.offsetTop
;
22 function scrollToId (id
) {
23 var el
= id
? document
.getElementById(id
) : null;
25 window
.scrollTo(0, offsetTop(el
) - 20);
26 history
.replaceState(null, "", "#" + id
);
30 function open (event
) {
32 var target
= this.target
=== "_parent" ? window
.parent
: window
;
33 target
.location
.href
= this.href
;
34 event
.preventDefault();
37 window
.addEventListener('load', function () {
38 if (typeof FastClick
!== "undefined")
39 FastClick
.attach(document
.body
, { tapDelay
: 50 });
40 scrollToId(location
.hash
.slice(1));
43 window
.addEventListener('hashchange', function () {
44 scrollToId(location
.hash
.slice(1));
47 window
.addEventListener('DOMContentLoaded', function () {
48 if (navigator
.standalone
)
49 document
.body
.className
+= ' standalone';
51 var links
= document
.querySelectorAll(
52 "a[href]:not([target=_blank])");
53 for (var i
= 0; i
< links
.length
; ++i
)
54 links
[i
].addEventListener('click', open
);
57 function choice (seq
) {
58 return seq
[(Math
.random() * seq
.length
) | 0];
62 return function () { return !f
.apply(this, arguments
); };
65 function contains (element
) {
66 return this.indexOf(element
) >= 0;
69 function issubset (sub
, sup
) {
70 return sub
.every(contains
, sup
);
73 function intersects (a
, b
) {
74 return Array
.prototype.some
.call(a
, contains
, b
);
77 function ventureForth () {
78 var difficulty
= document
.querySelector("[data-events]:checked");
79 var denizens
= document
.querySelectorAll("[data-flags]:checked");
80 var hash
= "#" + [difficulty
.getAttribute("data-events"),
81 difficulty
.getAttribute("data-nop")]
82 .concat(Array
.prototype.map
.call(denizens
, function (element
) {
83 return element
.getAttribute("data-flags");
85 location
.href
= "scenario.html" + hash
;
88 if (applicationCache
&& applicationCache
.status
) {
89 applicationCache
.update();
90 applicationCache
.addEventListener('updateready', function () {
91 if (applicationCache
.status
=== applicationCache
.UPDATEREADY
) {
92 applicationCache
.swapCache();