Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

click-outside.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function closeConditional() {
  6. return false;
  7. }
  8. function directive(e, el, binding) {
  9. // Args may not always be supplied
  10. binding.args = binding.args || {};
  11. // If no closeConditional was supplied assign a default
  12. var isActive = binding.args.closeConditional || closeConditional;
  13. // The include element callbacks below can be expensive
  14. // so we should avoid calling them when we're not active.
  15. // Explicitly check for false to allow fallback compatibility
  16. // with non-toggleable components
  17. if (!e || isActive(e) === false) return;
  18. // If click was triggered programmaticaly (domEl.click()) then
  19. // it shouldn't be treated as click-outside
  20. // Chrome/Firefox support isTrusted property
  21. // IE/Edge support pointerType property (empty if not triggered
  22. // by pointing device)
  23. if ('isTrusted' in e && !e.isTrusted || 'pointerType' in e && !e.pointerType) return;
  24. // Check if additional elements were passed to be included in check
  25. // (click must be outside all included elements, if any)
  26. var elements = (binding.args.include || function () {
  27. return [];
  28. })();
  29. // Add the root element for the component this directive was defined on
  30. elements.push(el);
  31. // Check if it's a click outside our elements, and then if our callback returns true.
  32. // Non-toggleable components should take action in their callback and return falsy.
  33. // Toggleable can return true if it wants to deactivate.
  34. // Note that, because we're in the capture phase, this callback will occur before
  35. // the bubbling click event on any outside elements.
  36. !elements.some(function (el) {
  37. return el.contains(e.target);
  38. }) && setTimeout(function () {
  39. isActive(e) && binding.value && binding.value(e);
  40. }, 0);
  41. }
  42. exports.default = {
  43. // [data-app] may not be found
  44. // if using bind, inserted makes
  45. // sure that the root element is
  46. // available, iOS does not support
  47. // clicks on body
  48. inserted: function inserted(el, binding) {
  49. var onClick = function onClick(e) {
  50. return directive(e, el, binding);
  51. };
  52. // iOS does not recognize click events on document
  53. // or body, this is the entire purpose of the v-app
  54. // component and [data-app], stop removing this
  55. var app = document.querySelector('[data-app]') || document.body; // This is only for unit tests
  56. app.addEventListener('click', onClick, true);
  57. el._clickOutside = onClick;
  58. },
  59. unbind: function unbind(el) {
  60. if (!el._clickOutside) return;
  61. var app = document.querySelector('[data-app]') || document.body; // This is only for unit tests
  62. app && app.removeEventListener('click', el._clickOutside, true);
  63. delete el._clickOutside;
  64. }
  65. };
  66. //# sourceMappingURL=click-outside.js.map