Skip to content

Commit cf01ca7

Browse files
manually apply gabrielecirulli#81
1 parent 2f91247 commit cf01ca7

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ <h1 class="title">2048</h1>
8282
</p>
8383
</div>
8484

85+
<script src="js/bind_polyfill.js"></script>
86+
<script src="js/classlist_polyfill.js"></script>
8587
<script src="js/animframe_polyfill.js"></script>
8688
<script src="js/keyboard_input_manager.js"></script>
8789
<script src="js/html_actuator.js"></script>

js/bind_polyfill.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Function.prototype.bind = Function.prototype.bind || function (target) {
2+
var self = this;
3+
return function (args) {
4+
if (!(args instanceof Array)) {
5+
args = [args];
6+
}
7+
self.apply(target, args);
8+
};
9+
};

js/classlist_polyfill.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(function () {
2+
if (typeof window.Element === "undefined" ||
3+
"classList" in document.documentElement) {
4+
return;
5+
}
6+
7+
var prototype = Array.prototype,
8+
push = prototype.push,
9+
splice = prototype.splice,
10+
join = prototype.join;
11+
12+
function DOMTokenList(el) {
13+
this.el = el;
14+
// The className needs to be trimmed and split on whitespace
15+
// to retrieve a list of classes.
16+
var classes = el.className.replace(/^\s+|\s+$/g, '').split(/\s+/);
17+
for (var i = 0; i < classes.length; i++) {
18+
push.call(this, classes[i]);
19+
}
20+
}
21+
22+
DOMTokenList.prototype = {
23+
add: function (token) {
24+
if (this.contains(token)) return;
25+
push.call(this, token);
26+
this.el.className = this.toString();
27+
},
28+
contains: function (token) {
29+
return this.el.className.indexOf(token) != -1;
30+
},
31+
item: function (index) {
32+
return this[index] || null;
33+
},
34+
remove: function (token) {
35+
if (!this.contains(token)) return;
36+
for (var i = 0; i < this.length; i++) {
37+
if (this[i] == token) break;
38+
}
39+
splice.call(this, i, 1);
40+
this.el.className = this.toString();
41+
},
42+
toString: function () {
43+
return join.call(this, ' ');
44+
},
45+
toggle: function (token) {
46+
if (!this.contains(token)) {
47+
this.add(token);
48+
} else {
49+
this.remove(token);
50+
}
51+
52+
return this.contains(token);
53+
}
54+
};
55+
56+
window.DOMTokenList = DOMTokenList;
57+
58+
function defineElementGetter(obj, prop, getter) {
59+
if (Object.defineProperty) {
60+
Object.defineProperty(obj, prop, {
61+
get: getter
62+
});
63+
} else {
64+
obj.__defineGetter__(prop, getter);
65+
}
66+
}
67+
68+
defineElementGetter(HTMLElement.prototype, 'classList', function () {
69+
return new DOMTokenList(this);
70+
});
71+
})();

js/game_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ function GameManager(size, InputManager, Actuator, StorageManager) {
1616
// Restart the game
1717
GameManager.prototype.restart = function () {
1818
this.storageManager.clearGameState();
19-
this.actuator.continue(); // Clear the game won/lost message
19+
this.actuator.continueGame(); // Clear the game won/lost message
2020
this.setup();
2121
};
2222

2323
// Keep playing after winning (allows going over 2048)
2424
GameManager.prototype.keepPlaying = function () {
2525
this.keepPlaying = true;
26-
this.actuator.continue(); // Clear the game won/lost message
26+
this.actuator.continueGame(); // Clear the game won/lost message
2727
};
2828

2929
// Return true if the game is lost, or has won and the user hasn't kept playing

js/html_actuator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
3636
};
3737

3838
// Continues the game (both restart and keep playing)
39-
HTMLActuator.prototype.continue = function () {
39+
HTMLActuator.prototype.continueGame = function () {
4040
this.clearMessage();
4141
};
4242

0 commit comments

Comments
 (0)