[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/event-mouseenter/ -> event-mouseenter.js (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1