Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created March 11, 2012 07:26
Show Gist options
  • Save mattpodwysocki/2015422 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/2015422 to your computer and use it in GitHub Desktop.
MooTools - Konami Code
<!DOCTYPE html>
<head>
<title>Rx for JavaScript Rocks!</title>
<script src="http://mootools.net/nightly/build/mootools-core.js" type="text/javascript"></script>
<script src="rx.js" type="text/javascript"></script>
<script src="rx.aggregates.js" type="text/javascript"></script>
<script src="../lib/rx.mootools.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
window.addEvent('domready', function () {
var codes = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]
, konami = Rx.Observable.fromArray(codes)
, result = $('result');
$(document).addEventAsObservable('keyup')
.select(function (e) { return e.code; })
.windowWithCount(10)
.selectMany(function (x) { return x.sequenceEqual(konami); })
.where(function (equal) { return equal; })
.subscribe(function () {
result.set('html', 'KONAMI!');
});
});
})(document.id);
</script>
</head>
<body style="font-family: Consolas, monospace; overflow: hidden">
<div id="result" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment