Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 45905aa

Browse files
Adding konamicode.ts
Also switching to noconflict-style document.ready
1 parent 61e7f31 commit 45905aa

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

examples/konamicode/konamicode.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(function ($) {
2-
1+
/// <reference path="../../ts/rx.jquery.d.ts" />
2+
jQuery(function ($) {
33
function identity (x) { return x; }
44

55
$(function () {
@@ -9,11 +9,15 @@
99

1010
$(document).keyupAsObservable()
1111
.select(function (e) { return e.keyCode; })
12-
.windowWithCount(10)
12+
.windowWithCount(10, 1)
1313
.selectMany(function (x) { return x.sequenceEqual(konami); })
1414
.where(identity)
1515
.subscribe(function () {
16-
result.html('KONAMI!').fadeOut(2000);
16+
result.html('KONAMI!')
17+
.fadeOutAsObservable(2000)
18+
.subscribe(function () {
19+
result.html('').fadeIn(0);
20+
});
1721
});
1822
});
19-
})(jQuery);
23+
});

examples/konamicode/konamicode.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path="../../ts/rx.jquery.d.ts" />
2+
3+
jQuery(function ($: JQueryStatic) {
4+
5+
function identity<T>(x: T): T { return x; }
6+
7+
$(function () {
8+
var codes = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
9+
konami = Rx.Observable.fromArray(codes),
10+
result = $('#result');
11+
12+
$(document).keyupAsObservable()
13+
.select(function (e: KeyboardEvent) { return e.keyCode; })
14+
.windowWithCount(10, 1)
15+
.selectMany(function (x) { return x.sequenceEqual(konami); })
16+
.where(identity)
17+
.subscribe(function () {
18+
result.html('KONAMI!').fadeOutAsObservable(2000).subscribe(function() {
19+
result.html('').fadeIn(0);
20+
});
21+
});
22+
});
23+
});

0 commit comments

Comments
 (0)