-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
151 lines (81 loc) · 2.67 KB
/
demo.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<html>
<head>
<title>jQuery.pushEvent</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/yeikos/jquery.pushevent/jquery.pushevent.js"></script>
<script type="text/javascript">
$(function() {
// bind
$('#bind').on('click.one', function() {
alert(1);
}).on('click.two', function() {
alert(2);
}).on('click', function() {
alert('You cannot change position of this event (no namespace)');
}).on('click.three', function() {
alert(3);
}).on('click.four', function() {
alert(4);
});
// delegate
$('#container').on('click.one', '#delegate', function() {
alert(1);
}).on('click.two', '#delegate', function() {
alert(2);
}).on('click', '#delegate', function() {
alert('You cannot change position of this event (no namespace)');
}).on('click.three', '#delegate', function() {
alert(3);
}).on('click.four', '#delegate', function() {
alert(4);
});
// buttons
$('ul a').click(function(event) {
var spl = $(this).text().split(/\s*,\s*/),
events = spl[0],
position = spl[1];
$('#bind').pushEvent(events, position);
$('#container').pushEvent(events, '#delegate', position);
debug();
event.preventDefault();
});
// debug
var debug = (function debug() {
$.each(['bind', 'delegate'], function(index, id) {
var rdir = (id == 'delegate') ? 'container' : id;
var result = $.map($('#' + rdir).data('events').click, function(item) {
return item.namespace ? item.namespace : 'NONAMESPACE';
});
$('#' + id + 'Events span').text(result.join(', '));
});
return debug;
})();
});
</script>
<style type="text/css">
a { text-decoration: none; }
h3 { margin: 15px 0 15px 0; font-size: 18px }
#container { margin: 15px; }
</style>
</head>
<body>
<div id="container">
<h3>jQuery.pushEvent demo</h3>
<h3>Press any button</h3>
<button id="bind">bind click</button> <button id="delegate">delegate click</button>
<h3>Change event position</h3>
<ul>
<li><a href="#">click.one click.two click.three click.four, -1</a></li>
<li><a href="#">click.one click.two click.three click.four, 0</a></li>
<li><a href="#">click.three, 0</a></li>
<li><a href="#">click.three, 1</a></li>
</ul>
<h3>Debug (events position)</h3>
<ul>
<li id="bindEvents">bind events: <span></span></li>
<li id="delegateEvents">delegate events: <span></span></li>
</ul>
</div>
</body>
</html>