Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

event-mouseenter-debug.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('event-mouseenter', function(Y) {
  9. /**
  10. * <p>Adds subscription and delegation support for mouseenter and mouseleave
  11. * events. Unlike mouseover and mouseout, these events aren't fired from child
  12. * elements of a subscribed node.</p>
  13. *
  14. * <p>This avoids receiving three mouseover notifications from a setup like</p>
  15. *
  16. * <pre><code>div#container > p > a[href]</code></pre>
  17. *
  18. * <p>where</p>
  19. *
  20. * <pre><code>Y.one('#container').on('mouseover', callback)</code></pre>
  21. *
  22. * <p>When the mouse moves over the link, one mouseover event is fired from
  23. * #container, then when the mouse moves over the p, another mouseover event is
  24. * fired and bubbles to #container, causing a second notification, and finally
  25. * when the mouse moves over the link, a third mouseover event is fired and
  26. * bubbles to #container for a third notification.</p>
  27. *
  28. * <p>By contrast, using mouseenter instead of mouseover, the callback would be
  29. * executed only once when the mouse moves over #container.</p>
  30. *
  31. * @module event
  32. * @submodule event-mouseenter
  33. */
  34. var domEventProxies = Y.Env.evt.dom_wrappers,
  35. contains = Y.DOM.contains,
  36. toArray = Y.Array,
  37. noop = function () {},
  38. config = {
  39. proxyType: "mouseover",
  40. relProperty: "fromElement",
  41. _notify: function (e, property, notifier) {
  42. var el = this._node,
  43. related = e.relatedTarget || e[property];
  44. if (el !== related && !contains(el, related)) {
  45. notifier.fire(new Y.DOMEventFacade(e, el,
  46. domEventProxies['event:' + Y.stamp(el) + e.type]));
  47. }
  48. },
  49. on: function (node, sub, notifier) {
  50. var el = Y.Node.getDOMNode(node),
  51. args = [
  52. this.proxyType,
  53. this._notify,
  54. el,
  55. null,
  56. this.relProperty,
  57. notifier];
  58. sub.handle = Y.Event._attach(args, { facade: false });
  59. // node.on(this.proxyType, notify, null, notifier);
  60. },
  61. detach: function (node, sub) {
  62. sub.handle.detach();
  63. },
  64. delegate: function (node, sub, notifier, filter) {
  65. var el = Y.Node.getDOMNode(node),
  66. args = [
  67. this.proxyType,
  68. noop,
  69. el,
  70. null,
  71. notifier
  72. ];
  73. sub.handle = Y.Event._attach(args, { facade: false });
  74. sub.handle.sub.filter = filter;
  75. sub.handle.sub.relProperty = this.relProperty;
  76. sub.handle.sub._notify = this._filterNotify;
  77. },
  78. _filterNotify: function (thisObj, args, ce) {
  79. args = args.slice();
  80. if (this.args) {
  81. args.push.apply(args, this.args);
  82. }
  83. var currentTarget = Y.delegate._applyFilter(this.filter, args, ce),
  84. related = args[0].relatedTarget || args[0][this.relProperty],
  85. e, i, len, ret, ct;
  86. if (currentTarget) {
  87. currentTarget = toArray(currentTarget);
  88. for (i = 0, len = currentTarget.length && (!e || !e.stopped); i < len; ++i) {
  89. ct = currentTarget[0];
  90. if (!contains(ct, related)) {
  91. if (!e) {
  92. e = new Y.DOMEventFacade(args[0], ct, ce);
  93. e.container = Y.one(ce.el);
  94. }
  95. e.currentTarget = Y.one(ct);
  96. // TODO: where is notifier? args? this.notifier?
  97. ret = args[1].fire(e);
  98. if (ret === false) {
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. return ret;
  105. },
  106. detachDelegate: function (node, sub) {
  107. sub.handle.detach();
  108. }
  109. };
  110. Y.Event.define("mouseenter", config, true);
  111. Y.Event.define("mouseleave", Y.merge(config, {
  112. proxyType: "mouseout",
  113. relProperty: "toElement"
  114. }), true);
  115. }, '3.4.0' ,{requires:['event-synthetic']});