~bcsaller/juju-gui/charmFind

« back to all changes in this revision

Viewing changes to lib/yui/tests/event/tests/manual/konami.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!doctype html>
2
 
<html>
3
 
<head>
4
 
    <title>Test Page</title>
5
 
    <style type="text/css">
6
 
        div {
7
 
            margin: 1em 0;
8
 
        }
9
 
    </style>
10
 
</head>
11
 
<body class="yui-skin-sam">
12
 
<input type="text" value="" id="k"><label for="k">&lt;-- up,up,dn,dn,l,r,l,r,b,a</label>
13
 
<ul id="output"></ul>
14
 
 
15
 
<script src="../../../../build/yui/yui.js"></script>
16
 
<!--
17
 
<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
18
 
<script src="../../../../build/event/event-synthetic.js"></script>
19
 
-->
20
 
<script>
21
 
YUI({
22
 
    useBrowserConsole: false,
23
 
    //lazyEventFacade: true,
24
 
    filter: 'raw'
25
 
}).use('event-synthetic', function (Y) {
26
 
 
27
 
Y.on('yui:log', function (e) {
28
 
    Y.one("#output").append("<li>" + e.msg + "</li>");
29
 
});
30
 
 
31
 
Y.Event.define('konami', {
32
 
    on: function (node, sub, ce) {
33
 
        var guid = Y.guid();
34
 
 
35
 
        node.on(guid + '|keydown', function (e) {
36
 
 
37
 
            Y.log(e.keyCode);
38
 
 
39
 
            if (e.keyCode === sub.keys[sub.progress]) {
40
 
                if (++sub.progress === sub.keys.length) {
41
 
                    ce.fire();
42
 
                    ce.detach(sub.fn, sub.context);
43
 
                }
44
 
            } else {
45
 
                sub.progress = 0;
46
 
            }
47
 
        });
48
 
 
49
 
        Y.mix(sub,{
50
 
            progress : 0,
51
 
            keys     : [38,38,40,40,37,39,37,39,66,65],
52
 
            keys     : [38,38,40,40,37,39,37,39,66,65],
53
 
            _evtGuid : guid
54
 
        });
55
 
    },
56
 
    detach: function (node, sub, ce) {
57
 
        node.detach(sub._evtGuid + '|*');
58
 
    }
59
 
});
60
 
 
61
 
Y.one('#k').on('konami', function (e) {
62
 
    Y.one('#output').append('<li>UNICORNS!</li>');
63
 
});
64
 
 
65
 
});
66
 
</script>
67
 
</body>
68
 
</html>