Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

event-outside-debug.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('event-outside', function(Y) {
  9. /**
  10. * Outside events are synthetic DOM events that fire when a corresponding native
  11. * or synthetic DOM event occurs outside a bound element.
  12. *
  13. * The following outside events are pre-defined by this module:
  14. * <ul>
  15. * <li>blur</li>
  16. * <li>change</li>
  17. * <li>click</li>
  18. * <li>dblclick</li>
  19. * <li>focus</li>
  20. * <li>keydown</li>
  21. * <li>keypress</li>
  22. * <li>keyup</li>
  23. * <li>mousedown</li>
  24. * <li>mousemove</li>
  25. * <li>mouseout</li>
  26. * <li>mouseover</li>
  27. * <li>mouseup</li>
  28. * <li>select</li>
  29. * <li>submit</li>
  30. * </ul>
  31. *
  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>.
  38. *
  39. * @module event
  40. * @submodule event-outside
  41. */
  42. // Outside events are pre-defined for each of these native DOM events
  43. var nativeEvents = [
  44. 'blur', 'change', 'click', 'dblclick', 'focus', 'keydown', 'keypress',
  45. 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
  46. 'select', 'submit'
  47. ];
  48. /**
  49. * Defines a new outside event to correspond with the given DOM event.
  50. *
  51. * By default, the created synthetic event name will be the name of the event
  52. * with "outside" appended (e.g. "click" becomes "clickoutside"). If you want
  53. * a different name for the created Event, pass it as a second argument like so:
  54. * <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
  55. *
  56. * @method Y.Event.defineOutside
  57. * @param {String} event DOM event
  58. * @param {String} name (optional) custom outside event name
  59. * @static
  60. */
  61. Y.Event.defineOutside = function (event, name) {
  62. name = name || (event + 'outside');
  63. var config = {
  64. on: function (node, sub, notifier) {
  65. sub.handle = Y.one('doc').on(event, function(e) {
  66. if (this.isOutside(node, e.target)) {
  67. e.currentTarget = node;
  68. notifier.fire(e);
  69. }
  70. }, this);
  71. },
  72. detach: function (node, sub, notifier) {
  73. sub.handle.detach();
  74. },
  75. delegate: function (node, sub, notifier, filter) {
  76. sub.handle = Y.one('doc').delegate(event, function (e) {
  77. if (this.isOutside(node, e.target)) {
  78. notifier.fire(e);
  79. }
  80. }, filter, this);
  81. },
  82. isOutside: function (node, target) {
  83. return target !== node && !target.ancestor(function (p) {
  84. return p === node;
  85. });
  86. }
  87. };
  88. config.detachDelegate = config.detach;
  89. Y.Event.define(name, config);
  90. };
  91. // Define outside events for some common native DOM events
  92. Y.Array.each(nativeEvents, function (event) {
  93. Y.Event.defineOutside(event);
  94. });
  95. }, '3.4.0' ,{requires:['event-synthetic']});