-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
211 lines (194 loc) · 7.03 KB
/
index.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="dist/smartEvents.single.min.js"></script>
<script>
// handlers definition, lets play a litle
// with one button we will :
// trigger a 'first' and second handler
// define a personalized event with data from second handler
// (so we make perso dependent of second (for a post ajax call maybe))
// and trigger it
var firstHDef = { ...smartEventDefine };
var secondHDef = { ...smartEventDefine };
var persoHDef = { ...smartEventDefine };
const PersonalEvent = 'personal:postClick'; // personal event Name
secondHDef.event = 'click';
secondHDef.handler = function (obj, event) {
console.log("In second Handler");
var event = $.Event(PersonalEvent); // and make the personal event
event.myData = "plop"; // with myData = "plop"
$(obj).trigger(event); // and trigger it now
};
firstHDef.event = 'click';
firstHDef.handler = function (obj, event) {
console.log("In first Handler");
};
persoHDef.event = PersonalEvent; // this is here where magic is made
persoHDef.handler = function (obj, event) {
console.log("In personal trigered Handler myData : ", event.myData);
};
$(document).ready(function() {
$('#myButton').smartEvent(secondHDef);
$('#myButton').smartEventFirst(firstHDef);
$('#myButton').smartEvent(persoHDef); // or first or last it is alone on 'personal:postClick' and will not collide with click
// and that's all ! you could write those lines in any order or from 3 files if you want it do not matter
// this will also work the same no writing order matter only your choices :
// $('#myButton').smartEvent(persoHDef);
// $('#myButton').smartEventFirst(firstHDef);
// $('#myButton').smartEventLast(secondHDef);
});
$(document).ready(function() {
$('#clear').click(function(e){
$('#out').html("");
})
var oneDef = { ...smartEventDefine };
var twoDef = { ...smartEventDefine };
var threeDef = { ...smartEventDefine };
var fourDef = { ...smartEventDefine };
var fiveDef = { ...smartEventDefine };
var sixDef = { ...smartEventDefine };
// handlers definition
oneDef.event = 'click';
oneDef.handler = function (obj, event) {
$('#out').append('1 <br>');
};
twoDef.event = 'click';
twoDef.handler = function (obj, event) {
$('#out').append('2 <br>');
};
threeDef.event = 'click';
threeDef.handler = function (obj, event) {
$('#out').append('3 <br>');
};
fourDef.event = 'click';
fourDef.handler = function (obj, event) {
$('#out').append('4 <br>');
};
fiveDef.event = 'click';
fiveDef.handler = function (obj, event) {
$('#out').append('5 <br>');
};
sixDef.event = 'click';
sixDef.handler = function (obj, event) {
$('#out').append('6 <br>');
};
// test 0
$('#zero').click(function(e){
$('#out').append('2 <br>');
});
$('#zero').click(function(e){
$('#out').append('1 <br>');
});
// test 1
// oneDef.owner = $('#first');
$('#first').smartEvent(oneDef);
// twoDef.owner = $('#first');
$('#first').smartEvent(twoDef);
// test 2
// oneDef.owner = $('#second');
$('#second').smartEvent(oneDef);
// twoDef.owner = $('#second');
$('#second').smartEventFirst(twoDef);
// setMeFirst(twoDef);
// test 3
$('#third').smartEventLast(oneDef);
$('#third').smartEvent(twoDef);
// test 4
$('#fourth').smartEvent(oneDef,1);
$('#fourth').smartEvent(twoDef,1);
// test 5
$('#fifth').smartEvent(oneDef);
$('#fifth').smartEventLast(twoDef);
$('#fifth').smartEventFirst(threeDef);
// test 6
$('#sixth').smartEventFirst(sixDef);
$('#sixth').smartEventFirst(fiveDef);
$('#sixth').smartEvent(fourDef);
$('#sixth').smartEvent(threeDef, 0);
$('#sixth').smartEventLast(oneDef);
$('#sixth').smartEventLast(twoDef);
});
</script>
</head>
<body>
<p>Advanced exemple : <button id='myButton'>Test Me</button></p>
<ul>
<li>
<button id='zero'>
Test 0
</button><br>
<p>
2 Standard jQuery callbacks defined as inverted. (no ordering)<br>
Expected: 1, 2 as we all know we have to define callbacks in the right order to do so
</p>
</li>
<li>
<button id='first'>
Test 1
</button><br>
<p>
2 callback functions natural order<br>
Expected: 1, 2
</p>
</li>
<li>
<button id='second'>
Test 2
</button><br>
<p>
2 callback functions the second as "first"<br>
Expected: 2, 1
</p>
</li>
<li>
<button id='third'>
Test 3
</button><br>
<p>
2 callback functions first as "last"<br>
Expected: 2, 1
</p>
</li>
<li>
<button id='fourth'>
Test 4
</button><br>
<p>
2 callback functions both with same order<br>
Expected: 1, 2
</p>
</li>
<li>
<button id='fifth'>
Test 5
</button><br >
<p>
3 callback functions , first as natural order, second as last, and the last as first<br>
Expected : 3, 1, 2
</p>
</li>
<li>
<button id='sixth'>
Test 6
</button><br >
<p>
6 callback functions,<br>
Defines: 6: first, 5: first, 4: natural, 3: 0, 1: last, 2: last<br>
Expected: 5, 6, 4, 3, 1, 2</p>
</li>
<li>
<button id='clear'>
Clear output
</button>
</li>
</ul>
<div id="out">
Results Here <br>
</div>
</body>
</html>