3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('event-outside', function(Y) {
10
* Outside events are synthetic DOM events that fire when a corresponding native
11
* or synthetic DOM event occurs outside a bound element.
13
* The following outside events are pre-defined by this module:
32
* Define new outside events with
33
* <code>Y.Event.defineOutside(eventType);</code>.
34
* By default, the created synthetic event name will be the name of the event
35
* with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
36
* a different name for the created Event, pass it as a second argument like so:
37
* <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
40
* @submodule event-outside
43
// Outside events are pre-defined for each of these native DOM events
45
'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
46
'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
51
* Defines a new outside event to correspond with the given DOM event.
53
* By default, the created synthetic event name will be the name of the event
54
* with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
55
* a different name for the created Event, pass it as a second argument like so:
56
* <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
58
* @method Y.Event.defineOutside
59
* @param {String} event DOM event
60
* @param {String} name (optional) custom outside event name
63
Y.Event.defineOutside = function (event, name) {
64
name = name || (event + 'outside');
68
on: function (node, sub, notifier) {
69
sub.handle = Y.one('doc').on(event, function(e) {
70
if (this.isOutside(node, e.target)) {
71
e.currentTarget = node;
77
detach: function (node, sub, notifier) {
81
delegate: function (node, sub, notifier, filter) {
82
sub.handle = Y.one('doc').delegate(event, function (e) {
83
if (this.isOutside(node, e.target)) {
89
isOutside: function (node, target) {
90
return target !== node && !target.ancestor(function (p) {
95
config.detachDelegate = config.detach;
97
Y.Event.define(name, config);
100
// Define outside events for some common native DOM events
101
Y.Array.each(nativeEvents, function (event) {
102
Y.Event.defineOutside(event);
106
}, '3.5.0' ,{requires:['event-synthetic']});