1/* 2Copyright (c) 2010, Yahoo! Inc. All rights reserved. 3Code licensed under the BSD License: 4http://developer.yahoo.com/yui/license.html 5version: 3.4.0 6build: nightly 7*/ 8YUI.add('event-outside', function(Y) { 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 * @module event 41 * @submodule event-outside 42 */ 43 44// Outside events are pre-defined for each of these native DOM events 45var nativeEvents = [ 46 'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress', 47 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 48 'select', 'submit' 49 ]; 50 51/** 52 * Defines a new outside event to correspond with the given DOM event. 53 * 54 * By default, the created synthetic event name will be the name of the event 55 * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want 56 * a different name for the created Event, pass it as a second argument like so: 57 * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>. 58 * 59 * @method Y.Event.defineOutside 60 * @param {String} event DOM event 61 * @param {String} name (optional) custom outside event name 62 * @static 63 */ 64Y.Event.defineOutside = function (event, name) { 65 name = name || (event + 'outside'); 66 67 var config = { 68 69 on: function (node, sub, notifier) { 70 sub.handle = Y.one('doc').on(event, function(e) { 71 if (this.isOutside(node, e.target)) { 72 e.currentTarget = node; 73 notifier.fire(e); 74 } 75 }, this); 76 }, 77 78 detach: function (node, sub, notifier) { 79 sub.handle.detach(); 80 }, 81 82 delegate: function (node, sub, notifier, filter) { 83 sub.handle = Y.one('doc').delegate(event, function (e) { 84 if (this.isOutside(node, e.target)) { 85 notifier.fire(e); 86 } 87 }, filter, this); 88 }, 89 90 isOutside: function (node, target) { 91 return target !== node && !target.ancestor(function (p) { 92 return p === node; 93 }); 94 } 95 }; 96 config.detachDelegate = config.detach; 97 98 Y.Event.define(name, config); 99}; 100 101// Define outside events for some common native DOM events 102Y.Array.each(nativeEvents, function (event) { 103 Y.Event.defineOutside(event); 104}); 105 106 107}, '3.4.0' ,{requires:['event-synthetic']});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.