2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('event-outside', function (Y, NAME) {
11 * Outside events are synthetic DOM events that fire when a corresponding native
12 * or synthetic DOM event occurs outside a bound element.
14 * The following outside events are pre-defined by this module:
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>.
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
45 * @submodule event-outside
46 * @author brettstimmerman
50 // Outside events are pre-defined for each of these native DOM events
52 'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
53 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
58 * Defines a new outside event to correspond with the given DOM event.
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>.
65 * @method defineOutside
66 * @param {String} event DOM event
67 * @param {String} name (optional) custom outside event name
71 Y.Event.defineOutside = function (event, name) {
72 name = name || (event + 'outside');
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;
85 detach: function (node, sub, notifier) {
89 delegate: function (node, sub, notifier, filter) {
90 sub.handle = Y.one('doc').delegate(event, function (e) {
91 if (this.isOutside(node, e.target)) {
97 isOutside: function (node, target) {
98 return target !== node && !target.ancestor(function (p) {
103 config.detachDelegate = config.detach;
105 Y.Event.define(name, config);
108 // Define outside events for some common native DOM events
109 Y.Array.each(nativeEvents, function (event) {
110 Y.Event.defineOutside(event);
114 }, '3.13.0', {"requires": ["event-synthetic"]});