-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
250 lines (204 loc) · 6.16 KB
/
test.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body class="yui3-skin-sam">
<p id="x">Treasure</p>
<script src="http://yui.yahooapis.com/3.8.1/build/yui/yui.js"></script>
<script src="event.js"></script>
<script>
YUI({
filter: 'raw'
}).use('eventx-base', function (Y) {
function C(name) {
this.name = name;
Y.EventTarget.call(this);
}
Y.extend(C, Y.EventTarget, {
_defaultBarFn: function () {
console.log("bar defaultFn");
},
_preventBarFn: function () {
console.log("bar preventedFn");
}
});
Y.EventTarget.configure(C, {
foo: { bubbles: false },
bar: {
emitFacade: true,
defaultFn: '_defaultBarFn',
preventedFn: '_preventBarFn'
},
onetime: {
emitFacade: true,
fireOnce: true,
defaultFn: function () {
console.log("fireOnce defaultFn (should not show up again)");
}
}
});
var c = new C("Little C"),
bigC = new C("Big C"),
ultraC = new C("Ultra C"),
lateralC = new C("Lateral C");
c.addTarget(bigC); // Should get event second
c.addTarget(lateralC); // Should get event third
bigC.addTarget(ultraC); // Should get event fourth
bigC.addTarget(lateralC); // Should NOT get event a second time
ultraC.addTarget(lateralC); // Should NOT get event a second time
c.on("test", function (data) {
console.log("#1 (c): " + this.name, data);
});
c.after("test", function (data) {
console.log("Last (c): " + this.name, data);
});
bigC.on("test", function (data) {
console.log("#5, then #1 (bigC): " + this.name, data);
});
ultraC.on("test", function (data) {
console.log("#7, then #3 (ultraC): " + this.name, data);
});
c.on("test", function (data) {
console.log("#2 (c as 'not a C'): " + this.name, data);
}, { name: "I'm NOT a C." });
c.subscribe("test", "before", function (data, nickname) {
console.log("#3 (c as Tito): " + this.name + ", but call me " + nickname, data);
}, null, "Tito");
c.on({
test: function (data) { console.log("#4 (c): " + this.name, data); },
foo: function (e) { console.log("foo from c. Should be undefined ->", e); },
bar: function (e) { console.log("bar #1", e); }
});
c.subscribe("test","middle", function (data) {
console.log("ERROR: Should NOT be logged. 'middle' is not a known phase.", data);
});
lateralC.on("test", function (data) {
console.log("#6, then #2 (lateralC): " + this.name, data);
});
c.after("bar", function (e) {
console.log("bar #2 (after defaultFn)", e);
});
c.on("onetime", function (e) {
console.log("fireOnce #1 (should not show up again)", e);
});
c.after("onetime", function (e) {
console.log("fireOnce #2 (should not show up again)", e);
});
bigC.on('foo', function (e) {
console.log("ERROR: This should not be logged. foo doesn't bubble. If you're seeing this, at least e should be undefined. Double whammy?", e);
});
c.fire("test", { data: "This is data from fire" });
c.fire("foo");
c.fire("bar");
c.fire("onetime");
c.fire("onetime");
c.detach();
c.on("bar", function (e) {
e.preventDefault();
});
c.on("onetime", function (e) {
console.log("fireOnce #3 (after fired, should not show up again)");
});
c.after("onetime", function (e) {
console.log("fireOnce #4 (after fired, should not show up again)");
});
c.fire("test", { data: "ERROR: should be no subs for test event" });
c.fire("bar");
console.log('And now for the Y tests');
Y._defaultYBarFn = function () {
console.log("bar defaultFn on Y");
};
Y.publish({
bar: {
emitFacade: true,
defaultFn: '_defaultYBarFn',
preventedFn: function () {
console.log("bar preventedFn on Y");
}
},
onetime: {
emitFacade: true,
fireOnce: true,
defaultFn: function () {
console.log("fireOnce defaultFn (this should not show up again)");
}
}
});
Y.on("test", function (data) {
console.log("#1", data);
});
Y.after("test", function (data) {
console.log("Last", data);
});
Y.on("test", function (data) {
console.log("#2", data);
});
Y.on("test", function (data) {
console.log("#3 (not a Y): " + this.name, data);
}, { name: "I'm not Y." });
Y.subscribe("test", "before", function (data, nickname) {
console.log("#4 (Tito): " + nickname, data);
}, null, "Tito");
Y.on({
test: function (data) { console.log("#5", data); },
foo: function (e) { console.log("foo #1. Should be undefined ->", e); },
bar: function (e) { console.log("bar #1", e); }
});
Y.subscribe("test", "middle", function (e) {
console.log("ERROR: Should NOT be logged. 'middle' is not a known phase.", e);
});
Y.after("bar", function (e) {
console.log("bar #2", e);
});
Y.on("onetime", function (e) {
console.log("fireOnce #1 (this should not show up again)", e);
});
Y.after("onetime", function (e) {
console.log("fireOnce #2 (this should not show up again)", e);
});
Y.fire("test", { data: "This is data from fire" });
Y.fire("foo");
Y.fire("bar");
Y.fire("onetime");
Y.fire("onetime");
Y.detach();
Y.on("bar", function (e) {
e.preventDefault();
});
Y.on("onetime", function (e) {
console.log("fireOnce #3 (subscribe after fired, this should not show up again)");
});
Y.after("onetime", function (e) {
console.log("fireOnce #4 (subscribe after fired, this should not show up again)");
});
Y.fire("test", { data: "ERROR: No subs for test event" });
Y.fire("bar");
console.log('testing new Y.EventTarget({ defaults })');
var target = new Y.EventTarget({
emitFacade: true,
bubbles: false
}),
parent = new Y.EventTarget();
target.addTarget(parent);
target.on('test', function (e) {
console.log('#1 EventTarget. Should be EventFacade ->', e);
});
parent.on('test', function (e) {
console.log('ERROR: #3 EventTarget Should not have been fired. Should be EventFacade ->', e);
});
target.publish('@test', {
pattern: /not-test/,
subscribe: function (target, sub) {
var event = target.getEvent('test');
return event.subscribe.apply(event, arguments);
}
}, null, ['subscribe']);
target.on('not-test', function (e) {
console.log('#2 EventTarget (smart event). Should be EventFacade ->', e);
});
target.fire('test');
});
</script>
</body>
</html>