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

Commit 8cd4574

Browse files
Updating konami code
1 parent 800a1fa commit 8cd4574

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

examples/KonamiCode/konamicode.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
(function () {
1+
(function (window, undefined) {
22

3-
function main () {
3+
function fadeOut(element) {
4+
var opacity = 1;
5+
element.style.opacity = opacity;
6+
7+
var subscription = Rx.Scheduler.timeout.schedulePeriodic(100, function () {
8+
opacity === 0 && subscription.dispose();
9+
opacity -= 0.1;
10+
element.style.opacity = opacity;
11+
});
12+
}
13+
14+
function initialize() {
415

516
var codes = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
617
konami = Rx.Observable.fromArray(codes),
718
result = document.getElementById('result');
819

9-
Rx.Observable.fromEvent(document, 'keyup')
20+
Rx.DOM.keyup(document)
1021
.pluck('keyCode')
1122
.bufferWithCount(10, 10)
1223
.filter(function (data) { return data.toString() === codes.toString(); })
1324
.subscribe(function () {
14-
result.innerHTML = 'KONAMI!';
15-
setTimeout(function () {
16-
result.style.opacity = 0;
17-
}, 2000);
25+
result.innerHTML = 'KONAMI!';
26+
fadeOut(result);
1827
});
1928
}
2029

21-
window.onload = main;
22-
})();
30+
Rx.DOM.ready().subscribe(initialize);
31+
})(window);

examples/dragndrop/dragndrop.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
(function (window, undefined) {
22

3-
function main () {
3+
function initialize () {
44
var dragTarget = document.getElementById('dragTarget');
55

66
// Get the three major events
7-
var mouseup = Rx.Observable.fromEvent(dragTarget, 'mouseup');
8-
var mousemove = Rx.Observable.fromEvent(document, 'mousemove');
9-
var mousedown = Rx.Observable.fromEvent(dragTarget, 'mousedown');
7+
var mouseup = Rx.DOM.mouseup(dragTarget);
8+
var mousemove = Rx.DOM.mousemove(document);
9+
var mousedown = Rx.DOM.mousedown(dragTarget);
1010

11-
var mousedrag = mousedown.selectMany(function (md) {
11+
var mousedrag = mousedown.flatMap(function (md) {
1212

1313
// calculate offsets when mouse down
1414
var startX = md.offsetX, startY = md.offsetY;
@@ -31,6 +31,6 @@
3131
});
3232
}
3333

34-
window.onload = main;
34+
Rx.DOM.ready().subscribe(initialize);
3535

3636
}(window));

0 commit comments

Comments
 (0)