forked from gabrielecirulli/2048
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f91247
commit cf01ca7
Showing
5 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Function.prototype.bind = Function.prototype.bind || function (target) { | ||
var self = this; | ||
return function (args) { | ||
if (!(args instanceof Array)) { | ||
args = [args]; | ||
} | ||
self.apply(target, args); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
(function () { | ||
if (typeof window.Element === "undefined" || | ||
"classList" in document.documentElement) { | ||
return; | ||
} | ||
|
||
var prototype = Array.prototype, | ||
push = prototype.push, | ||
splice = prototype.splice, | ||
join = prototype.join; | ||
|
||
function DOMTokenList(el) { | ||
this.el = el; | ||
// The className needs to be trimmed and split on whitespace | ||
// to retrieve a list of classes. | ||
var classes = el.className.replace(/^\s+|\s+$/g, '').split(/\s+/); | ||
for (var i = 0; i < classes.length; i++) { | ||
push.call(this, classes[i]); | ||
} | ||
} | ||
|
||
DOMTokenList.prototype = { | ||
add: function (token) { | ||
if (this.contains(token)) return; | ||
push.call(this, token); | ||
this.el.className = this.toString(); | ||
}, | ||
contains: function (token) { | ||
return this.el.className.indexOf(token) != -1; | ||
}, | ||
item: function (index) { | ||
return this[index] || null; | ||
}, | ||
remove: function (token) { | ||
if (!this.contains(token)) return; | ||
for (var i = 0; i < this.length; i++) { | ||
if (this[i] == token) break; | ||
} | ||
splice.call(this, i, 1); | ||
this.el.className = this.toString(); | ||
}, | ||
toString: function () { | ||
return join.call(this, ' '); | ||
}, | ||
toggle: function (token) { | ||
if (!this.contains(token)) { | ||
this.add(token); | ||
} else { | ||
this.remove(token); | ||
} | ||
|
||
return this.contains(token); | ||
} | ||
}; | ||
|
||
window.DOMTokenList = DOMTokenList; | ||
|
||
function defineElementGetter(obj, prop, getter) { | ||
if (Object.defineProperty) { | ||
Object.defineProperty(obj, prop, { | ||
get: getter | ||
}); | ||
} else { | ||
obj.__defineGetter__(prop, getter); | ||
} | ||
} | ||
|
||
defineElementGetter(HTMLElement.prototype, 'classList', function () { | ||
return new DOMTokenList(this); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters