1
YUI.add('event-synthetic-tests', function(Y) {
3
Y.Node.prototype.click = function (options) {
4
Y.Event.simulate(this._node, 'click', options);
6
Y.NodeList.importMethod(Y.Node.prototype, 'click');
10
var suite = new Y.Test.Suite("Y.SyntheticEvent"),
11
areSame = Y.Assert.areSame;
13
function initTestbed() {
14
var testbed = Y.one('#testbed'),
19
testbed = body.create('<div id="testbed"></div>');
20
body.prepend(testbed);
25
'<button id="button1">Button 1 text</button>' +
26
'<ul class="nested">' +
27
'<li id="item1">Item 1</li>' +
28
'<li id="item2" class="nested">Item 2</li>' +
29
'<li id="item3"><p>Item 3</p></li>' +
32
'<p id="p1_no">no</p>' +
33
'<p id="p2_yes">yes</p>' +
34
'<div id="inner_1">' +
35
'<p id="inner_1_p1_no"><em>no</em></p>' +
36
'<p id="inner_1_p2_yes">yes</p>' +
38
'<p id="p3_no">no</p>' +
43
function initSynth() {
44
Y.Event.define('synth', {
45
on: function (node, sub, notifier, filter) {
46
var method = (filter) ? 'delegate' : 'on';
48
sub._handle = node[method]('click',
49
Y.bind(notifier.fire, notifier), filter);
52
delegate: function () {
53
this.on.apply(this, arguments);
56
detach: function (node, sub) {
60
detachDelegate: function () {
61
this.detach.apply(this, arguments);
71
function destroyTestbed() {
72
var testbed = Y.one('#testbed');
74
testbed.purge(true).remove();
78
function undefineSynth() {
79
delete Y.Node.DOM_EVENTS.synth;
80
delete Y.Env.evt.plugins.synth;
88
/******************************************************************************/
89
/****************************** Tests begin here ****************************/
90
/******************************************************************************/
92
suite.add(new Y.Test.Case({
93
name: "Y.Event.define",
95
"Y.Event.define(name) should add to DOM_EVENTS": function () {
96
delete Y.Node.DOM_EVENTS.mouseover;
98
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
100
Y.Event.define('mouseover');
102
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
105
"Y.Event.define([name1, name2]) should add to DOM_EVENTS": function () {
106
delete Y.Node.DOM_EVENTS.mouseover;
107
delete Y.Node.DOM_EVENTS.mouseout;
109
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
110
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseout);
112
Y.Event.define(['mouseover', 'mouseout']);
114
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
115
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseout);
118
"Y.Event.define(type, {...}) should register a new synth in DOM_EVENTS": function () {
119
Y.Event.define('synth', {
123
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
124
Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
125
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
126
areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
129
"Subsequent Y.Event.define() should not overwrite existing synth": function () {
130
Y.Event.define('synth', {
134
areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
137
"Y.Event.define(..., true) should overwrite existing synth": function () {
138
Y.Event.define('synth', {
142
areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
145
"Y.Event.define({ type: ...}) should register a new synth in DOM_EVENTS": function () {
146
delete Y.Node.DOM_EVENTS.synth;
153
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
154
Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
155
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
156
areSame(Y.Node.DOM_EVENTS.synth, Y.Env.evt.plugins.synth);
157
areSame(3, Y.Node.DOM_EVENTS.synth.eventDef.index);
160
"Y.Event.define({...}, true) should overwrite existing synth": function () {
166
areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
171
suite.add(new Y.Test.Case({
177
"test Y.on('synth', fn, node)": function () {
178
var target = Y.one("#item3"),
179
type, currentTarget, thisObj;
181
Y.on('synth', function (e) {
183
currentTarget = e.currentTarget;
189
areSame('synth', type);
190
areSame(target, currentTarget);
191
areSame(target, thisObj);
194
"test Y.on('synth', fn, node, thisObj)": function () {
195
var target = Y.one("#item3"),
196
obj = { foo: 'bar' },
197
type, currentTarget, thisObj, foo;
199
Y.on('synth', function (e) {
201
currentTarget = e.currentTarget;
208
areSame('synth', type);
209
areSame(target, currentTarget);
210
areSame(obj, thisObj);
211
areSame(obj.foo, thisObj.foo);
214
"test Y.on('synth', fn, node, thisObj, arg)": function () {
215
var target = Y.one("#item3"),
216
obj = { foo: 'bar' },
217
type, currentTarget, thisObj, foo, arg;
219
Y.on('synth', function (e, x) {
221
currentTarget = e.currentTarget;
225
}, target, obj, 'arg!');
229
areSame('synth', type);
230
areSame(target, currentTarget);
231
areSame(obj, thisObj);
232
areSame(obj.foo, thisObj.foo);
233
areSame('arg!', arg);
236
"test Y.on('synth', fn, node, null, arg)": function () {
237
var target = Y.one("#item3"),
238
type, currentTarget, thisObj, arg;
240
Y.on('synth', function (e, x) {
242
currentTarget = e.currentTarget;
245
}, target, null, 'arg!');
249
areSame('synth', type);
250
areSame(target, currentTarget);
251
areSame(target, thisObj);
252
areSame('arg!', arg);
255
"test Y.on('synth', fn, el)": function () {
256
var targetEl = Y.DOM.byId('item3'),
257
target = Y.one(targetEl),
258
type, currentTarget, thisObj;
260
Y.on('synth', function (e) {
262
currentTarget = e.currentTarget;
268
areSame('synth', type);
269
areSame(target, currentTarget);
270
areSame(target, thisObj);
273
"test Y.on('synth', fn, el, thisObj)": function () {
274
var targetEl = Y.DOM.byId("item3"),
275
target = Y.one(targetEl),
276
obj = { foo: 'bar' },
277
type, currentTarget, thisObj, foo;
279
Y.on('synth', function (e) {
281
currentTarget = e.currentTarget;
288
areSame('synth', type);
289
areSame(target, currentTarget);
290
areSame(obj, thisObj);
291
areSame(obj.foo, thisObj.foo);
294
"test Y.on('synth', fn, el, thisObj, arg)": function () {
295
var targetEl = Y.DOM.byId("item3"),
296
target = Y.one(targetEl),
297
obj = { foo: 'bar' },
298
type, currentTarget, thisObj, foo, arg;
300
Y.on('synth', function (e, x) {
302
currentTarget = e.currentTarget;
306
}, targetEl, obj, 'arg!');
310
areSame('synth', type);
311
areSame(target, currentTarget);
312
areSame(obj, thisObj);
313
areSame(obj.foo, thisObj.foo);
314
areSame('arg!', arg);
317
"test Y.on('synth', fn, el, null, arg)": function () {
318
var targetEl = Y.DOM.byId("item3"),
319
target = Y.one(targetEl),
320
type, currentTarget, thisObj, arg;
322
Y.on('synth', function (e, x) {
324
currentTarget = e.currentTarget;
327
}, targetEl, null, 'arg!');
331
areSame('synth', type);
332
areSame(target, currentTarget);
333
areSame(target, thisObj);
334
areSame('arg!', arg);
337
"test Y.on('synth', fn, selectorOne)": function () {
338
var target = Y.one('#item3'),
339
type, currentTarget, thisObj;
341
Y.on('synth', function (e) {
343
currentTarget = e.currentTarget;
349
areSame('synth', type);
350
areSame(target, currentTarget);
351
areSame(target, thisObj);
354
"test Y.on('synth', fn, selectorOne, thisObj)": function () {
355
var target = Y.one('#item3'),
356
obj = { foo: 'bar' },
357
type, currentTarget, thisObj, foo;
359
Y.on('synth', function (e) {
361
currentTarget = e.currentTarget;
368
areSame('synth', type);
369
areSame(target, currentTarget);
370
areSame(obj, thisObj);
371
areSame(obj.foo, thisObj.foo);
374
"test Y.on('synth', fn, selectorOne, thisObj, arg)": function () {
375
var target = Y.one('#item3'),
376
obj = { foo: 'bar' },
377
type, currentTarget, thisObj, foo, arg;
379
Y.on('synth', function (e, x) {
381
currentTarget = e.currentTarget;
385
}, '#item3', obj, 'arg!');
389
areSame('synth', type);
390
areSame(target, currentTarget);
391
areSame(obj, thisObj);
392
areSame(obj.foo, thisObj.foo);
393
areSame('arg!', arg);
396
"test Y.on('synth', fn, selectorOne, null, arg)": function () {
397
var target = Y.one('#item3'),
398
type, currentTarget, thisObj, arg;
400
Y.on('synth', function (e, x) {
402
currentTarget = e.currentTarget;
405
}, '#item3', null, 'arg!');
409
areSame('synth', type);
410
areSame(target, currentTarget);
411
areSame(target, thisObj);
412
areSame('arg!', arg);
415
"test Y.on('synth', fn, selectorMultiple)": function () {
416
var item1 = Y.one('#item1'),
417
item2 = Y.one('#item2'),
418
item3 = Y.one('#item3'),
423
Y.on('synth', function (e) {
425
currentTarget.push(e.currentTarget);
433
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
434
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
435
Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
438
"test Y.on('synth', fn, selectorMultiple, thisObj)": function () {
439
var item1 = Y.one('#item1'),
440
item2 = Y.one('#item2'),
441
item3 = Y.one('#item3'),
442
obj = { foo: 'bar' },
448
Y.on('synth', function (e) {
450
currentTarget.push(e.currentTarget);
453
}, '#outer li', obj);
459
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
460
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
461
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
462
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
465
"test Y.on('synth', fn, selectorMultiple, thisObj, arg)": function () {
466
var item1 = Y.one('#item1'),
467
item2 = Y.one('#item2'),
468
item3 = Y.one('#item3'),
469
obj = { foo: 'bar' },
476
Y.on('synth', function (e, x) {
478
currentTarget.push(e.currentTarget);
482
}, '#outer li', obj, 'arg!');
488
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
489
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
490
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
491
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
492
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
495
"test Y.on('synth', fn, selectorMultiple, null, arg)": function () {
496
var item1 = Y.one('#item1'),
497
item2 = Y.one('#item2'),
498
item3 = Y.one('#item3'),
504
Y.on('synth', function (e, x) {
506
currentTarget.push(e.currentTarget);
509
}, '#outer li', null, 'arg!');
515
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
516
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
517
Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
518
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
521
"test Y.on('synth', fn, notYetAvailable)": function () {
522
var inner = Y.one('#inner'),
528
inner.all('#p4').remove();
530
Y.on('synth', function (e) {
532
currentTarget = e.currentTarget;
536
inner.append("<p id='p4'>Added</p>");
538
// This is a tainted test because it's using a different synthetic
539
// event to test that the synthetic event infrastructure is working
540
// properly. The other option is to use Y.later, but that opens a race
541
// condition. The test is left in place because something is better
543
Y.on("available", function () {
544
test.resume(function () {
545
var p4 = inner.one('#p4');
548
areSame('synth', type);
549
areSame(p4, currentTarget);
550
areSame(p4, thisObj);
552
Y.Assert.fail("Something is wrong with onAvailable");
560
"test Y.on('synth', fn, notYetAvailable, thisObj)": function () {
561
var inner = Y.one('#inner'),
563
obj = { foo: 'bar' },
564
type, currentTarget, thisObj, foo;
566
inner.all('#p4').remove();
568
Y.on('synth', function (e) {
570
currentTarget = e.currentTarget;
575
inner.append("<p id='p4'>Added</p>");
577
// This is a tainted test because it's using a different synthetic
578
// event to test that the synthetic event infrastructure is working
579
// properly. The other option is to use Y.later, but that opens a race
580
// condition. The test is left in place because something is better
582
Y.on("available", function () {
583
test.resume(function () {
584
var p4 = inner.one('#p4');
587
areSame('synth', type);
588
areSame(p4, currentTarget);
589
areSame(obj, thisObj);
592
Y.Assert.fail("Something is wrong with onAvailable");
600
"test Y.on('synth', fn, notYetAvailable, thisObj, arg)": function () {
601
var inner = Y.one('#inner'),
603
obj = { foo: 'bar' },
604
type, currentTarget, thisObj, foo, arg;
606
inner.all('#p4').remove();
608
Y.on('synth', function (e, x) {
610
currentTarget = e.currentTarget;
614
}, '#p4', obj, 'arg!');
616
inner.append("<p id='p4'>Added</p>");
618
// This is a tainted test because it's using a different synthetic
619
// event to test that the synthetic event infrastructure is working
620
// properly. The other option is to use Y.later, but that opens a race
621
// condition. The test is left in place because something is better
623
Y.on("available", function () {
624
test.resume(function () {
625
var p4 = inner.one('#p4');
628
areSame('synth', type);
629
areSame(p4, currentTarget);
630
areSame(obj, thisObj);
632
areSame('arg!', arg);
634
Y.Assert.fail("Something is wrong with onAvailable");
642
"test Y.on('synth', fn, notYetAvailable, null, arg)": function () {
643
var inner = Y.one('#inner'),
645
type, currentTarget, thisObj, arg;
647
inner.all('#p4').remove();
649
Y.on('synth', function (e, x) {
651
currentTarget = e.currentTarget;
654
}, '#p4', null, 'arg!');
656
inner.append("<p id='p4'>Added</p>");
658
// This is a tainted test because it's using a different synthetic
659
// event to test that the synthetic event infrastructure is working
660
// properly. The other option is to use Y.later, but that opens a race
661
// condition. The test is left in place because something is better
663
Y.on("available", function () {
664
test.resume(function () {
665
var p4 = inner.one('#p4');
668
areSame('synth', type);
669
areSame(p4, currentTarget);
670
areSame(p4, thisObj);
671
areSame('arg!', arg);
673
Y.Assert.fail("Something is wrong with onAvailable");
681
"test Y.on('synth', fn) defaults to window": function (){
682
var handle = Y.on('synth', function (e) {});
684
areSame(Y.one(Y.config.win), handle.sub.node);
691
suite.add(new Y.Test.Case({
697
"test node.on(x, fn)": function () {
698
var target = Y.one("#item3"),
699
type, currentTarget, thisObj;
701
target.on('synth', function (e) {
703
currentTarget = e.currentTarget;
709
areSame('synth', type);
710
areSame(target, currentTarget);
711
areSame(target, thisObj);
714
"test node.on(x, fn, thisObj)": function () {
715
var target = Y.one("#item3"),
716
obj = { foo: 'bar' },
717
type, currentTarget, thisObj, foo;
719
target.on('synth', function (e) {
721
currentTarget = e.currentTarget;
728
areSame('synth', type);
729
areSame(target, currentTarget);
730
areSame(obj, thisObj);
731
areSame(obj.foo, thisObj.foo);
734
"test node.on(x, fn, thisObj, arg)": function () {
735
var target = Y.one("#item3"),
736
obj = { foo: 'bar' },
737
type, currentTarget, thisObj, foo, arg;
739
target.on('synth', function (e, x) {
741
currentTarget = e.currentTarget;
749
areSame('synth', type);
750
areSame(target, currentTarget);
751
areSame(obj, thisObj);
752
areSame(obj.foo, thisObj.foo);
753
areSame('arg!', arg);
756
"test node.on(x, fn, null, arg)": function () {
757
var target = Y.one("#item3"),
758
type, currentTarget, thisObj, arg;
760
target.on('synth', function (e, x) {
762
currentTarget = e.currentTarget;
769
areSame('synth', type);
770
areSame(target, currentTarget);
771
areSame(target, thisObj);
772
areSame('arg!', arg);
776
suite.add(new Y.Test.Case({
782
"test nodelist.on(x, fn)": function () {
783
var targets = Y.all("#inner p"),
788
targets.on('synth', function (e) {
790
currentTarget.push(e.currentTarget);
794
Y.one("#p1_no").click();
795
Y.one("#p3_no").click();
796
Y.one("#inner_1_p1_no").click();
798
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
799
Y.ArrayAssert.itemsAreSame(
800
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
802
Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
805
"test nodelist.on(x, fn, thisObj)": function () {
806
var targets = Y.all("#inner p"),
807
obj = { foo: 'bar' },
813
targets.on('synth', function (e) {
815
currentTarget.push(e.currentTarget);
820
Y.one("#p1_no").click();
821
Y.one("#p3_no").click();
822
Y.one("#inner_1_p1_no").click();
824
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
825
Y.ArrayAssert.itemsAreSame(
826
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
828
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
829
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
832
"test nodelist.on(x, fn, thisObj, arg)": function () {
833
var targets = Y.all("#inner p"),
834
obj = { foo: 'bar' },
841
targets.on('synth', function (e, x) {
843
currentTarget.push(e.currentTarget);
849
Y.one("#p1_no").click();
850
Y.one("#p3_no").click();
851
Y.one("#inner_1_p1_no").click();
853
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
854
Y.ArrayAssert.itemsAreSame(
855
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
857
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
858
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
859
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
862
"test nodelist.on(x, fn, null, arg)": function () {
863
var targets = Y.all("#inner p"),
869
targets.on('synth', function (e, x) {
871
currentTarget.push(e.currentTarget);
876
Y.one("#p1_no").click();
877
Y.one("#p3_no").click();
878
Y.one("#inner_1_p1_no").click();
880
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
881
Y.ArrayAssert.itemsAreSame(
882
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
884
Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
885
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
889
suite.add(new Y.Test.Case({
895
initUniqueSynth: function () {
896
Y.Event.define('synth', {
899
on: function (node, sub, notifier, filter) {
900
var method = (filter) ? 'delegate' : 'on';
902
sub._handle = node[method]('click',
903
Y.bind(notifier.fire, notifier), filter);
906
detach: function (node, sub) {
907
sub._handle.detach();
912
"node.on(x, fn) + node.on(x, fn) should allow dups": function () {
915
var target = Y.one("#item1"),
918
function increment() {
922
target.on('synth', increment);
923
target.on('synth', increment);
925
Y.one("#item1").click();
930
"Y.on(x, fn) + node.on(x, fn) should allow dups": function () {
935
function increment() {
939
Y.one('#item1').on('synth', increment);
940
Y.on('synth', increment, '#item1');
942
Y.one("#item1").click();
947
"nodelist.on(x, fn) + node.on(x, fn) should allow dups": function () {
952
function increment() {
956
Y.all("#item1").on('synth', increment);
957
Y.one("#item1").on('synth', increment);
959
Y.one("#item1").click();
964
"preventDups:true node.on(x, fn) + node.on(x, fn) should prevent dups": function () {
965
this.initUniqueSynth();
967
var target = Y.one("#item1"),
970
function increment() {
974
target.on('synth', increment);
975
target.on('synth', increment);
977
Y.one("#item1").click();
982
"preventDups:true Y.on(x, fn) + node.on(x, fn) should prevent dups": function () {
983
this.initUniqueSynth();
987
function increment() {
991
Y.one('#item1').on('synth', increment);
992
Y.on('synth', increment, '#item1');
994
Y.one("#item1").click();
999
"preventDups:true nodelist.on(x, fn) + node.on(x, fn) should prevent dups": function () {
1000
this.initUniqueSynth();
1004
function increment() {
1008
Y.all("#item1").on('synth', increment);
1009
Y.one("#item1").on('synth', increment);
1011
Y.one("#item1").click();
1017
suite.add(new Y.Test.Case({
1018
name: "node.delegate",
1023
"test node.delegate(synth, fn, filter)": function () {
1030
inner = Y.one("#inner"),
1031
a = Y.one("#p1_no"),
1032
b = Y.one("#inner_1_p1_no em");
1034
inner.delegate('synth', function (e) {
1037
target.push(e.target);
1038
currentTarget.push(e.currentTarget);
1040
container.push(e.container);
1046
Y.ArrayAssert.itemsAreSame(['synth'], type);
1047
Y.ArrayAssert.itemsAreSame([a], target);
1048
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1049
Y.ArrayAssert.itemsAreSame([a], thisObj);
1050
Y.ArrayAssert.itemsAreSame([inner], container);
1055
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1056
Y.ArrayAssert.itemsAreSame([a, b], target);
1057
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1058
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1059
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1062
"test node.delegate(synth, fn, filter, thisObj)": function () {
1064
obj = { foo: "bar" },
1071
inner = Y.one("#inner"),
1072
a = Y.one("#p1_no"),
1073
b = Y.one("#inner_1_p1_no em");
1075
inner.delegate('synth', function (e) {
1078
target.push(e.target);
1079
currentTarget.push(e.currentTarget);
1082
container.push(e.container);
1088
Y.ArrayAssert.itemsAreSame(['synth'], type);
1089
Y.ArrayAssert.itemsAreSame([a], target);
1090
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1091
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1092
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1093
Y.ArrayAssert.itemsAreSame([inner], container);
1098
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1099
Y.ArrayAssert.itemsAreSame([a, b], target);
1100
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1101
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1102
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1103
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1106
"test node.delegate(synth, fn, filter, thisObj, arg)": function () {
1108
obj = { foo: "bar" },
1116
inner = Y.one("#inner"),
1117
a = Y.one("#p1_no"),
1118
b = Y.one("#inner_1_p1_no em");
1120
inner.delegate('synth', function (e, x) {
1123
target.push(e.target);
1124
currentTarget.push(e.currentTarget);
1128
container.push(e.container);
1129
}, 'p', obj, 'arg!');
1134
Y.ArrayAssert.itemsAreSame(['synth'], type);
1135
Y.ArrayAssert.itemsAreSame([a], target);
1136
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1137
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1138
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1139
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1140
Y.ArrayAssert.itemsAreSame([inner], container);
1145
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1146
Y.ArrayAssert.itemsAreSame([a, b], target);
1147
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1148
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1149
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1150
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1151
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1154
"test node.delegate(synth, fn, filter, null, arg)": function () {
1162
inner = Y.one("#inner"),
1163
a = Y.one("#p1_no"),
1164
b = Y.one("#inner_1_p1_no em");
1166
inner.delegate('synth', function (e, x) {
1169
target.push(e.target);
1170
currentTarget.push(e.currentTarget);
1173
container.push(e.container);
1174
}, 'p', null, "arg!");
1179
Y.ArrayAssert.itemsAreSame(['synth'], type);
1180
Y.ArrayAssert.itemsAreSame([a], target);
1181
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1182
Y.ArrayAssert.itemsAreSame([a], thisObj);
1183
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1184
Y.ArrayAssert.itemsAreSame([inner], container);
1189
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1190
Y.ArrayAssert.itemsAreSame([a, b], target);
1191
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1192
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1193
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1194
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1199
suite.add(new Y.Test.Case({
1205
"test Y.delegate(synth, fn, node, filter)": function () {
1212
inner = Y.one("#inner"),
1213
a = Y.one("#p1_no"),
1214
b = Y.one("#inner_1_p1_no em");
1216
Y.delegate('synth', function (e) {
1219
target.push(e.target);
1220
currentTarget.push(e.currentTarget);
1222
container.push(e.container);
1228
Y.ArrayAssert.itemsAreSame(['synth'], type);
1229
Y.ArrayAssert.itemsAreSame([a], target);
1230
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1231
Y.ArrayAssert.itemsAreSame([a], thisObj);
1232
Y.ArrayAssert.itemsAreSame([inner], container);
1237
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1238
Y.ArrayAssert.itemsAreSame([a, b], target);
1239
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1240
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1241
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1244
"test Y.delegate(synth, fn, el, filter)": function () {
1251
inner = Y.one("#inner"),
1252
a = Y.one("#p1_no"),
1253
b = Y.one("#inner_1_p1_no em");
1255
Y.delegate('synth', function (e) {
1258
target.push(e.target);
1259
currentTarget.push(e.currentTarget);
1261
container.push(e.container);
1262
}, inner._node, 'p');
1267
Y.ArrayAssert.itemsAreSame(['synth'], type);
1268
Y.ArrayAssert.itemsAreSame([a], target);
1269
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1270
Y.ArrayAssert.itemsAreSame([a], thisObj);
1271
Y.ArrayAssert.itemsAreSame([inner], container);
1276
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1277
Y.ArrayAssert.itemsAreSame([a, b], target);
1278
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1279
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1280
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1283
"test Y.delegate(synth, fn, selectorOne, filter)": function () {
1290
inner = Y.one("#inner"),
1291
a = Y.one("#p1_no"),
1292
b = Y.one("#inner_1_p1_no em");
1294
Y.delegate('synth', function (e) {
1297
target.push(e.target);
1298
currentTarget.push(e.currentTarget);
1300
container.push(e.container);
1306
Y.ArrayAssert.itemsAreSame(['synth'], type);
1307
Y.ArrayAssert.itemsAreSame([a], target);
1308
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1309
Y.ArrayAssert.itemsAreSame([a], thisObj);
1310
Y.ArrayAssert.itemsAreSame([inner], container);
1315
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1316
Y.ArrayAssert.itemsAreSame([a, b], target);
1317
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1318
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1319
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1322
"test Y.delegate(synth, fn, node, filter, thisObj)": function () {
1324
obj = { foo: "bar" },
1331
inner = Y.one("#inner"),
1332
a = Y.one("#p1_no"),
1333
b = Y.one("#inner_1_p1_no em");
1335
Y.delegate('synth', function (e) {
1338
target.push(e.target);
1339
currentTarget.push(e.currentTarget);
1342
container.push(e.container);
1343
}, inner, 'p', obj);
1348
Y.ArrayAssert.itemsAreSame(['synth'], type);
1349
Y.ArrayAssert.itemsAreSame([a], target);
1350
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1351
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1352
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1353
Y.ArrayAssert.itemsAreSame([inner], container);
1358
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1359
Y.ArrayAssert.itemsAreSame([a, b], target);
1360
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1361
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1362
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1363
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1366
"test Y.delegate(synth, fn, node, filter, thisObj, arg)": function () {
1368
obj = { foo: "bar" },
1376
inner = Y.one("#inner"),
1377
a = Y.one("#p1_no"),
1378
b = Y.one("#inner_1_p1_no em");
1380
Y.delegate('synth', function (e, x) {
1383
target.push(e.target);
1384
currentTarget.push(e.currentTarget);
1388
container.push(e.container);
1389
}, inner, 'p', obj, 'arg!');
1394
Y.ArrayAssert.itemsAreSame(['synth'], type);
1395
Y.ArrayAssert.itemsAreSame([a], target);
1396
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1397
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1398
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1399
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1400
Y.ArrayAssert.itemsAreSame([inner], container);
1405
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1406
Y.ArrayAssert.itemsAreSame([a, b], target);
1407
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1408
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1409
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1410
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1411
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1414
"test Y.delegate(synth, fn, node, filter, null, arg)": function () {
1422
inner = Y.one("#inner"),
1423
a = Y.one("#p1_no"),
1424
b = Y.one("#inner_1_p1_no em");
1426
Y.delegate('synth', function (e, x) {
1429
target.push(e.target);
1430
currentTarget.push(e.currentTarget);
1433
container.push(e.container);
1434
}, inner, 'p', null, "arg!");
1439
Y.ArrayAssert.itemsAreSame(['synth'], type);
1440
Y.ArrayAssert.itemsAreSame([a], target);
1441
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1442
Y.ArrayAssert.itemsAreSame([a], thisObj);
1443
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1444
Y.ArrayAssert.itemsAreSame([inner], container);
1449
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1450
Y.ArrayAssert.itemsAreSame([a, b], target);
1451
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1452
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1453
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1454
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1457
"test Y.delegate(synth, fn, notAvailableYet, filter)": function () {
1458
var inner = Y.one('#inner'),
1469
Y.delegate('synth', function (e) {
1472
target.push(e.target);
1473
currentTarget.push(e.currentTarget);
1475
container.push(e.container);
1476
}, '#inner_1', 'p');
1478
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1480
// This is a tainted test because it's using a different synthetic
1481
// event to test that the synthetic event infrastructure is working
1482
// properly. The other option is to use Y.later, but that opens a race
1483
// condition. The test is left in place because something is better
1485
Y.on("available", function () {
1486
test.resume(function () {
1487
var a = inner.one('#pass1'),
1488
b = inner.one('#pass2-trigger'),
1489
inner1 = inner.one('#inner_1');
1491
if (a && b && inner1) {
1495
Y.ArrayAssert.itemsAreSame(['synth'], type);
1496
Y.ArrayAssert.itemsAreSame([a], target);
1497
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1498
Y.ArrayAssert.itemsAreSame([a], thisObj);
1499
Y.ArrayAssert.itemsAreSame([inner1], container);
1504
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1505
Y.ArrayAssert.itemsAreSame([a, b], target);
1506
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1507
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1508
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1510
Y.Assert.fail("Something is wrong with onAvailable");
1513
}, '#pass2-trigger');
1518
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj)": function () {
1519
var inner = Y.one('#inner'),
1520
obj = { foo: 'bar' },
1532
Y.delegate('synth', function (e) {
1535
target.push(e.target);
1536
currentTarget.push(e.currentTarget);
1539
container.push(e.container);
1540
}, '#inner_1', 'p', obj);
1542
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1544
// This is a tainted test because it's using a different synthetic
1545
// event to test that the synthetic event infrastructure is working
1546
// properly. The other option is to use Y.later, but that opens a race
1547
// condition. The test is left in place because something is better
1549
Y.on("available", function () {
1550
test.resume(function () {
1551
var a = inner.one('#pass1'),
1552
b = inner.one('#pass2-trigger'),
1553
inner1 = inner.one('#inner_1');
1555
if (a && b && inner1) {
1559
Y.ArrayAssert.itemsAreSame(['synth'], type);
1560
Y.ArrayAssert.itemsAreSame([a], target);
1561
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1562
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1563
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1564
Y.ArrayAssert.itemsAreSame([inner1], container);
1569
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1570
Y.ArrayAssert.itemsAreSame([a, b], target);
1571
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1572
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1573
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1574
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1576
Y.Assert.fail("Something is wrong with onAvailable");
1579
}, '#pass2-trigger');
1584
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj, arg)": function () {
1585
var inner = Y.one('#inner'),
1586
obj = { foo: 'bar' },
1599
Y.delegate('synth', function (e, x) {
1602
target.push(e.target);
1603
currentTarget.push(e.currentTarget);
1607
container.push(e.container);
1608
}, '#inner_1', 'p', obj, "arg!");
1610
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1612
// This is a tainted test because it's using a different synthetic
1613
// event to test that the synthetic event infrastructure is working
1614
// properly. The other option is to use Y.later, but that opens a race
1615
// condition. The test is left in place because something is better
1617
Y.on("available", function () {
1618
test.resume(function () {
1619
var a = inner.one('#pass1'),
1620
b = inner.one('#pass2-trigger'),
1621
inner1 = inner.one('#inner_1');
1623
if (a && b && inner1) {
1627
Y.ArrayAssert.itemsAreSame(['synth'], type);
1628
Y.ArrayAssert.itemsAreSame([a], target);
1629
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1630
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1631
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1632
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1633
Y.ArrayAssert.itemsAreSame([inner1], container);
1638
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1639
Y.ArrayAssert.itemsAreSame([a, b], target);
1640
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1641
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1642
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1643
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1644
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1646
Y.Assert.fail("Something is wrong with onAvailable");
1649
}, '#pass2-trigger');
1654
"test Y.delegate(synth, fn, notAvailableYet, filter, null, arg)": function () {
1655
var inner = Y.one('#inner'),
1667
Y.delegate('synth', function (e, x) {
1670
target.push(e.target);
1671
currentTarget.push(e.currentTarget);
1674
container.push(e.container);
1675
}, '#inner_1', 'p', null, "arg!");
1677
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1679
// This is a tainted test because it's using a different synthetic
1680
// event to test that the synthetic event infrastructure is working
1681
// properly. The other option is to use Y.later, but that opens a race
1682
// condition. The test is left in place because something is better
1684
Y.on("available", function () {
1685
test.resume(function () {
1686
var a = inner.one('#pass1'),
1687
b = inner.one('#pass2-trigger'),
1688
inner1 = inner.one('#inner_1');
1690
if (a && b && inner1) {
1694
Y.ArrayAssert.itemsAreSame(['synth'], type);
1695
Y.ArrayAssert.itemsAreSame([a], target);
1696
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1697
Y.ArrayAssert.itemsAreSame([a], thisObj);
1698
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1699
Y.ArrayAssert.itemsAreSame([inner1], container);
1704
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1705
Y.ArrayAssert.itemsAreSame([a, b], target);
1706
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1707
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1708
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1709
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1711
Y.Assert.fail("Something is wrong with onAvailable");
1714
}, '#pass2-trigger');
1719
"test Y.delegate(synth, fn, selectorMulti, filter)": function () {
1726
nested = Y.one('.nested'),
1727
inner = Y.one('#inner'),
1728
a = Y.one('#item3 p'),
1729
b = Y.one("#inner_1_p1_no em");
1731
Y.delegate('synth', function (e) {
1734
target.push(e.target);
1735
currentTarget.push(e.currentTarget);
1737
container.push(e.container);
1738
}, ".nested, #inner", 'p');
1743
Y.ArrayAssert.itemsAreSame(['synth'], type);
1744
Y.ArrayAssert.itemsAreSame([a], target);
1745
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1746
Y.ArrayAssert.itemsAreSame([a], thisObj);
1747
Y.ArrayAssert.itemsAreSame([nested], container);
1752
Y.ArrayAssert.itemsAreSame(['synth', 'synth'], type);
1753
Y.ArrayAssert.itemsAreSame([a, b], target);
1754
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1755
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1756
Y.ArrayAssert.itemsAreSame([nested, inner], container);
1761
suite.add(new Y.Test.Case({
1769
// TODO: Can this be made to work?
1770
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": true,
1771
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": true,
1772
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": true,
1773
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": true,
1774
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": true,
1775
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": true
1779
"test node.on() + node.detach(synth, fn)": function () {
1781
target = Y.one('#button1');
1787
target.on('synth', fn);
1793
target.detach('synth', fn);
1799
target.on('synth', fn);
1800
target.on('synth', fn);
1801
target.on('click', fn);
1807
target.detach('synth', fn);
1814
"test node.on(synth, fn, thisObj) + node.detach(synth, fn)": function () {
1818
target = Y.one('#button1');
1824
target.on('synth', fn, a);
1830
target.detach('synth', fn);
1836
target.on('synth', fn, a);
1837
target.on('synth', fn, b);
1843
target.detach('synth', fn);
1850
"test node.on() + node.detach(synth)": function () {
1852
target = Y.one('#button1');
1858
target.on('synth', fn);
1864
target.detach('synth');
1870
target.on('synth', fn);
1871
target.on('synth', fn);
1872
target.on('click', fn);
1878
target.detach('synth');
1885
"test node.on() + node.detach()": function () {
1887
target = Y.one('#button1');
1893
target.on('synth', fn);
1905
target.on('synth', fn);
1906
target.on('synth', fn);
1907
target.on('click', fn);
1920
"test node.on() + node.detachAll()": function () {
1922
target = Y.one('#button1');
1928
target.on('synth', fn);
1940
target.on('synth', fn);
1941
target.on('synth', fn);
1942
target.on('click', fn);
1955
"test node.on() + node.purge(true, synth)": function () {
1957
target = Y.one('#button1');
1963
target.on('synth', fn);
1969
target.purge(true, 'synth');
1975
target.on('synth', fn);
1976
target.on('synth', fn);
1977
target.on('click', fn);
1983
target.purge(true, 'synth');
1990
"test node.on() + parent.purge(true, synth)": function () {
1992
target = Y.one('#button1'),
1993
parent = target.get('parentNode');
1999
target.on('synth', fn);
2005
parent.purge(true, 'synth');
2011
target.on('synth', fn);
2012
target.on('synth', fn);
2013
target.on('click', fn);
2019
parent.purge(true, 'synth');
2026
"test nodelist.on(synth, fn) + node.detach(synth, fn)": function () {
2028
all = Y.all('.nested li'),
2031
function increment() {
2035
all.on('synth', increment);
2041
item.detach('synth', increment);
2048
"test nodelist.on(synth, fn) + node.detach(synth)": function () {
2050
all = Y.all('.nested li'),
2053
function increment() {
2057
all.on('synth', increment);
2063
item.detach('synth');
2070
"test node.on(synth, fn) + nodelist.detach(synth, fn)": function () {
2072
all = Y.all('.nested li'),
2075
function increment() {
2079
item.on('synth', increment);
2085
all.detach('synth', increment);
2092
"test node.on(synth, fn) + nodelist.detach(synth)": function () {
2094
all = Y.all('.nested li'),
2097
function increment() {
2101
item.on('synth', increment);
2107
all.detach('synth');
2114
"test node.on() + handle.detach()": function () {
2116
item = Y.one('#button1'),
2119
function increment() {
2123
sub = item.on('synth', increment);
2136
"test nodelist.on() + handle.detach()": function () {
2138
items = Y.all('.nested li'),
2139
one = items.item(0),
2140
two = items.item(1),
2141
three = items.item(2),
2144
function increment() {
2148
sub = items.on('synth', increment);
2171
"test nodelist.on() + nodelist.detach(synth, fn)": function () {
2173
items = Y.all('.nested li');
2179
items.on('synth', fn);
2181
items.item(0).click();
2182
items.item(1).click();
2183
items.item(2).click();
2187
items.detach('synth', fn);
2190
items.item(0).click();
2191
items.item(1).click();
2192
items.item(2).click();
2196
items.on('synth', fn);
2197
items.on('synth', fn);
2198
items.on('click', fn);
2201
items.item(0).click();
2202
items.item(1).click();
2203
items.item(2).click();
2207
items.detach('synth', fn);
2210
items.item(0).click();
2211
items.item(1).click();
2212
items.item(2).click();
2217
"test nodelist.on(synth, fn, thisObj) + nodelist.detach(synth, fn)": function () {
2221
items = Y.all('.nested li');
2227
items.on('synth', fn, a);
2229
items.item(0).click();
2230
items.item(1).click();
2231
items.item(2).click();
2235
items.detach('synth', fn);
2238
items.item(0).click();
2239
items.item(1).click();
2240
items.item(2).click();
2244
items.on('synth', fn, a);
2245
items.on('synth', fn, b);
2248
items.item(0).click();
2249
items.item(1).click();
2250
items.item(2).click();
2254
items.detach('synth', fn);
2257
items.item(0).click();
2258
items.item(1).click();
2259
items.item(2).click();
2264
"test nodelist.on() + nodelist.detach(synth)": function () {
2266
items = Y.all('.nested li');
2272
items.on('synth', fn);
2274
items.item(0).click();
2275
items.item(1).click();
2276
items.item(2).click();
2280
items.detach('synth');
2283
items.item(0).click();
2284
items.item(1).click();
2285
items.item(2).click();
2289
items.on('synth', fn);
2290
items.on('synth', fn);
2291
items.on('click', fn);
2294
items.item(0).click();
2295
items.item(1).click();
2296
items.item(2).click();
2300
items.detach('synth');
2303
items.item(0).click();
2304
items.item(1).click();
2305
items.item(2).click();
2310
"test nodelist.on() + nodelist.detach()": function () {
2312
items = Y.all('.nested li');
2318
items.on('synth', fn);
2320
items.item(0).click();
2321
items.item(1).click();
2322
items.item(2).click();
2329
items.item(0).click();
2330
items.item(1).click();
2331
items.item(2).click();
2335
items.on('synth', fn);
2336
items.on('synth', fn);
2337
items.on('click', fn);
2340
items.item(0).click();
2341
items.item(1).click();
2342
items.item(2).click();
2349
items.item(0).click();
2350
items.item(1).click();
2351
items.item(2).click();
2356
"test nodelist.on() + nodelist.detachAll()": function () {
2358
items = Y.all('.nested li');
2364
items.on('synth', fn);
2366
items.item(0).click();
2367
items.item(1).click();
2368
items.item(2).click();
2375
items.item(0).click();
2376
items.item(1).click();
2377
items.item(2).click();
2381
items.on('synth', fn);
2382
items.on('synth', fn);
2383
items.on('click', fn);
2386
items.item(0).click();
2387
items.item(1).click();
2388
items.item(2).click();
2395
items.item(0).click();
2396
items.item(1).click();
2397
items.item(2).click();
2402
"test nodelist.on() + parent.purge(true, synth)": function () {
2404
items = Y.all('.nested li'),
2405
parent = items.item(0).get('parentNode');
2411
items.on('synth', fn);
2413
items.item(0).click();
2414
items.item(1).click();
2415
items.item(2).click();
2419
parent.purge(true, 'synth');
2422
items.item(0).click();
2423
items.item(1).click();
2424
items.item(2).click();
2428
items.on('synth', fn);
2429
items.on('synth', fn);
2430
items.on('click', fn);
2433
items.item(0).click();
2434
items.item(1).click();
2435
items.item(2).click();
2439
parent.purge(true, 'synth');
2442
items.item(0).click();
2443
items.item(1).click();
2444
items.item(2).click();
2449
"test node.on('cat|__', fn) + node.detach('cat|___')": function () {
2451
item = Y.one('#button1');
2453
function increment() {
2457
item.on('cat|synth', increment);
2463
item.detach('cat|synth');
2470
"test node.on('cat|__', fn) + node.detach('cat|___', fn)": function () {
2472
item = Y.one('#button1');
2474
function increment() {
2478
item.on('cat|synth', increment);
2484
item.detach('cat|synth', increment);
2491
"test node.on('cat|__', fn) + node.detach('cat|*')": function () {
2493
item = Y.one('#button1');
2495
function increment() {
2499
item.on('cat|synth', increment);
2505
item.detach('cat|*');
2512
"test Y.on('cat|__', fn, sel) + node.detach('cat|___')": function () {
2514
item = Y.one('#button1');
2516
function increment() {
2520
Y.on('cat|synth', increment, '#button1');
2526
item.detach('cat|synth');
2533
"test Y.on('cat|__', fn, sel) + node.detach('cat|___', fn)": function () {
2535
item = Y.one('#button1');
2537
function increment() {
2541
Y.on('cat|synth', increment, '#button1');
2547
item.detach('cat|synth', increment);
2554
"test Y.on('cat|__', fn) + node.detach('cat|*')": function () {
2556
item = Y.one('#button1');
2558
function increment() {
2562
Y.on('cat|synth', increment, '#button1');
2568
item.detach('cat|*');
2575
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": function () {
2577
items = Y.all('#inner p');
2579
function increment() {
2583
items.on('cat|synth', increment);
2589
items.detach('cat|synth');
2596
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": function () {
2598
items = Y.all('#inner p');
2600
function increment() {
2604
items.on('cat|synth', increment);
2610
items.detach('cat|synth', increment);
2617
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": function () {
2619
items = Y.all('#inner p');
2621
function increment() {
2625
items.on('cat|synth', increment);
2631
items.detach('cat|*');
2638
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": function () {
2640
items = Y.all('#inner p');
2642
function increment() {
2646
Y.on('cat|synth', increment, '#inner p');
2652
items.detach('cat|synth');
2659
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": function () {
2661
items = Y.all('#inner p');
2663
function increment() {
2667
Y.on('cat|synth', increment, '#inner p');
2673
items.detach('cat|synth', increment);
2680
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": function () {
2682
items = Y.all('#inner p');
2684
function increment() {
2688
Y.on('cat|synth', increment, '#inner p');
2694
items.detach('cat|*');
2700
// Y.on('cat|_', fn, multiSelector) + nodelist.detach('cat|_'[, fn]);
2703
suite.add(new Y.Test.Case({
2704
name: "processArgs",
2706
setUp: function () {
2710
processArgs: function (args, delegate) {
2711
return [args.splice(3,1)[0], delegate];
2714
on: function (node, sub, notifier, filter) {
2715
var method = (filter) ? 'delegate' : 'on';
2717
sub._handle = node[method]('click', function (e) {
2723
detach: function (node, sub) {
2724
sub._handle.detach();
2727
config.delegate = config.on;
2728
config.detachDelegate = config.detach;
2730
Y.Event.define('synth', config, true);
2734
"test Y.on('synth', fn, selector, extra)": function () {
2736
target = Y.one("#item3"),
2737
type, currentTarget, thisObj, extra, callbackArgs;
2739
Y.on('synth', function (e) {
2741
currentTarget = e.currentTarget;
2743
extra = e.sub._extra[0];
2744
callbackArgs = arguments.length;
2745
}, '#item3', 'EXTRA');
2749
areSame('synth', type);
2750
areSame(target, currentTarget);
2751
areSame(target, thisObj);
2752
areSame('EXTRA', extra);
2753
areSame(1, callbackArgs);
2756
"Y.on('synth', fn, '#not-here-yet', extra) should resubscribe with original arguments": function () {
2758
target, type, currentTarget, thisObj, extra, callbackArgs;
2760
Y.on('synth', function (e) {
2762
currentTarget = e.currentTarget;
2764
extra = e.sub._extra[0];
2765
callbackArgs = arguments.length;
2766
}, '#item4', 'EXTRA');
2768
setTimeout(function () {
2769
target = Y.Node.create('<li id="item4"><p>Item 4</p></li>');
2770
Y.one(".nested").append(target);
2772
setTimeout(function () {
2773
test.resume(function () {
2775
areSame('synth', type);
2776
areSame(target, currentTarget);
2777
areSame(target, thisObj);
2778
areSame('EXTRA', extra);
2779
areSame(1, callbackArgs);
2789
suite.add(new Y.Test.Case({
2798
Y.Test.Runner.add(suite);
2801
}, '@VERSION@' ,{requires:['event-synthetic', 'test', 'node-event-simulate']});