Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1.  
  2. YUI().use('event', 'base', function(Y) {
  3.  
  4. var Foo = function() {
  5. Foo.superclass.constructor.apply(this, arguments);
  6. };
  7. Y.extend(Foo, Y.Base, {
  8. }, {
  9. NAME: 'foo'
  10. });
  11.  
  12. var Bar = function() {
  13. Bar.superclass.constructor.apply(this, arguments);
  14. };
  15. Y.extend(Bar, Y.Base, {
  16. _prevFn: function() {
  17. console.info('Bar::Event Prevented Function..');
  18. },
  19. _defFn: function() {
  20. console.info('Bar::Event Default Function..');
  21. },
  22. initializer: function() {
  23. this.publish('event', {
  24. defaultFn: this._defFn,
  25. preventedFn: this._prevFn,
  26. emitFacade: true,
  27. bubbles: true,
  28. prefix: 'bar'
  29. });
  30. }
  31. }, {
  32. NAME: 'bar'
  33. });
  34.  
  35. var b = new Bar();
  36. b.on('bar:event', function(e) {
  37. console.info('Single Instance Prevented');
  38. e.preventDefault();
  39. });
  40. console.log('Single Instance Fire');
  41. b.fire('bar:event');
  42.  
  43.  
  44. var f = new Foo();
  45. var b1 = new Bar();
  46. b1.addTarget(f);
  47. f.on('bar:event', function(e) {
  48. console.info('Bubble Instance Prevented');
  49. e.preventDefault();
  50. });
  51. console.log('Bubbled Instance Fire');
  52. b1.fire('bar:event');
  53.  
  54.  
  55. });
Add Comment
Please, Sign In to add comment