[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/event-outside/ -> event-outside-debug.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-outside', function (Y, NAME) {
   9  
  10  /**
  11   * Outside events are synthetic DOM events that fire when a corresponding native
  12   * or synthetic DOM event occurs outside a bound element.
  13   *
  14   * The following outside events are pre-defined by this module:
  15   * <ul>
  16   *   <li>blur</li>
  17   *   <li>change</li>
  18   *   <li>click</li>
  19   *   <li>dblclick</li>
  20   *   <li>focus</li>
  21   *   <li>keydown</li>
  22   *   <li>keypress</li>
  23   *   <li>keyup</li>
  24   *   <li>mousedown</li>
  25   *   <li>mousemove</li>
  26   *   <li>mouseout</li>
  27   *   <li>mouseover</li>
  28   *   <li>mouseup</li>
  29   *   <li>select</li>
  30   *   <li>submit</li>
  31   * </ul>
  32   *
  33   * Define new outside events with
  34   * <code>Y.Event.defineOutside(eventType);</code>.
  35   * By default, the created synthetic event name will be the name of the event
  36   * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
  37   * a different name for the created Event, pass it as a second argument like so:
  38   * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
  39   *
  40   * This module was contributed by Brett Stimmerman, promoted from his
  41   * gallery-outside-events module at
  42   * http://yuilibrary.com/gallery/show/outside-events
  43   *
  44   * @module event
  45   * @submodule event-outside
  46   * @author brettstimmerman
  47   * @since 3.4.0
  48   */
  49  
  50  // Outside events are pre-defined for each of these native DOM events
  51  var nativeEvents = [
  52          'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
  53          'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
  54          'select', 'submit'
  55      ];
  56  
  57  /**
  58   * Defines a new outside event to correspond with the given DOM event.
  59   *
  60   * By default, the created synthetic event name will be the name of the event
  61   * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
  62   * a different name for the created Event, pass it as a second argument like so:
  63   * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
  64   *
  65   * @method defineOutside
  66   * @param {String} event DOM event
  67   * @param {String} name (optional) custom outside event name
  68   * @static
  69   * @for Event
  70   */
  71  Y.Event.defineOutside = function (event, name) {
  72      name = name || (event + 'outside');
  73  
  74      var config = {
  75  
  76          on: function (node, sub, notifier) {
  77              sub.handle = Y.one('doc').on(event, function(e) {
  78                  if (this.isOutside(node, e.target)) {
  79                      e.currentTarget = node;
  80                      notifier.fire(e);
  81                  }
  82              }, this);
  83          },
  84  
  85          detach: function (node, sub, notifier) {
  86              sub.handle.detach();
  87          },
  88  
  89          delegate: function (node, sub, notifier, filter) {
  90              sub.handle = Y.one('doc').delegate(event, function (e) {
  91                  if (this.isOutside(node, e.target)) {
  92                      notifier.fire(e);
  93                  }
  94              }, filter, this);
  95          },
  96  
  97          isOutside: function (node, target) {
  98              return target !== node && !target.ancestor(function (p) {
  99                      return p === node;
 100                  });
 101          }
 102      };
 103      config.detachDelegate = config.detach;
 104  
 105      Y.Event.define(name, config);
 106  };
 107  
 108  // Define outside events for some common native DOM events
 109  Y.Array.each(nativeEvents, function (event) {
 110      Y.Event.defineOutside(event);
 111  });
 112  
 113  
 114  }, '3.17.2', {"requires": ["event-synthetic"]});


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