0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore <p id="clicker1" class="clickers"><a id='clicka'>click1</a></p>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <!-- YUI3 Core //-->
a4a12866ef14f142b1a799fc246a542d69af602bLuke Smith <script type="text/javascript" src="/build/yui/yui.js"></script>
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore <!-- Initialization process //-->
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) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore // creating the console...
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith (new Y.Test.Console()).render();
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore // starting the testing process
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // add the test cases and suites
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore name: "DOM Event Tests",
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
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith tearDown: function () {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_on_with_string: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore node = Y.one('#clickcontainer'),
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore el = document.getElementById('clickcontainer');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.attachEvent('click', function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log("IE click");
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.addEventListener('click', function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log("DOM2 click");
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // }, false);
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // el.onclick = function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore // console.log('DOM0 click');
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);
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 test_on_with_node: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
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);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
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 test_node_on: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = false,
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
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);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
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 test_node_detachall: function() {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore var clicked = false, overed = false,
057b95e2faede12bf00a82837632ae67e03ad0fcAdam Moore node = Y.one('#clickcontainer');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.on('click', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore clicked = true;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore node.on('mouseover', function(e, extra1, extra2) {
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore overed = true;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clickcontainer'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isFalse(clicked, "click handler was not removed");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.isFalse(overed, "mouseover handler was not removed");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_nodelist_on: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore nodelist = Y.all('.clickers');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore nodelist.on('click', function(e, extra1, extra2) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.Event.simulate(document.getElementById('clicker2'), 'click');
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 test_y_on_with_nodelist: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore nodelist = Y.all('.clickers');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore context = this;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex1 = extra1;
e69255aa5a65f8406ba2fabaf69fe4e1d05daf69Adam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, nodelist, obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.Event.simulate(document.getElementById('clicker2'), 'click');
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");
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore test_y_detach_with_nodelist: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore nodelist = Y.all('.clickers'),
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore fn = function(e, extra1, extra2) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context = this;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1 = extra1;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2 = extra2;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.on('click', fn, nodelist, obj, 2, 3);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.detach('click', fn, nodelist);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler wasn't removed");
111837fe5c14f516f4a15878f9bbaf7bb0091364Adam Moore test_y_detach_with_array: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore arrayofselectors = ['#clicker1', '#clicker2'];
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore fn = function(e, extra1, extra2) {
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore context = this;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex1 = extra1;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore ex2 = extra2;
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.on('click', fn, arrayofselectors, obj, 2, 3);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.detach('click', fn, arrayofselectors);
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55Adam Moore Y.Assert.areEqual(1, clicked, "click handler wasn't removed");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_y_on_with_selector_multiple_match: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context = this;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1 = extra1;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, '.clickers', obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.Event.simulate(document.getElementById('clicker2'), 'click');
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 test_y_on_with_htmlelementcollection: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.on('click', function(e, extra1, extra2) {
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore context = this;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex1 = extra1;
6a3faa9e0e4639febffbd7018ce47b861626d0baAdam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore }, document.getElementsByTagName('p'), obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
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 Y.Event.simulate(document.getElementById('clicker2'), 'click');
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");
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore test_y_on_empty_array: function() {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.on('click', function(e, extra1, extra2) {
df39d9c816a02c79aa6a3436784de5bba0ef7075Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_detach_by_sig: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore }, fn = function(e, extra1, extra2) {
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore context = this;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex1 = extra1;
2f03ba9e07559709925bfe6cb1b40c83aa810672Adam Moore ex2 = extra2;
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.on('click', fn, '#clicker1', obj, 2, 3);
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.detach('click', fn, '#clicker1', obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.on('click', fn, '#clicker1');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.detach('click', fn, '#clicker1');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
03f9aefec605c500b64625110a955e65b900b100Adam Moore var node = Y.one("#clicker1");
03f9aefec605c500b64625110a955e65b900b100Adam Moore node.on('click', fn);
f89b4dd628000da1b003539c3c181e6b9880de00Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
03f9aefec605c500b64625110a955e65b900b100Adam Moore Y.Assert.areEqual(1, clicked, "detach by signature was a failure");
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");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_multi_detach: function() {
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore var clicked = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, fn = function(e, extra1, extra2) {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore context = this;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex1 = extra1;
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore ex2 = extra2;
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore var handle = Y.on('click', fn, '.clickers', obj, 2, 3);
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, clicked, "single detach handle for multiple listeners doesn't work.");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_onavail_detach: function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var avail = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle = Y.on('available', function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, '#notthereyet'),
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div.id = 'notthereyet';
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, avail, "onavailable wasn't canceled.");
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore test_lazy_attach_detach: function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore var avail = 0,
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore handle = Y.on('click', function() {
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore }, '#notthereyet'),
bc8660dcb747bedc141ca9061de83f6f32f8018fAdam Moore div.id = 'notthereyet';
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Event.simulate(document.getElementById('notthereyet'), 'click');
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore Y.Assert.areEqual(0, avail, "lazy detacher didn't work.");
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore test_purge: function() {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clickcontainer');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicker1');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicker2');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.on('click', function(e) {
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore }, '#clicka');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.simulate(document.getElementById('clicka'), 'click');
5cbcc8e7f5c3e4ad283e5cb76520840300f81a0aAdam Moore Y.Event.purgeElement('#clickcontainer', true, 'click');
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');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore test_categories: function() {
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore var count = 0;
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore var list = Y.all('.clickers');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore list.on('category|click', function(e) {
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Event.simulate(document.getElementById('clicker1'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore Y.Event.simulate(document.getElementById('clicker2'), 'click');
f6baa527839e75655081768c365a749c59edc80dAdam Moore // @TODO FIX
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.all('.foo').detach('category|click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore list.detach('category|click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.Event.simulate(document.getElementById('clicker1'), 'click');
38ede344a04d04daedd560a485bd38f50e4c0a71Adam Moore // Y.Event.simulate(document.getElementById('clicker2'), 'click');
f841387cb4997959ecf710977b259b86f959ba48Luke Smith "test left and right click, mouseup": function () {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith var node = Y.one('#clicker1'),
f841387cb4997959ecf710977b259b86f959ba48Luke Smith el = node._node,
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')),
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // custom simulation because Y.Event.simulate attempts to
f841387cb4997959ecf710977b259b86f959ba48Luke Smith function mouseEvent(type, config) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith var key = typePrefix + type,
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle = node.on(['mouseup', 'click'], function (e) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired[e.type] = true;
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 if (testIE) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // IE 6 - 8 left click
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('click', { button: 1 });
f841387cb4997959ecf710977b259b86f959ba48Luke Smith handle = node.on(['mouseup', 'click'], function (e) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith fired[e.type] = true;
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 if (testIE) {
f841387cb4997959ecf710977b259b86f959ba48Luke Smith // IE 6 - 8 left click
f841387cb4997959ecf710977b259b86f959ba48Luke Smith mouseEvent('mouseup', { button: 2 });
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith "error in onavailable callback should not result in infinite _poll": function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith var test = this,
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith found = false;
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.on('available', function () {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith found = true;
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith throw "test error";
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }, '#infinite-poll');
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith if (found) {
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith Y.one('#infinite-poll').remove(true);
7a213507f399e32bf880bd234a6265b6807f8ee6Luke Smith }, null, true);
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>');
772f655fcf57e58b97fa46b6a8d3fc772b83f743Adam Moore //run all tests
3641f0baf10c9737e4ac6aac1566bfeaca00eeffAdam Moore /* finishing the testing process */