472cb5998fc636f7d3cb6e3780dba7986a75e912Luke Smith<!DOCTYPE html>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore<html>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore<head>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <title>YUI DOM Event Tests</title>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore</head>
0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore<body class="yui3-skin-sam">
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore <div id="doc">
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <div id="clickcontainer">
0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore <p id="clicker1" class="clickers"><a id='clicka'>click1</a></p>
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore <p id="clicker2" class="clickers">click2</p>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore </div>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore </div>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <!-- YUI3 Core //-->
a4a12866ef14f142b1a799fc246a542d69af602bLuke Smith <script type="text/javascript" src="/build/yui/yui.js"></script>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <!-- Initialization process //-->
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <script type="text/javascript">
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore YUI({
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith //lazyEventFacade: true,
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith allowRollup: false
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }).use('test-console', 'test', 'node', 'event-simulate', function (Y) {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore // creating the console...
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith (new Y.Test.Console()).render();
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore // starting the testing process
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // add the test cases and suites
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Test.Runner.add(new Y.Test.Case({
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore name: "DOM Event Tests",
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith _should: {
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith error: {
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // This test fakes the processing of click and mouseup
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // events without actually triggering them (because
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // Event.simulate tries to correct e.button and doesn't
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // accept e.which as simulated event config) which
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // runs afoul of the document.createEventObject(e)
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith // used to allow getters
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith "test left and right click, mouseup": Y.config.lazyEventFacade
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith }
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith },
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith tearDown: function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith if (this.timer) {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith this.timer.cancel();
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith },
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_on_with_string: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore obj = {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore a: 1
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore },
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore node = Y.one('#clickcontainer'),
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore el = document.getElementById('clickcontainer');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.attachEvent('click', function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log("IE click");
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // });
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.addEventListener('click', function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log("DOM2 click");
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // }, false);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.onclick = function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log('DOM0 click');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // };
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked = true;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, '#clickcontainer', obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore Y.Event.simulate(el, 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isTrue(clicked, "click handler via Y.on didn't work when passed a string.");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_on_with_node: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore obj = {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore a: 1
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked = true;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, node, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isTrue(clicked, "click handler via Y.on didn't work when passed a node.");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_node_on: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore obj = {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore a: 1
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked = true;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isTrue(clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_node_detachall: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore var clicked = false, overed = false,
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked = true;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.on('mouseover', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore overed = true;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.detachAll();
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isFalse(clicked, "click handler was not removed");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isFalse(overed, "mouseover handler was not removed");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_nodelist_on: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore obj = {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore a: 1
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore nodelist = Y.all('.clickers');
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore nodelist.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked++;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work"); // bug #2528155
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work"); // bug #2528155
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work"); // bug #2528155
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work"); // bug #2528155
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_y_on_with_nodelist: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore obj = {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore a: 1
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore },
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore nodelist = Y.all('.clickers');
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked++;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, nodelist, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore test_y_detach_with_nodelist: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore obj = {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore a: 1
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore nodelist = Y.all('.clickers'),
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore fn = function(e, extra1, extra2) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore clicked++;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context = this;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1 = extra1;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2 = extra2;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore } ;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.on('click', fn, nodelist, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.detach('click', fn, nodelist);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler wasn't removed");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
111837fe5c14f516f4a15878f9bbaf7bb0091364Adam Moore test_y_detach_with_array: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore obj = {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore a: 1
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore arrayofselectors = ['#clicker1', '#clicker2'];
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore fn = function(e, extra1, extra2) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore clicked++;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context = this;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1 = extra1;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2 = extra2;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore } ;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.on('click', fn, arrayofselectors, obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.detach('click', fn, arrayofselectors);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler wasn't removed");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore },
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_y_on_with_selector_multiple_match: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore obj = {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore a: 1
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore };
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked++;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context = this;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1 = extra1;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, '.clickers', obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_y_on_with_htmlelementcollection: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2,
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore obj = {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore a: 1
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore };
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked++;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context = this;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1 = extra1;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, document.getElementsByTagName('p'), obj, 2, 3);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, clicked, "click handler didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(1, context.a, "context didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(2, ex1, "extra arg1 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(3, ex2, "extra arg2 didn't work");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore test_y_on_empty_array: function() {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.on('click', function(e, extra1, extra2) {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore //
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore }, []);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore },
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_detach_by_sig: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore context,
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex1,
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex2,
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore obj = {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore a: 1
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore }, fn = function(e, extra1, extra2) {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore clicked++;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore context = this;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex1 = extra1;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex2 = extra2;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore },
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore els = document.getElementsByTagName('p');
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.on('click', fn, '#clicker1', obj, 2, 3);
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.detach('click', fn, '#clicker1', obj, 2, 3);
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.on('click', fn, '#clicker1');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.detach('click', fn, '#clicker1');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
03f9aefec605c500b64625110a955e65b900b100Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore var node = Y.one("#clicker1");
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
03f9aefec605c500b64625110a955e65b900b100Adam Moore node.on('click', fn);
03f9aefec605c500b64625110a955e65b900b100Adam Moore node.detach('click', fn);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore // Y.on('windowresize', fn);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore // // unbind windowresize - THIS IS NOT WORKING
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore // Y.detach('windowresize', fn);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore // Y.Event.simulate(window, 'resize');
03f9aefec605c500b64625110a955e65b900b100Adam Moore // Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_multi_detach: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore context,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex1,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex2,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore obj = {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore a: 1
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, fn = function(e, extra1, extra2) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore clicked++;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore context = this;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex1 = extra1;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex2 = extra2;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore els = document.getElementsByTagName('p');
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore var handle = Y.on('click', fn, '.clickers', obj, 2, 3);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore // Y.log(handle);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle.detach();
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, clicked, "single detach handle for multiple listeners doesn't work.");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_onavail_detach: function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var avail = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle = Y.on('available', function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore avail++;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, '#notthereyet'),
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div = document.createElement("div");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div.id = 'notthereyet';
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle.detach();
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore document.body.appendChild(div);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore this.wait(function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, avail, "onavailable wasn't canceled.");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, 300);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore },
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_lazy_attach_detach: function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var avail = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle = Y.on('click', function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore avail++;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, '#notthereyet'),
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div = document.createElement("div");
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div.id = 'notthereyet';
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore document.body.appendChild(div);
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore this.wait(function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore handle.detach();
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('notthereyet'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, avail, "lazy detacher didn't work.");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, 300);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore },
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore test_purge: function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore var a = 0,
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore b = 0
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore c = 0,
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore d = 0;
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore a++;
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clickcontainer');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore b++;
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicker1');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore c++;
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicker2');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore d++;
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicka');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clicka'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, a);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, b);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(0, c);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, d);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.purgeElement('#clickcontainer', true, 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clicka'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, a);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, b);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(0, c);
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Assert.areEqual(1, d);
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore },
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore test_categories: function() {
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore var count = 0;
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore var list = Y.all('.clickers');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore list.on('category|click', function(e) {
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore count++;
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore });
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
f6baa527839e75655081768c365a749c59edc80dAdam Moore // @TODO FIX
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.all('.foo').detach('category|click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore list.detach('category|click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Assert.areEqual(2, count);
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.Event.simulate(document.getElementById('clicker1'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.Event.simulate(document.getElementById('clicker2'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Assert.areEqual(2, count);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith },
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith "test left and right click, mouseup": function () {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith var node = Y.one('#clicker1'),
f841387cb4997959ecf710977b259b86f959ba48Luke Smith el = node._node,
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired = {},
f841387cb4997959ecf710977b259b86f959ba48Luke Smith typePrefix = 'event:' + Y.stamp(el),
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // cribbed from the event-base-ie.js conditional loading
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith imp = Y.config.doc && Y.config.doc.implementation,
f328401955235416edeee0c5ac3ae9fb6dee940aLuke Smith testIE = !(imp && imp.hasFeature
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith && imp.hasFeature('Events', '2.0')),
f0a82c6a29c12f3a85bdc740203affbbe75ce665Luke Smith handle;
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // custom simulation because Y.Event.simulate attempts to
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // correct e.button and doesn't accept e.which
f841387cb4997959ecf710977b259b86f959ba48Luke Smith function mouseEvent(type, config) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith var key = typePrefix + type,
f841387cb4997959ecf710977b259b86f959ba48Luke Smith wrapper = Y.Env.evt.dom_wrappers[key];
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith config.type = type;
f841387cb4997959ecf710977b259b86f959ba48Luke Smith config.target = el;
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith wrapper.fire(Y.Event.getEvent(config, el));
f841387cb4997959ecf710977b259b86f959ba48Luke Smith }
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle = node.on(['mouseup', 'click'], function (e) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired[e.type] = true;
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.areSame(1, e.button);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.areSame(1, e.which);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // FF 5-, Chrome, Opera 11- left mouseup,click
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('mouseup', { button: 0, which: 1 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('click', { button: 0, which: 1 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith if (testIE) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // IE 6 - 8 left click
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('click', { button: 1 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith }
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle.detach();
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.isTrue(fired.mouseup);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.isTrue(fired.click);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired = {};
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle = node.on(['mouseup', 'click'], function (e) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired[e.type] = true;
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.areSame(3, e.button);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.areSame(3, e.which);
f841387cb4997959ecf710977b259b86f959ba48Luke Smith });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // FF, Chrome, Opera, right mouseup
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // Not simulating right 'click' because I can't get the
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // event to be triggered manually
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('mouseup', { button: 2, which: 3 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith if (testIE) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // IE 6 - 8 left click
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('mouseup', { button: 2 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith }
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle.detach();
f841387cb4997959ecf710977b259b86f959ba48Luke Smith
f841387cb4997959ecf710977b259b86f959ba48Luke Smith Y.Assert.isTrue(fired.mouseup);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith },
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith "error in onavailable callback should not result in infinite _poll": function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith var test = this,
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith found = false;
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.Assert.isFalse(!!Y.Event.locked);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.on('available', function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith found = true;
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith throw "test error";
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }, '#infinite-poll');
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith this.timer = Y.later(25, {}, function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith if (found) {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith test.timer.cancel();
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.one('#infinite-poll').remove(true);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith test.resume(function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.Assert.isFalse(Y.Event.locked);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith });
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }, null, true);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.later(25, {}, function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.one('#clickcontainer')
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith .append('<p id="infinite-poll">THIS SHOULD NOT BE LEFT OVER</p>');
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith });
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith test.wait();
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore }));
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore //run all tests
9a76bc095233b0cb0be3a913f5913bfc72c38b6cSatyen Desai Y.Test.Runner.setName("DOMEvents");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Test.Runner.run();
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore /* finishing the testing process */
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore });
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore </script>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore</body>
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore</html>