Skip to content

Commit d0bd7de

Browse files
author
ddprrt
committed
added bower.json + test.html
and some other cleanups as well!
1 parent 2150e09 commit d0bd7de

4 files changed

Lines changed: 89 additions & 65 deletions

File tree

bower.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "konamicode.js",
3+
"version": "1.0.0",
4+
"main": "build/konamicode.min.js",
5+
"ignore": [
6+
]
7+
}

src/konamicode.jquery.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
22
3-
Author: Stefan Baumgartner (@ddprrt)
4-
File: konamicode.jquery.js
5-
Requires: konamicode.js, jQuery
3+
Author: Stefan Baumgartner (@ddprrt)
4+
File: konamicode.jquery.js
5+
Requires: konamicode.js, jQuery
66
7-
Description: Small jQuery extension for the konamicode.js
7+
Description: Small jQuery extension for the konamicode.js
88
99
**/
1010

1111
!function ($, window, undefined) {
1212

13-
$.fn.konamicode = function(callback) {
14-
if(window.konamicode) {
15-
window.konamicode(this[0], callback);
16-
}
17-
}
13+
$.fn.konamicode = function(callback) {
14+
if(window.konamicode) {
15+
window.konamicode(this[0], callback);
16+
}
17+
}
1818

1919
}(jQuery, window)

src/konamicode.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
/**
22
3-
Author: Stefan Baumgartner (@ddprrt)
4-
File: konamicode.js
3+
Author: Stefan Baumgartner (@ddprrt)
4+
File: konamicode.js
55
6-
Description: Adds the konamicode to any element on your website. You can add a multitude
7-
of callbacks.
8-
6+
Description: Adds the konamicode to any element on your website. You can add a multitude
7+
of callbacks.
8+
99
**/
1010

11-
!function (window, undefined) {
11+
;(function (window, undefined) {
1212

13-
'use strict';
13+
'use strict';
1414

15-
var keyCodes = [38,38,40,40,37,39,37,39,66,65],
16-
elems = {};
15+
var keyCodes = [38,38,40,40,37,39,37,39,66,65],
16+
elems = {};
1717

18-
window.konamicode = function(elem, callback) {
19-
if(!elems[elem]) {
20-
elems[elem] = new KonamiCode(elem);
21-
}
18+
window.konamicode = function(elem, callback) {
19+
if(!elems[elem]) {
20+
elems[elem] = new KonamiCode(elem);
21+
}
2222

23-
elems[elem].addCallback(callback);
24-
}
23+
elems[elem].addCallback(callback);
24+
}
2525

26-
function KonamiCode(elem) {
27-
var that = this;
28-
that.elem = elem;
29-
if (that.elem.addEventListener) {
30-
that.elem.addEventListener('keyup', check, false);
31-
} else if (that.elem.attachEvent) {
32-
that.elem.attachEvent('onkeyup', check);
33-
}
26+
function KonamiCode(elem) {
27+
var that = this;
28+
that.elem = elem;
29+
if (that.elem.addEventListener) {
30+
that.elem.addEventListener('keyup', check, false);
31+
} else if (that.elem.attachEvent) {
32+
that.elem.attachEvent('onkeyup', check);
33+
}
3434

35-
function check(ev) {
36-
that.checkPosition(ev);
37-
}
38-
}
35+
function check(ev) {
36+
that.checkPosition(ev);
37+
}
38+
}
3939

40-
KonamiCode.prototype = {
41-
position: 0,
42-
callbacks: [],
43-
addCallback: function(callback) {
44-
this.callbacks.push(callback);
45-
},
46-
executeCallbacks: function() {
47-
var i = 0,
48-
len = this.callbacks.length;
40+
KonamiCode.prototype = {
41+
position: 0,
42+
callbacks: [],
43+
addCallback: function(callback) {
44+
this.callbacks.push(callback);
45+
},
46+
executeCallbacks: function() {
47+
var i = 0,
48+
len = this.callbacks.length;
4949

50-
for(i; i < len; i = i + 1) {
51-
if(this.callbacks[i]) {
52-
this.callbacks[i]();
53-
}
54-
}
50+
for(i; i < len; i = i + 1) {
51+
if(this.callbacks[i]) {
52+
this.callbacks[i]();
53+
}
54+
}
5555

56-
this.position = 0;
57-
},
58-
checkPosition: function(ev) {
59-
if(keyCodes[this.position] === ev.keyCode) {
60-
if(this.position+1 < keyCodes.length) {
61-
this.position = this.position + 1;
62-
} else {
63-
this.executeCallbacks();
64-
}
65-
} else {
66-
this.position = 0;
67-
}
68-
}
69-
}
56+
this.position = 0;
57+
},
58+
checkPosition: function(ev) {
59+
if(keyCodes[this.position] === ev.keyCode) {
60+
if(this.position+1 < keyCodes.length) {
61+
this.position = this.position + 1;
62+
} else {
63+
this.executeCallbacks();
64+
}
65+
} else {
66+
this.position = 0;
67+
}
68+
}
69+
}
7070

71-
}(window)
71+
})(window)

test.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Test Suite</title>
5+
</head>
6+
<body>
7+
8+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
9+
<script src="src/konamicode.js"></script>
10+
<script src="src/konamicode.jquery.js"></script>
11+
<script>
12+
$(document).konamicode(function() {
13+
alert('Itsa work!');
14+
})
15+
</script>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)