File: events.html

package info (click to toggle)
jsxgraph 1.3.5+dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 26,044 kB
  • sloc: xml: 5,869; java: 1,072; python: 747; php: 192; makefile: 146; sh: 47
file content (101 lines) | stat: -rw-r--r-- 3,179 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>JSXGraph CeBIT Tests</title>
    <style type="text/css">
        .box {
            width: 200px;
            height: 80px;
        }
    </style>
    <script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
    <script type="text/javascript">

        function addEvent(obj, type, fn, owner) {
            owner['x_internal'+type] = function() {
                return fn.apply(owner, arguments);
            };

            if (obj.addEventListener) { // Non-IE browser
                console.log('addEventListener', type);
                obj.addEventListener(type, owner['x_internal'+type], false);
            } else {
                console.log('attach event', type);
                obj.attachEvent('on'+type, owner['x_internal'+type]);
            }
        }
    </script>
</head>
<body>

<div id="playfield" style="width: 300px; height: 300px; border: 3px solid black; -ms-touch-action: none;"></div>
<div id="result"></div>
<a href="jxg.html"><div class="box" style="float: left; background-color: #ccc;">Next</div></a>

<script type="text/javascript">
    var container = document.getElementById('playfield'),
        i,
        pointerTypes = [
            'undefined',
            'unavailable',
            'touch',
            'pen',
            'mouse'
        ],
        eventManager = {
            events: [
                'mousedown',
                'mousemove',
                'mouseup',
                'touchstart',
                'touchmove',
                'touchend',
                'MSPointerDown',
                'MSPointerMove',
                'MSPointerUp'
            ],

            lastEvent: '',
            counter: 1,

            handleEvent: function(what, e) {
                if (what !== this.lastEvent || this.counter > 50) {
                    $('#result').append(what + ' called ' + this.counter + ' times<br />');
                    this.counter = 1;
                }

                console.log('type ', pointerTypes[e.pointerType], ' / pressure ', e.pressure, ' / id ', e.pointerId, ' / primary ',e.isPrimary);

                this.lastEvent = what;
                this.counter += 1;

                if (e.preventDefault) {
                    e.preventDefault();
                } else if (window.event) {
                    window.event.returnValue = false;
                }

                return true;
            },
            makeEventHandler: function(what) {
                return function(e) {
                    return this.handleEvent(what, e);
                };
            }
        };

    $('#result').append('mspointerenabled:', window.navigator.msPointerEnabled.toString(), '<br />');
    console.log(window.navigator.msPointerEnabled);

    try {
        for(i = 0; i < eventManager.events.length; i++) {
            addEvent(container, eventManager.events[i], eventManager.makeEventHandler(eventManager.events[i]), eventManager);
        }
    } catch(e) {
        $('#result').append('Error: ' + e);
    }
</script>

</body>
</html>