test_propagation_bubble.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var parent,
  2. child,
  3. hammerChild,
  4. hammerParent;
  5. module('Propagation (Tap in Child and Parent)', {
  6. setup: function() {
  7. parent = document.createElement('div');
  8. child = document.createElement('div');
  9. document.getElementById('qunit-fixture').appendChild(parent);
  10. parent.appendChild(child);
  11. hammerParent = new Hammer.Manager(parent);
  12. hammerChild = new Hammer.Manager(child);
  13. hammerChild.add(new Hammer.Tap());
  14. hammerParent.add(new Hammer.Tap());
  15. },
  16. teardown: function() {
  17. hammerChild.destroy();
  18. hammerParent.destroy();
  19. }
  20. });
  21. test('Tap on the child, fires also the tap event to the parent', function() {
  22. expect(2);
  23. hammerChild.on('tap', function() {
  24. ok(true);
  25. });
  26. hammerParent.on('tap', function() {
  27. ok(true);
  28. });
  29. utils.dispatchTouchEvent(child, 'start', 0, 10);
  30. utils.dispatchTouchEvent(child, 'end', 0, 10);
  31. });
  32. test('When tap on the child and the child stops the input event propagation, the tap event does not get fired in the parent', function() {
  33. expect(1);
  34. hammerChild.on('tap', function() {
  35. ok(true);
  36. });
  37. hammerParent.on('tap', function() {
  38. throw new Error('parent tap gesture should not be recognized');
  39. });
  40. child.addEventListener('touchend', function(ev) {
  41. ev.stopPropagation();
  42. });
  43. utils.dispatchTouchEvent(child, 'start', 0, 10);
  44. utils.dispatchTouchEvent(child, 'end', 0, 10);
  45. });