[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/2in3/2.9.0/build/yui2-event-mouseenter/ -> yui2-event-mouseenter-debug.js (source)

   1  YUI.add('yui2-event-mouseenter', function(Y) {
   2      var YAHOO    = Y.YUI2;
   3      /*
   4  Copyright (c) 2011, Yahoo! Inc. All rights reserved.
   5  Code licensed under the BSD License:
   6  http://developer.yahoo.com/yui/license.html
   7  version: 2.9.0
   8  */
   9  /**
  10   * Augments the Event Utility with support for the mouseenter and mouseleave 
  11   * events:  A mouseenter event fires the first time the mouse enters an 
  12   * element; a mouseleave event first the first time the mouse leaves an 
  13   * element.
  14   * 
  15   * @module event-mouseenter
  16   * @title Event Utility mouseenter and mouseout Module
  17   * @namespace YAHOO.util
  18   * @requires event
  19   */
  20  
  21  (function () {
  22  
  23      var Event = YAHOO.util.Event,
  24          Lang = YAHOO.lang,
  25  
  26          addListener = Event.addListener,
  27          removeListener = Event.removeListener,
  28          getListeners = Event.getListeners,
  29  
  30          delegates = [],
  31          
  32          specialTypes = {
  33              mouseenter: "mouseover",
  34              mouseleave: "mouseout"
  35          }, 
  36  
  37          remove = function(el, type, fn) {
  38  
  39              var index = Event._getCacheIndex(delegates, el, type, fn),
  40                  cacheItem,
  41                  returnVal;
  42  
  43              if (index >= 0) {
  44                  cacheItem = delegates[index];
  45              }
  46  
  47              if (el && cacheItem) {
  48  
  49                  //    removeListener will translate the value of type                
  50                  returnVal = removeListener.call(Event, cacheItem[0], type, cacheItem[3]);
  51          
  52                  if (returnVal) {
  53                      delete delegates[index][2];
  54                      delete delegates[index][3];
  55                      delegates.splice(index, 1);
  56                  }
  57          
  58              }
  59  
  60              return returnVal;
  61  
  62          };        
  63  
  64  
  65      Lang.augmentObject(Event._specialTypes, specialTypes); 
  66  
  67      Lang.augmentObject(Event, {
  68  
  69          /**
  70           * Creates a delegate function used to call mouseover and mouseleave 
  71           * event listeners specified via the 
  72           * <code>YAHOO.util.Event.addListener</code> 
  73           * or <code>YAHOO.util.Event.on</code> method.
  74           *
  75           * @method _createMouseDelegate
  76           *
  77           * @param {Function} fn        The method (event listener) to call
  78           * @param {Object}   obj    An arbitrary object that will be 
  79           *                             passed as a parameter to the listener
  80           * @param {Boolean|object}  overrideContext  If true, the value of the 
  81           *                             obj parameter becomes the execution context
  82           *                          of the listener. If an object, this object
  83           *                          becomes the execution context. 
  84           * @return {Function} Function that will call the event listener 
  85           * specified by either the <code>YAHOO.util.Event.addListener</code> 
  86           * or <code>YAHOO.util.Event.on</code> method.
  87           * @private
  88           * @static
  89           * @for Event
  90           */
  91          _createMouseDelegate: function (fn, obj, overrideContext) {
  92  
  93              return function (event, container) {
  94  
  95                  var el = this,
  96                      relatedTarget = Event.getRelatedTarget(event),
  97                      context,
  98                      args;
  99  
 100                  if (el != relatedTarget && !YAHOO.util.Dom.isAncestor(el, relatedTarget)) {
 101  
 102                      context = el;
 103  
 104                      if (overrideContext) {
 105                          if (overrideContext === true) {
 106                              context = obj;
 107                          } else {
 108                              context = overrideContext;
 109                          }
 110                      }
 111  
 112                      // The default args passed back to a mouseenter or 
 113                      // mouseleave listener are: the event, and any object
 114                      // the user passed when subscribing
 115  
 116                      args = [event, obj];
 117  
 118                      // Add the element and delegation container as arguments
 119                      // when delegating mouseenter and mouseleave
 120  
 121                      if (container) {
 122                          args.splice(1, 0, el, container);
 123                      }
 124  
 125                      return fn.apply(context, args);
 126  
 127                  }
 128  
 129              };
 130  
 131          },
 132          
 133          addListener: function (el, type, fn, obj, overrideContext) {
 134  
 135              var fnDelegate,
 136                  returnVal;
 137  
 138              if (specialTypes[type]) {
 139  
 140                  fnDelegate = Event._createMouseDelegate(fn, obj, overrideContext);
 141                  
 142                  fnDelegate.mouseDelegate = true;
 143  
 144                  delegates.push([el, type, fn, fnDelegate]);
 145  
 146                  //    addListener will translate the value of type
 147                  returnVal = addListener.call(Event, el, type, fnDelegate);
 148  
 149              }
 150              else {
 151                  returnVal = addListener.apply(Event, arguments);
 152              }
 153  
 154              return returnVal;
 155  
 156          },
 157          
 158          removeListener: function (el, type, fn) {
 159  
 160              var returnVal;
 161  
 162              if (specialTypes[type]) {
 163                  returnVal = remove.apply(Event, arguments);
 164              }
 165              else {
 166                  returnVal = removeListener.apply(Event, arguments);
 167              }
 168  
 169              return returnVal;
 170  
 171          },
 172          
 173          getListeners: function (el, type) {
 174  
 175              //    If the user specified the type as mouseover or mouseout, 
 176              //    need to filter out those used by mouseenter and mouseleave.
 177              //    If the user specified the type as mouseenter or mouseleave, 
 178              //    need to filter out the true mouseover and mouseout listeners.
 179  
 180              var listeners = [],
 181                  elListeners,
 182                  bMouseOverOrOut = (type === "mouseover" || type === "mouseout"),
 183                  bMouseDelegate,
 184                  i,
 185                  l;
 186              
 187              if (type && (bMouseOverOrOut || specialTypes[type])) {
 188                  
 189                  elListeners = getListeners.call(Event, el, this._getType(type));
 190  
 191                  if (elListeners) {
 192  
 193                      for (i=elListeners.length-1; i>-1; i--) {
 194  
 195                          l = elListeners[i];
 196                          bMouseDelegate = l.fn.mouseDelegate;
 197  
 198                          if ((specialTypes[type] && bMouseDelegate) || (bMouseOverOrOut && !bMouseDelegate)) {
 199                              listeners.push(l);
 200                          }
 201  
 202                      }
 203  
 204                  }
 205                  
 206              }
 207              else {
 208                  listeners = getListeners.apply(Event, arguments);
 209              }
 210  
 211              return (listeners && listeners.length) ? listeners : null;
 212              
 213          }
 214          
 215      }, true);
 216      
 217      Event.on = Event.addListener;
 218  
 219  }());
 220  YAHOO.register("event-mouseenter", YAHOO.util.Event, {version: "2.9.0", build: "2800"});
 221  
 222  }, '2.9.0' ,{"requires": ["yui2-yahoo", "yui2-dom", "yui2-event"]});


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