1
Y.Node.prototype.click = function (options) {
2
Y.Event.simulate(this._node, 'click', options);
4
Y.NodeList.importMethod(Y.Node.prototype, 'click');
8
var suite = new Y.Test.Suite("Y.SyntheticEvent"),
9
areSame = Y.Assert.areSame;
11
function initTestbed() {
12
var testbed = Y.one('#testbed'),
17
testbed = body.create('<div id="testbed"></div>');
18
body.prepend(testbed);
23
'<button id="button1">Button 1 text</button>' +
24
'<ul class="nested">' +
25
'<li id="item1">Item 1</li>' +
26
'<li id="item2" class="nested">Item 2</li>' +
27
'<li id="item3"><p>Item 3</p></li>' +
30
'<p id="p1_no">no</p>' +
31
'<p id="p2_yes">yes</p>' +
32
'<div id="inner_1">' +
33
'<p id="inner_1_p1_no"><em>no</em></p>' +
34
'<p id="inner_1_p2_yes">yes</p>' +
36
'<p id="p3_no">no</p>' +
41
function initSynth() {
42
Y.Event.define('synth', {
43
on: function (node, sub, notifier, filter) {
44
var method = (filter) ? 'delegate' : 'on';
46
sub._handle = node[method]('click',
47
Y.bind(notifier.fire, notifier), filter);
50
delegate: function () {
51
this.on.apply(this, arguments);
54
detach: function (node, sub) {
58
detachDelegate: function () {
59
this.detach.apply(this, arguments);
69
function destroyTestbed() {
70
var testbed = Y.one('#testbed');
72
testbed.purge(true).remove();
76
function undefineSynth() {
77
delete Y.Node.DOM_EVENTS.synth;
78
delete Y.Env.evt.plugins.synth;
86
/******************************************************************************/
87
/****************************** Tests begin here ****************************/
88
/******************************************************************************/
90
suite.add(new Y.Test.Case({
91
name: "Y.Event.define",
93
"Y.Event.define(name) should add to DOM_EVENTS": function () {
94
delete Y.Node.DOM_EVENTS.mouseover;
96
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
98
Y.Event.define('mouseover');
100
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
103
"Y.Event.define([name1, name2]) should add to DOM_EVENTS": function () {
104
delete Y.Node.DOM_EVENTS.mouseover;
105
delete Y.Node.DOM_EVENTS.mouseout;
107
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseover);
108
Y.Assert.isUndefined(Y.Node.DOM_EVENTS.mouseout);
110
Y.Event.define(['mouseover', 'mouseout']);
112
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseover);
113
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.mouseout);
116
"Y.Event.define(type, {...}) should register a new synth in DOM_EVENTS": function () {
117
Y.Event.define('synth', {
121
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
122
Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
123
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
124
areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
127
"Subsequent Y.Event.define() should not overwrite existing synth": function () {
128
Y.Event.define('synth', {
132
areSame(0, Y.Node.DOM_EVENTS.synth.eventDef.index);
135
"Y.Event.define(..., true) should overwrite existing synth": function () {
136
Y.Event.define('synth', {
140
areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
143
"Y.Event.define({ type: ...}) should register a new synth in DOM_EVENTS": function () {
144
delete Y.Node.DOM_EVENTS.synth;
151
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth);
152
Y.Assert.isNotUndefined(Y.Env.evt.plugins.synth);
153
Y.Assert.isNotUndefined(Y.Node.DOM_EVENTS.synth.eventDef);
154
areSame(Y.Node.DOM_EVENTS.synth, Y.Env.evt.plugins.synth);
155
areSame(3, Y.Node.DOM_EVENTS.synth.eventDef.index);
158
"Y.Event.define({...}, true) should overwrite existing synth": function () {
164
areSame(2, Y.Node.DOM_EVENTS.synth.eventDef.index);
169
suite.add(new Y.Test.Case({
175
"test Y.on('synth', fn, node)": function () {
176
var target = Y.one("#item3"),
177
type, currentTarget, thisObj;
179
Y.on('synth', function (e) {
181
currentTarget = e.currentTarget;
187
areSame('synth', type);
188
areSame(target, currentTarget);
189
areSame(target, thisObj);
192
"test Y.on('synth', fn, node, thisObj)": function () {
193
var target = Y.one("#item3"),
194
obj = { foo: 'bar' },
195
type, currentTarget, thisObj, foo;
197
Y.on('synth', function (e) {
199
currentTarget = e.currentTarget;
206
areSame('synth', type);
207
areSame(target, currentTarget);
208
areSame(obj, thisObj);
209
areSame(obj.foo, thisObj.foo);
212
"test Y.on('synth', fn, node, thisObj, arg)": function () {
213
var target = Y.one("#item3"),
214
obj = { foo: 'bar' },
215
type, currentTarget, thisObj, foo, arg;
217
Y.on('synth', function (e, x) {
219
currentTarget = e.currentTarget;
223
}, target, obj, 'arg!');
227
areSame('synth', type);
228
areSame(target, currentTarget);
229
areSame(obj, thisObj);
230
areSame(obj.foo, thisObj.foo);
231
areSame('arg!', arg);
234
"test Y.on('synth', fn, node, null, arg)": function () {
235
var target = Y.one("#item3"),
236
type, currentTarget, thisObj, arg;
238
Y.on('synth', function (e, x) {
240
currentTarget = e.currentTarget;
243
}, target, null, 'arg!');
247
areSame('synth', type);
248
areSame(target, currentTarget);
249
areSame(target, thisObj);
250
areSame('arg!', arg);
253
"test Y.on('synth', fn, el)": function () {
254
var targetEl = Y.DOM.byId('item3'),
255
target = Y.one(targetEl),
256
type, currentTarget, thisObj;
258
Y.on('synth', function (e) {
260
currentTarget = e.currentTarget;
266
areSame('synth', type);
267
areSame(target, currentTarget);
268
areSame(target, thisObj);
271
"test Y.on('synth', fn, el, thisObj)": function () {
272
var targetEl = Y.DOM.byId("item3"),
273
target = Y.one(targetEl),
274
obj = { foo: 'bar' },
275
type, currentTarget, thisObj, foo;
277
Y.on('synth', function (e) {
279
currentTarget = e.currentTarget;
286
areSame('synth', type);
287
areSame(target, currentTarget);
288
areSame(obj, thisObj);
289
areSame(obj.foo, thisObj.foo);
292
"test Y.on('synth', fn, el, thisObj, arg)": function () {
293
var targetEl = Y.DOM.byId("item3"),
294
target = Y.one(targetEl),
295
obj = { foo: 'bar' },
296
type, currentTarget, thisObj, foo, arg;
298
Y.on('synth', function (e, x) {
300
currentTarget = e.currentTarget;
304
}, targetEl, obj, 'arg!');
308
areSame('synth', type);
309
areSame(target, currentTarget);
310
areSame(obj, thisObj);
311
areSame(obj.foo, thisObj.foo);
312
areSame('arg!', arg);
315
"test Y.on('synth', fn, el, null, arg)": function () {
316
var targetEl = Y.DOM.byId("item3"),
317
target = Y.one(targetEl),
318
type, currentTarget, thisObj, arg;
320
Y.on('synth', function (e, x) {
322
currentTarget = e.currentTarget;
325
}, targetEl, null, 'arg!');
329
areSame('synth', type);
330
areSame(target, currentTarget);
331
areSame(target, thisObj);
332
areSame('arg!', arg);
335
"test Y.on('synth', fn, selectorOne)": function () {
336
var target = Y.one('#item3'),
337
type, currentTarget, thisObj;
339
Y.on('synth', function (e) {
341
currentTarget = e.currentTarget;
347
areSame('synth', type);
348
areSame(target, currentTarget);
349
areSame(target, thisObj);
352
"test Y.on('synth', fn, selectorOne, thisObj)": function () {
353
var target = Y.one('#item3'),
354
obj = { foo: 'bar' },
355
type, currentTarget, thisObj, foo;
357
Y.on('synth', function (e) {
359
currentTarget = e.currentTarget;
366
areSame('synth', type);
367
areSame(target, currentTarget);
368
areSame(obj, thisObj);
369
areSame(obj.foo, thisObj.foo);
372
"test Y.on('synth', fn, selectorOne, thisObj, arg)": function () {
373
var target = Y.one('#item3'),
374
obj = { foo: 'bar' },
375
type, currentTarget, thisObj, foo, arg;
377
Y.on('synth', function (e, x) {
379
currentTarget = e.currentTarget;
383
}, '#item3', obj, 'arg!');
387
areSame('synth', type);
388
areSame(target, currentTarget);
389
areSame(obj, thisObj);
390
areSame(obj.foo, thisObj.foo);
391
areSame('arg!', arg);
394
"test Y.on('synth', fn, selectorOne, null, arg)": function () {
395
var target = Y.one('#item3'),
396
type, currentTarget, thisObj, arg;
398
Y.on('synth', function (e, x) {
400
currentTarget = e.currentTarget;
403
}, '#item3', null, 'arg!');
407
areSame('synth', type);
408
areSame(target, currentTarget);
409
areSame(target, thisObj);
410
areSame('arg!', arg);
413
"test Y.on('synth', fn, selectorMultiple)": function () {
414
var item1 = Y.one('#item1'),
415
item2 = Y.one('#item2'),
416
item3 = Y.one('#item3'),
421
Y.on('synth', function (e) {
423
currentTarget.push(e.currentTarget);
431
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
432
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
433
Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
436
"test Y.on('synth', fn, selectorMultiple, thisObj)": function () {
437
var item1 = Y.one('#item1'),
438
item2 = Y.one('#item2'),
439
item3 = Y.one('#item3'),
440
obj = { foo: 'bar' },
446
Y.on('synth', function (e) {
448
currentTarget.push(e.currentTarget);
451
}, '#outer li', obj);
457
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
458
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
459
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
460
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
463
"test Y.on('synth', fn, selectorMultiple, thisObj, arg)": function () {
464
var item1 = Y.one('#item1'),
465
item2 = Y.one('#item2'),
466
item3 = Y.one('#item3'),
467
obj = { foo: 'bar' },
474
Y.on('synth', function (e, x) {
476
currentTarget.push(e.currentTarget);
480
}, '#outer li', obj, 'arg!');
486
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
487
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
488
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
489
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
490
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
493
"test Y.on('synth', fn, selectorMultiple, null, arg)": function () {
494
var item1 = Y.one('#item1'),
495
item2 = Y.one('#item2'),
496
item3 = Y.one('#item3'),
502
Y.on('synth', function (e, x) {
504
currentTarget.push(e.currentTarget);
507
}, '#outer li', null, 'arg!');
513
Y.ArrayAssert.itemsAreSame(['synth','synth','synth'], type);
514
Y.ArrayAssert.itemsAreSame([item1, item2, item3], currentTarget);
515
Y.ArrayAssert.itemsAreSame([item1, item2, item3], thisObj);
516
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
519
"test Y.on('synth', fn, notYetAvailable)": function () {
520
var inner = Y.one('#inner'),
526
inner.all('#p4').remove();
528
Y.on('synth', function (e) {
530
currentTarget = e.currentTarget;
534
inner.append("<p id='p4'>Added</p>");
536
// This is a tainted test because it's using a different synthetic
537
// event to test that the synthetic event infrastructure is working
538
// properly. The other option is to use Y.later, but that opens a race
539
// condition. The test is left in place because something is better
541
Y.on("available", function () {
542
test.resume(function () {
543
var p4 = inner.one('#p4');
546
areSame('synth', type);
547
areSame(p4, currentTarget);
548
areSame(p4, thisObj);
550
Y.Assert.fail("Something is wrong with onAvailable");
558
"test Y.on('synth', fn, notYetAvailable, thisObj)": function () {
559
var inner = Y.one('#inner'),
561
obj = { foo: 'bar' },
562
type, currentTarget, thisObj, foo;
564
inner.all('#p4').remove();
566
Y.on('synth', function (e) {
568
currentTarget = e.currentTarget;
573
inner.append("<p id='p4'>Added</p>");
575
// This is a tainted test because it's using a different synthetic
576
// event to test that the synthetic event infrastructure is working
577
// properly. The other option is to use Y.later, but that opens a race
578
// condition. The test is left in place because something is better
580
Y.on("available", function () {
581
test.resume(function () {
582
var p4 = inner.one('#p4');
585
areSame('synth', type);
586
areSame(p4, currentTarget);
587
areSame(obj, thisObj);
590
Y.Assert.fail("Something is wrong with onAvailable");
598
"test Y.on('synth', fn, notYetAvailable, thisObj, arg)": function () {
599
var inner = Y.one('#inner'),
601
obj = { foo: 'bar' },
602
type, currentTarget, thisObj, foo, arg;
604
inner.all('#p4').remove();
606
Y.on('synth', function (e, x) {
608
currentTarget = e.currentTarget;
612
}, '#p4', obj, 'arg!');
614
inner.append("<p id='p4'>Added</p>");
616
// This is a tainted test because it's using a different synthetic
617
// event to test that the synthetic event infrastructure is working
618
// properly. The other option is to use Y.later, but that opens a race
619
// condition. The test is left in place because something is better
621
Y.on("available", function () {
622
test.resume(function () {
623
var p4 = inner.one('#p4');
626
areSame('synth', type);
627
areSame(p4, currentTarget);
628
areSame(obj, thisObj);
630
areSame('arg!', arg);
632
Y.Assert.fail("Something is wrong with onAvailable");
640
"test Y.on('synth', fn, notYetAvailable, null, arg)": function () {
641
var inner = Y.one('#inner'),
643
type, currentTarget, thisObj, arg;
645
inner.all('#p4').remove();
647
Y.on('synth', function (e, x) {
649
currentTarget = e.currentTarget;
652
}, '#p4', null, 'arg!');
654
inner.append("<p id='p4'>Added</p>");
656
// This is a tainted test because it's using a different synthetic
657
// event to test that the synthetic event infrastructure is working
658
// properly. The other option is to use Y.later, but that opens a race
659
// condition. The test is left in place because something is better
661
Y.on("available", function () {
662
test.resume(function () {
663
var p4 = inner.one('#p4');
666
areSame('synth', type);
667
areSame(p4, currentTarget);
668
areSame(p4, thisObj);
669
areSame('arg!', arg);
671
Y.Assert.fail("Something is wrong with onAvailable");
679
"test Y.on('synth', fn) defaults to window": function (){
680
var handle = Y.on('synth', function (e) {});
682
areSame(Y.one(Y.config.win), handle.sub.node);
689
suite.add(new Y.Test.Case({
695
"test node.on(x, fn)": function () {
696
var target = Y.one("#item3"),
697
type, currentTarget, thisObj;
699
target.on('synth', function (e) {
701
currentTarget = e.currentTarget;
707
areSame('synth', type);
708
areSame(target, currentTarget);
709
areSame(target, thisObj);
712
"test node.on(x, fn, thisObj)": function () {
713
var target = Y.one("#item3"),
714
obj = { foo: 'bar' },
715
type, currentTarget, thisObj, foo;
717
target.on('synth', function (e) {
719
currentTarget = e.currentTarget;
726
areSame('synth', type);
727
areSame(target, currentTarget);
728
areSame(obj, thisObj);
729
areSame(obj.foo, thisObj.foo);
732
"test node.on(x, fn, thisObj, arg)": function () {
733
var target = Y.one("#item3"),
734
obj = { foo: 'bar' },
735
type, currentTarget, thisObj, foo, arg;
737
target.on('synth', function (e, x) {
739
currentTarget = e.currentTarget;
747
areSame('synth', type);
748
areSame(target, currentTarget);
749
areSame(obj, thisObj);
750
areSame(obj.foo, thisObj.foo);
751
areSame('arg!', arg);
754
"test node.on(x, fn, null, arg)": function () {
755
var target = Y.one("#item3"),
756
type, currentTarget, thisObj, arg;
758
target.on('synth', function (e, x) {
760
currentTarget = e.currentTarget;
767
areSame('synth', type);
768
areSame(target, currentTarget);
769
areSame(target, thisObj);
770
areSame('arg!', arg);
774
suite.add(new Y.Test.Case({
780
"test nodelist.on(x, fn)": function () {
781
var targets = Y.all("#inner p"),
786
targets.on('synth', function (e) {
788
currentTarget.push(e.currentTarget);
792
Y.one("#p1_no").click();
793
Y.one("#p3_no").click();
794
Y.one("#inner_1_p1_no").click();
796
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
797
Y.ArrayAssert.itemsAreSame(
798
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
800
Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
803
"test nodelist.on(x, fn, thisObj)": function () {
804
var targets = Y.all("#inner p"),
805
obj = { foo: 'bar' },
811
targets.on('synth', function (e) {
813
currentTarget.push(e.currentTarget);
818
Y.one("#p1_no").click();
819
Y.one("#p3_no").click();
820
Y.one("#inner_1_p1_no").click();
822
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
823
Y.ArrayAssert.itemsAreSame(
824
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
826
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
827
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
830
"test nodelist.on(x, fn, thisObj, arg)": function () {
831
var targets = Y.all("#inner p"),
832
obj = { foo: 'bar' },
839
targets.on('synth', function (e, x) {
841
currentTarget.push(e.currentTarget);
847
Y.one("#p1_no").click();
848
Y.one("#p3_no").click();
849
Y.one("#inner_1_p1_no").click();
851
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
852
Y.ArrayAssert.itemsAreSame(
853
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
855
Y.ArrayAssert.itemsAreSame([obj, obj, obj], thisObj);
856
Y.ArrayAssert.itemsAreSame(['bar', 'bar', 'bar'], foo);
857
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
860
"test nodelist.on(x, fn, null, arg)": function () {
861
var targets = Y.all("#inner p"),
867
targets.on('synth', function (e, x) {
869
currentTarget.push(e.currentTarget);
874
Y.one("#p1_no").click();
875
Y.one("#p3_no").click();
876
Y.one("#inner_1_p1_no").click();
878
Y.ArrayAssert.itemsAreSame(['synth', 'synth', 'synth'], type);
879
Y.ArrayAssert.itemsAreSame(
880
[Y.one('#p1_no'), Y.one('#p3_no'), Y.one('#inner_1_p1_no')],
882
Y.ArrayAssert.itemsAreSame([targets, targets, targets], thisObj);
883
Y.ArrayAssert.itemsAreSame(['arg!', 'arg!', 'arg!'], arg);
887
suite.add(new Y.Test.Case({
893
initUniqueSynth: function () {
894
Y.Event.define('synth', {
897
on: function (node, sub, notifier, filter) {
898
var method = (filter) ? 'delegate' : 'on';
900
sub._handle = node[method]('click',
901
Y.bind(notifier.fire, notifier), filter);
904
detach: function (node, sub) {
905
sub._handle.detach();
910
"node.on(x, fn) + node.on(x, fn) should allow dups": function () {
913
var target = Y.one("#item1"),
916
function increment() {
920
target.on('synth', increment);
921
target.on('synth', increment);
923
Y.one("#item1").click();
928
"Y.on(x, fn) + node.on(x, fn) should allow dups": function () {
933
function increment() {
937
Y.one('#item1').on('synth', increment);
938
Y.on('synth', increment, '#item1');
940
Y.one("#item1").click();
945
"nodelist.on(x, fn) + node.on(x, fn) should allow dups": function () {
950
function increment() {
954
Y.all("#item1").on('synth', increment);
955
Y.one("#item1").on('synth', increment);
957
Y.one("#item1").click();
962
"preventDups:true node.on(x, fn) + node.on(x, fn) should prevent dups": function () {
963
this.initUniqueSynth();
965
var target = Y.one("#item1"),
968
function increment() {
972
target.on('synth', increment);
973
target.on('synth', increment);
975
Y.one("#item1").click();
980
"preventDups:true Y.on(x, fn) + node.on(x, fn) should prevent dups": function () {
981
this.initUniqueSynth();
985
function increment() {
989
Y.one('#item1').on('synth', increment);
990
Y.on('synth', increment, '#item1');
992
Y.one("#item1").click();
997
"preventDups:true nodelist.on(x, fn) + node.on(x, fn) should prevent dups": function () {
998
this.initUniqueSynth();
1002
function increment() {
1006
Y.all("#item1").on('synth', increment);
1007
Y.one("#item1").on('synth', increment);
1009
Y.one("#item1").click();
1015
suite.add(new Y.Test.Case({
1016
name: "node.delegate",
1021
"test node.delegate(synth, fn, filter)": function () {
1028
inner = Y.one("#inner"),
1029
a = Y.one("#p1_no"),
1030
b = Y.one("#inner_1_p1_no em");
1032
inner.delegate('synth', function (e) {
1035
target.push(e.target);
1036
currentTarget.push(e.currentTarget);
1038
container.push(e.container);
1044
Y.ArrayAssert.itemsAreSame(['synth'], type);
1045
Y.ArrayAssert.itemsAreSame([a], target);
1046
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1047
Y.ArrayAssert.itemsAreSame([a], thisObj);
1048
Y.ArrayAssert.itemsAreSame([inner], container);
1053
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1054
Y.ArrayAssert.itemsAreSame([a, b], target);
1055
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1056
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1057
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1060
"test node.delegate(synth, fn, filter, thisObj)": function () {
1062
obj = { foo: "bar" },
1069
inner = Y.one("#inner"),
1070
a = Y.one("#p1_no"),
1071
b = Y.one("#inner_1_p1_no em");
1073
inner.delegate('synth', function (e) {
1076
target.push(e.target);
1077
currentTarget.push(e.currentTarget);
1080
container.push(e.container);
1086
Y.ArrayAssert.itemsAreSame(['synth'], type);
1087
Y.ArrayAssert.itemsAreSame([a], target);
1088
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1089
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1090
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1091
Y.ArrayAssert.itemsAreSame([inner], container);
1096
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1097
Y.ArrayAssert.itemsAreSame([a, b], target);
1098
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1099
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1100
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1101
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1104
"test node.delegate(synth, fn, filter, thisObj, arg)": function () {
1106
obj = { foo: "bar" },
1114
inner = Y.one("#inner"),
1115
a = Y.one("#p1_no"),
1116
b = Y.one("#inner_1_p1_no em");
1118
inner.delegate('synth', function (e, x) {
1121
target.push(e.target);
1122
currentTarget.push(e.currentTarget);
1126
container.push(e.container);
1127
}, 'p', obj, 'arg!');
1132
Y.ArrayAssert.itemsAreSame(['synth'], type);
1133
Y.ArrayAssert.itemsAreSame([a], target);
1134
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1135
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1136
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1137
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1138
Y.ArrayAssert.itemsAreSame([inner], container);
1143
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1144
Y.ArrayAssert.itemsAreSame([a, b], target);
1145
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1146
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1147
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1148
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1149
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1152
"test node.delegate(synth, fn, filter, null, arg)": function () {
1160
inner = Y.one("#inner"),
1161
a = Y.one("#p1_no"),
1162
b = Y.one("#inner_1_p1_no em");
1164
inner.delegate('synth', function (e, x) {
1167
target.push(e.target);
1168
currentTarget.push(e.currentTarget);
1171
container.push(e.container);
1172
}, 'p', null, "arg!");
1177
Y.ArrayAssert.itemsAreSame(['synth'], type);
1178
Y.ArrayAssert.itemsAreSame([a], target);
1179
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1180
Y.ArrayAssert.itemsAreSame([a], thisObj);
1181
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1182
Y.ArrayAssert.itemsAreSame([inner], container);
1187
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1188
Y.ArrayAssert.itemsAreSame([a, b], target);
1189
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1190
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1191
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1192
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1197
suite.add(new Y.Test.Case({
1203
"test Y.delegate(synth, fn, node, filter)": function () {
1210
inner = Y.one("#inner"),
1211
a = Y.one("#p1_no"),
1212
b = Y.one("#inner_1_p1_no em");
1214
Y.delegate('synth', function (e) {
1217
target.push(e.target);
1218
currentTarget.push(e.currentTarget);
1220
container.push(e.container);
1226
Y.ArrayAssert.itemsAreSame(['synth'], type);
1227
Y.ArrayAssert.itemsAreSame([a], target);
1228
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1229
Y.ArrayAssert.itemsAreSame([a], thisObj);
1230
Y.ArrayAssert.itemsAreSame([inner], container);
1235
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1236
Y.ArrayAssert.itemsAreSame([a, b], target);
1237
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1238
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1239
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1242
"test Y.delegate(synth, fn, el, filter)": function () {
1249
inner = Y.one("#inner"),
1250
a = Y.one("#p1_no"),
1251
b = Y.one("#inner_1_p1_no em");
1253
Y.delegate('synth', function (e) {
1256
target.push(e.target);
1257
currentTarget.push(e.currentTarget);
1259
container.push(e.container);
1260
}, inner._node, 'p');
1265
Y.ArrayAssert.itemsAreSame(['synth'], type);
1266
Y.ArrayAssert.itemsAreSame([a], target);
1267
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1268
Y.ArrayAssert.itemsAreSame([a], thisObj);
1269
Y.ArrayAssert.itemsAreSame([inner], container);
1274
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1275
Y.ArrayAssert.itemsAreSame([a, b], target);
1276
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1277
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1278
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1281
"test Y.delegate(synth, fn, selectorOne, filter)": function () {
1288
inner = Y.one("#inner"),
1289
a = Y.one("#p1_no"),
1290
b = Y.one("#inner_1_p1_no em");
1292
Y.delegate('synth', function (e) {
1295
target.push(e.target);
1296
currentTarget.push(e.currentTarget);
1298
container.push(e.container);
1304
Y.ArrayAssert.itemsAreSame(['synth'], type);
1305
Y.ArrayAssert.itemsAreSame([a], target);
1306
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1307
Y.ArrayAssert.itemsAreSame([a], thisObj);
1308
Y.ArrayAssert.itemsAreSame([inner], container);
1313
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1314
Y.ArrayAssert.itemsAreSame([a, b], target);
1315
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1316
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1317
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1320
"test Y.delegate(synth, fn, node, filter, thisObj)": function () {
1322
obj = { foo: "bar" },
1329
inner = Y.one("#inner"),
1330
a = Y.one("#p1_no"),
1331
b = Y.one("#inner_1_p1_no em");
1333
Y.delegate('synth', function (e) {
1336
target.push(e.target);
1337
currentTarget.push(e.currentTarget);
1340
container.push(e.container);
1341
}, inner, 'p', obj);
1346
Y.ArrayAssert.itemsAreSame(['synth'], type);
1347
Y.ArrayAssert.itemsAreSame([a], target);
1348
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1349
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1350
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1351
Y.ArrayAssert.itemsAreSame([inner], container);
1356
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1357
Y.ArrayAssert.itemsAreSame([a, b], target);
1358
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1359
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1360
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1361
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1364
"test Y.delegate(synth, fn, node, filter, thisObj, arg)": function () {
1366
obj = { foo: "bar" },
1374
inner = Y.one("#inner"),
1375
a = Y.one("#p1_no"),
1376
b = Y.one("#inner_1_p1_no em");
1378
Y.delegate('synth', function (e, x) {
1381
target.push(e.target);
1382
currentTarget.push(e.currentTarget);
1386
container.push(e.container);
1387
}, inner, 'p', obj, 'arg!');
1392
Y.ArrayAssert.itemsAreSame(['synth'], type);
1393
Y.ArrayAssert.itemsAreSame([a], target);
1394
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1395
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1396
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1397
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1398
Y.ArrayAssert.itemsAreSame([inner], container);
1403
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1404
Y.ArrayAssert.itemsAreSame([a, b], target);
1405
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1406
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1407
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1408
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1409
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1412
"test Y.delegate(synth, fn, node, filter, null, arg)": function () {
1420
inner = Y.one("#inner"),
1421
a = Y.one("#p1_no"),
1422
b = Y.one("#inner_1_p1_no em");
1424
Y.delegate('synth', function (e, x) {
1427
target.push(e.target);
1428
currentTarget.push(e.currentTarget);
1431
container.push(e.container);
1432
}, inner, 'p', null, "arg!");
1437
Y.ArrayAssert.itemsAreSame(['synth'], type);
1438
Y.ArrayAssert.itemsAreSame([a], target);
1439
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1440
Y.ArrayAssert.itemsAreSame([a], thisObj);
1441
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1442
Y.ArrayAssert.itemsAreSame([inner], container);
1447
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1448
Y.ArrayAssert.itemsAreSame([a, b], target);
1449
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1450
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1451
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1452
Y.ArrayAssert.itemsAreSame([inner, inner], container);
1455
"test Y.delegate(synth, fn, notAvailableYet, filter)": function () {
1456
var inner = Y.one('#inner'),
1467
Y.delegate('synth', function (e) {
1470
target.push(e.target);
1471
currentTarget.push(e.currentTarget);
1473
container.push(e.container);
1474
}, '#inner_1', 'p');
1476
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1478
// This is a tainted test because it's using a different synthetic
1479
// event to test that the synthetic event infrastructure is working
1480
// properly. The other option is to use Y.later, but that opens a race
1481
// condition. The test is left in place because something is better
1483
Y.on("available", function () {
1484
test.resume(function () {
1485
var a = inner.one('#pass1'),
1486
b = inner.one('#pass2-trigger'),
1487
inner1 = inner.one('#inner_1');
1489
if (a && b && inner1) {
1493
Y.ArrayAssert.itemsAreSame(['synth'], type);
1494
Y.ArrayAssert.itemsAreSame([a], target);
1495
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1496
Y.ArrayAssert.itemsAreSame([a], thisObj);
1497
Y.ArrayAssert.itemsAreSame([inner1], container);
1502
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1503
Y.ArrayAssert.itemsAreSame([a, b], target);
1504
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1505
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1506
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1508
Y.Assert.fail("Something is wrong with onAvailable");
1511
}, '#pass2-trigger');
1516
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj)": function () {
1517
var inner = Y.one('#inner'),
1518
obj = { foo: 'bar' },
1530
Y.delegate('synth', function (e) {
1533
target.push(e.target);
1534
currentTarget.push(e.currentTarget);
1537
container.push(e.container);
1538
}, '#inner_1', 'p', obj);
1540
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1542
// This is a tainted test because it's using a different synthetic
1543
// event to test that the synthetic event infrastructure is working
1544
// properly. The other option is to use Y.later, but that opens a race
1545
// condition. The test is left in place because something is better
1547
Y.on("available", function () {
1548
test.resume(function () {
1549
var a = inner.one('#pass1'),
1550
b = inner.one('#pass2-trigger'),
1551
inner1 = inner.one('#inner_1');
1553
if (a && b && inner1) {
1557
Y.ArrayAssert.itemsAreSame(['synth'], type);
1558
Y.ArrayAssert.itemsAreSame([a], target);
1559
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1560
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1561
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1562
Y.ArrayAssert.itemsAreSame([inner1], container);
1567
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1568
Y.ArrayAssert.itemsAreSame([a, b], target);
1569
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1570
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1571
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1572
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1574
Y.Assert.fail("Something is wrong with onAvailable");
1577
}, '#pass2-trigger');
1582
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj, arg)": function () {
1583
var inner = Y.one('#inner'),
1584
obj = { foo: 'bar' },
1597
Y.delegate('synth', function (e, x) {
1600
target.push(e.target);
1601
currentTarget.push(e.currentTarget);
1605
container.push(e.container);
1606
}, '#inner_1', 'p', obj, "arg!");
1608
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1610
// This is a tainted test because it's using a different synthetic
1611
// event to test that the synthetic event infrastructure is working
1612
// properly. The other option is to use Y.later, but that opens a race
1613
// condition. The test is left in place because something is better
1615
Y.on("available", function () {
1616
test.resume(function () {
1617
var a = inner.one('#pass1'),
1618
b = inner.one('#pass2-trigger'),
1619
inner1 = inner.one('#inner_1');
1621
if (a && b && inner1) {
1625
Y.ArrayAssert.itemsAreSame(['synth'], type);
1626
Y.ArrayAssert.itemsAreSame([a], target);
1627
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1628
Y.ArrayAssert.itemsAreSame([obj], thisObj);
1629
Y.ArrayAssert.itemsAreSame(["bar"], foo);
1630
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1631
Y.ArrayAssert.itemsAreSame([inner1], container);
1636
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1637
Y.ArrayAssert.itemsAreSame([a, b], target);
1638
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1639
Y.ArrayAssert.itemsAreSame([obj, obj], thisObj);
1640
Y.ArrayAssert.itemsAreSame(["bar", "bar"], foo);
1641
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1642
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1644
Y.Assert.fail("Something is wrong with onAvailable");
1647
}, '#pass2-trigger');
1652
"test Y.delegate(synth, fn, notAvailableYet, filter, null, arg)": function () {
1653
var inner = Y.one('#inner'),
1665
Y.delegate('synth', function (e, x) {
1668
target.push(e.target);
1669
currentTarget.push(e.currentTarget);
1672
container.push(e.container);
1673
}, '#inner_1', 'p', null, "arg!");
1675
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
1677
// This is a tainted test because it's using a different synthetic
1678
// event to test that the synthetic event infrastructure is working
1679
// properly. The other option is to use Y.later, but that opens a race
1680
// condition. The test is left in place because something is better
1682
Y.on("available", function () {
1683
test.resume(function () {
1684
var a = inner.one('#pass1'),
1685
b = inner.one('#pass2-trigger'),
1686
inner1 = inner.one('#inner_1');
1688
if (a && b && inner1) {
1692
Y.ArrayAssert.itemsAreSame(['synth'], type);
1693
Y.ArrayAssert.itemsAreSame([a], target);
1694
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1695
Y.ArrayAssert.itemsAreSame([a], thisObj);
1696
Y.ArrayAssert.itemsAreSame(["arg!"], arg);
1697
Y.ArrayAssert.itemsAreSame([inner1], container);
1702
Y.ArrayAssert.itemsAreSame(['synth','synth'], type);
1703
Y.ArrayAssert.itemsAreSame([a, b], target);
1704
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1705
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1706
Y.ArrayAssert.itemsAreSame(["arg!", "arg!"], arg);
1707
Y.ArrayAssert.itemsAreSame([inner1, inner1], container);
1709
Y.Assert.fail("Something is wrong with onAvailable");
1712
}, '#pass2-trigger');
1717
"test Y.delegate(synth, fn, selectorMulti, filter)": function () {
1724
nested = Y.one('.nested'),
1725
inner = Y.one('#inner'),
1726
a = Y.one('#item3 p'),
1727
b = Y.one("#inner_1_p1_no em");
1729
Y.delegate('synth', function (e) {
1732
target.push(e.target);
1733
currentTarget.push(e.currentTarget);
1735
container.push(e.container);
1736
}, ".nested, #inner", 'p');
1741
Y.ArrayAssert.itemsAreSame(['synth'], type);
1742
Y.ArrayAssert.itemsAreSame([a], target);
1743
Y.ArrayAssert.itemsAreSame([a], currentTarget);
1744
Y.ArrayAssert.itemsAreSame([a], thisObj);
1745
Y.ArrayAssert.itemsAreSame([nested], container);
1750
Y.ArrayAssert.itemsAreSame(['synth', 'synth'], type);
1751
Y.ArrayAssert.itemsAreSame([a, b], target);
1752
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], currentTarget);
1753
Y.ArrayAssert.itemsAreSame([a, b.ancestor('p')], thisObj);
1754
Y.ArrayAssert.itemsAreSame([nested, inner], container);
1759
suite.add(new Y.Test.Case({
1767
// TODO: Can this be made to work?
1768
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": true,
1769
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": true,
1770
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": true,
1771
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": true,
1772
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": true,
1773
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": true
1777
"test node.on() + node.detach(synth, fn)": function () {
1779
target = Y.one('#button1');
1785
target.on('synth', fn);
1791
target.detach('synth', fn);
1797
target.on('synth', fn);
1798
target.on('synth', fn);
1799
target.on('click', fn);
1805
target.detach('synth', fn);
1812
"test node.on(synth, fn, thisObj) + node.detach(synth, fn)": function () {
1816
target = Y.one('#button1');
1822
target.on('synth', fn, a);
1828
target.detach('synth', fn);
1834
target.on('synth', fn, a);
1835
target.on('synth', fn, b);
1841
target.detach('synth', fn);
1848
"test node.on() + node.detach(synth)": function () {
1850
target = Y.one('#button1');
1856
target.on('synth', fn);
1862
target.detach('synth');
1868
target.on('synth', fn);
1869
target.on('synth', fn);
1870
target.on('click', fn);
1876
target.detach('synth');
1883
"test node.on() + node.detach()": function () {
1885
target = Y.one('#button1');
1891
target.on('synth', fn);
1903
target.on('synth', fn);
1904
target.on('synth', fn);
1905
target.on('click', fn);
1918
"test node.on() + node.detachAll()": function () {
1920
target = Y.one('#button1');
1926
target.on('synth', fn);
1938
target.on('synth', fn);
1939
target.on('synth', fn);
1940
target.on('click', fn);
1953
"test node.on() + node.purge(true, synth)": function () {
1955
target = Y.one('#button1');
1961
target.on('synth', fn);
1967
target.purge(true, 'synth');
1973
target.on('synth', fn);
1974
target.on('synth', fn);
1975
target.on('click', fn);
1981
target.purge(true, 'synth');
1988
"test node.on() + parent.purge(true, synth)": function () {
1990
target = Y.one('#button1'),
1991
parent = target.get('parentNode');
1997
target.on('synth', fn);
2003
parent.purge(true, 'synth');
2009
target.on('synth', fn);
2010
target.on('synth', fn);
2011
target.on('click', fn);
2017
parent.purge(true, 'synth');
2024
"test nodelist.on(synth, fn) + node.detach(synth, fn)": function () {
2026
all = Y.all('.nested li'),
2029
function increment() {
2033
all.on('synth', increment);
2039
item.detach('synth', increment);
2046
"test nodelist.on(synth, fn) + node.detach(synth)": function () {
2048
all = Y.all('.nested li'),
2051
function increment() {
2055
all.on('synth', increment);
2061
item.detach('synth');
2068
"test node.on(synth, fn) + nodelist.detach(synth, fn)": function () {
2070
all = Y.all('.nested li'),
2073
function increment() {
2077
item.on('synth', increment);
2083
all.detach('synth', increment);
2090
"test node.on(synth, fn) + nodelist.detach(synth)": function () {
2092
all = Y.all('.nested li'),
2095
function increment() {
2099
item.on('synth', increment);
2105
all.detach('synth');
2112
"test node.on() + handle.detach()": function () {
2114
item = Y.one('#button1'),
2117
function increment() {
2121
sub = item.on('synth', increment);
2134
"test nodelist.on() + handle.detach()": function () {
2136
items = Y.all('.nested li'),
2137
one = items.item(0),
2138
two = items.item(1),
2139
three = items.item(2),
2142
function increment() {
2146
sub = items.on('synth', increment);
2169
"test nodelist.on() + nodelist.detach(synth, fn)": function () {
2171
items = Y.all('.nested li');
2177
items.on('synth', fn);
2179
items.item(0).click();
2180
items.item(1).click();
2181
items.item(2).click();
2185
items.detach('synth', fn);
2188
items.item(0).click();
2189
items.item(1).click();
2190
items.item(2).click();
2194
items.on('synth', fn);
2195
items.on('synth', fn);
2196
items.on('click', fn);
2199
items.item(0).click();
2200
items.item(1).click();
2201
items.item(2).click();
2205
items.detach('synth', fn);
2208
items.item(0).click();
2209
items.item(1).click();
2210
items.item(2).click();
2215
"test nodelist.on(synth, fn, thisObj) + nodelist.detach(synth, fn)": function () {
2219
items = Y.all('.nested li');
2225
items.on('synth', fn, a);
2227
items.item(0).click();
2228
items.item(1).click();
2229
items.item(2).click();
2233
items.detach('synth', fn);
2236
items.item(0).click();
2237
items.item(1).click();
2238
items.item(2).click();
2242
items.on('synth', fn, a);
2243
items.on('synth', fn, b);
2246
items.item(0).click();
2247
items.item(1).click();
2248
items.item(2).click();
2252
items.detach('synth', fn);
2255
items.item(0).click();
2256
items.item(1).click();
2257
items.item(2).click();
2262
"test nodelist.on() + nodelist.detach(synth)": function () {
2264
items = Y.all('.nested li');
2270
items.on('synth', fn);
2272
items.item(0).click();
2273
items.item(1).click();
2274
items.item(2).click();
2278
items.detach('synth');
2281
items.item(0).click();
2282
items.item(1).click();
2283
items.item(2).click();
2287
items.on('synth', fn);
2288
items.on('synth', fn);
2289
items.on('click', fn);
2292
items.item(0).click();
2293
items.item(1).click();
2294
items.item(2).click();
2298
items.detach('synth');
2301
items.item(0).click();
2302
items.item(1).click();
2303
items.item(2).click();
2308
"test nodelist.on() + nodelist.detach()": function () {
2310
items = Y.all('.nested li');
2316
items.on('synth', fn);
2318
items.item(0).click();
2319
items.item(1).click();
2320
items.item(2).click();
2327
items.item(0).click();
2328
items.item(1).click();
2329
items.item(2).click();
2333
items.on('synth', fn);
2334
items.on('synth', fn);
2335
items.on('click', fn);
2338
items.item(0).click();
2339
items.item(1).click();
2340
items.item(2).click();
2347
items.item(0).click();
2348
items.item(1).click();
2349
items.item(2).click();
2354
"test nodelist.on() + nodelist.detachAll()": function () {
2356
items = Y.all('.nested li');
2362
items.on('synth', fn);
2364
items.item(0).click();
2365
items.item(1).click();
2366
items.item(2).click();
2373
items.item(0).click();
2374
items.item(1).click();
2375
items.item(2).click();
2379
items.on('synth', fn);
2380
items.on('synth', fn);
2381
items.on('click', fn);
2384
items.item(0).click();
2385
items.item(1).click();
2386
items.item(2).click();
2393
items.item(0).click();
2394
items.item(1).click();
2395
items.item(2).click();
2400
"test nodelist.on() + parent.purge(true, synth)": function () {
2402
items = Y.all('.nested li'),
2403
parent = items.item(0).get('parentNode');
2409
items.on('synth', fn);
2411
items.item(0).click();
2412
items.item(1).click();
2413
items.item(2).click();
2417
parent.purge(true, 'synth');
2420
items.item(0).click();
2421
items.item(1).click();
2422
items.item(2).click();
2426
items.on('synth', fn);
2427
items.on('synth', fn);
2428
items.on('click', fn);
2431
items.item(0).click();
2432
items.item(1).click();
2433
items.item(2).click();
2437
parent.purge(true, 'synth');
2440
items.item(0).click();
2441
items.item(1).click();
2442
items.item(2).click();
2447
"test node.on('cat|__', fn) + node.detach('cat|___')": function () {
2449
item = Y.one('#button1');
2451
function increment() {
2455
item.on('cat|synth', increment);
2461
item.detach('cat|synth');
2468
"test node.on('cat|__', fn) + node.detach('cat|___', fn)": function () {
2470
item = Y.one('#button1');
2472
function increment() {
2476
item.on('cat|synth', increment);
2482
item.detach('cat|synth', increment);
2489
"test node.on('cat|__', fn) + node.detach('cat|*')": function () {
2491
item = Y.one('#button1');
2493
function increment() {
2497
item.on('cat|synth', increment);
2503
item.detach('cat|*');
2510
"test Y.on('cat|__', fn, sel) + node.detach('cat|___')": function () {
2512
item = Y.one('#button1');
2514
function increment() {
2518
Y.on('cat|synth', increment, '#button1');
2524
item.detach('cat|synth');
2531
"test Y.on('cat|__', fn, sel) + node.detach('cat|___', fn)": function () {
2533
item = Y.one('#button1');
2535
function increment() {
2539
Y.on('cat|synth', increment, '#button1');
2545
item.detach('cat|synth', increment);
2552
"test Y.on('cat|__', fn) + node.detach('cat|*')": function () {
2554
item = Y.one('#button1');
2556
function increment() {
2560
Y.on('cat|synth', increment, '#button1');
2566
item.detach('cat|*');
2573
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": function () {
2575
items = Y.all('#inner p');
2577
function increment() {
2581
items.on('cat|synth', increment);
2587
items.detach('cat|synth');
2594
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": function () {
2596
items = Y.all('#inner p');
2598
function increment() {
2602
items.on('cat|synth', increment);
2608
items.detach('cat|synth', increment);
2615
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": function () {
2617
items = Y.all('#inner p');
2619
function increment() {
2623
items.on('cat|synth', increment);
2629
items.detach('cat|*');
2636
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": function () {
2638
items = Y.all('#inner p');
2640
function increment() {
2644
Y.on('cat|synth', increment, '#inner p');
2650
items.detach('cat|synth');
2657
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": function () {
2659
items = Y.all('#inner p');
2661
function increment() {
2665
Y.on('cat|synth', increment, '#inner p');
2671
items.detach('cat|synth', increment);
2678
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": function () {
2680
items = Y.all('#inner p');
2682
function increment() {
2686
Y.on('cat|synth', increment, '#inner p');
2692
items.detach('cat|*');
2698
// Y.on('cat|_', fn, multiSelector) + nodelist.detach('cat|_'[, fn]);
2701
suite.add(new Y.Test.Case({
2702
name: "processArgs",
2704
setUp: function () {
2708
processArgs: function (args, delegate) {
2709
return [args.splice(3,1)[0], delegate];
2712
on: function (node, sub, notifier, filter) {
2713
var method = (filter) ? 'delegate' : 'on';
2715
sub._handle = node[method]('click', function (e) {
2721
detach: function (node, sub) {
2722
sub._handle.detach();
2725
config.delegate = config.on;
2726
config.detachDelegate = config.detach;
2728
Y.Event.define('synth', config, true);
2732
"test Y.on('synth', fn, selector, extra)": function () {
2734
target = Y.one("#item3"),
2735
type, currentTarget, thisObj, extra, callbackArgs;
2737
Y.on('synth', function (e) {
2739
currentTarget = e.currentTarget;
2741
extra = e.sub._extra[0];
2742
callbackArgs = arguments.length;
2743
}, '#item3', 'EXTRA');
2747
areSame('synth', type);
2748
areSame(target, currentTarget);
2749
areSame(target, thisObj);
2750
areSame('EXTRA', extra);
2751
areSame(1, callbackArgs);
2754
"Y.on('synth', fn, '#not-here-yet', extra) should resubscribe with original arguments": function () {
2756
target, type, currentTarget, thisObj, extra, callbackArgs;
2758
Y.on('synth', function (e) {
2760
currentTarget = e.currentTarget;
2762
extra = e.sub._extra[0];
2763
callbackArgs = arguments.length;
2764
}, '#item4', 'EXTRA');
2766
setTimeout(function () {
2767
target = Y.Node.create('<li id="item4"><p>Item 4</p></li>');
2768
Y.one(".nested").append(target);
2770
setTimeout(function () {
2771
test.resume(function () {
2773
areSame('synth', type);
2774
areSame(target, currentTarget);
2775
areSame(target, thisObj);
2776
areSame('EXTRA', extra);
2777
areSame(1, callbackArgs);
2787
suite.add(new Y.Test.Case({
2796
Y.Test.Runner.add(suite);