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.

overlayable.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. require('../../src/stylus/components/_overlay.styl');
  6. var _helpers = require('../util/helpers');
  7. var _vue = require('vue');
  8. var _vue2 = _interopRequireDefault(_vue);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /* @vue/component */
  11. // Utilities
  12. exports.default = _vue2.default.extend().extend({
  13. name: 'overlayable',
  14. props: {
  15. hideOverlay: Boolean
  16. },
  17. data: function data() {
  18. return {
  19. overlay: null,
  20. overlayOffset: 0,
  21. overlayTimeout: undefined,
  22. overlayTransitionDuration: 500 + 150 // transition + delay
  23. };
  24. },
  25. watch: {
  26. hideOverlay: function hideOverlay(value) {
  27. if (value) this.removeOverlay();else this.genOverlay();
  28. }
  29. },
  30. beforeDestroy: function beforeDestroy() {
  31. this.removeOverlay();
  32. },
  33. methods: {
  34. genOverlay: function genOverlay() {
  35. var _this = this;
  36. // If fn is called and timeout is active
  37. // or overlay already exists
  38. // cancel removal of overlay and re-add active
  39. if (!this.isActive || this.hideOverlay || this.isActive && this.overlayTimeout || this.overlay) {
  40. clearTimeout(this.overlayTimeout);
  41. return this.overlay && this.overlay.classList.add('v-overlay--active');
  42. }
  43. this.overlay = document.createElement('div');
  44. this.overlay.className = 'v-overlay';
  45. if (this.absolute) this.overlay.className += ' v-overlay--absolute';
  46. this.hideScroll();
  47. var parent = this.absolute ? this.$el.parentNode : document.querySelector('[data-app]');
  48. parent && parent.insertBefore(this.overlay, parent.firstChild);
  49. // eslint-disable-next-line no-unused-expressions
  50. this.overlay.clientHeight; // Force repaint
  51. requestAnimationFrame(function () {
  52. // https://github.com/vuetifyjs/vuetify/issues/4678
  53. if (!_this.overlay) return;
  54. _this.overlay.className += ' v-overlay--active';
  55. if (_this.activeZIndex !== undefined) {
  56. _this.overlay.style.zIndex = String(_this.activeZIndex - 1);
  57. }
  58. });
  59. return true;
  60. },
  61. /** removeOverlay(false) will not restore the scollbar afterwards */
  62. removeOverlay: function removeOverlay() {
  63. var _this2 = this;
  64. var showScroll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  65. if (!this.overlay) {
  66. return showScroll && this.showScroll();
  67. }
  68. this.overlay.classList.remove('v-overlay--active');
  69. this.overlayTimeout = window.setTimeout(function () {
  70. // IE11 Fix
  71. try {
  72. if (_this2.overlay && _this2.overlay.parentNode) {
  73. _this2.overlay.parentNode.removeChild(_this2.overlay);
  74. }
  75. _this2.overlay = null;
  76. showScroll && _this2.showScroll();
  77. } catch (e) {
  78. console.log(e);
  79. }
  80. clearTimeout(_this2.overlayTimeout);
  81. _this2.overlayTimeout = undefined;
  82. }, this.overlayTransitionDuration);
  83. },
  84. scrollListener: function scrollListener(e) {
  85. if (e.type === 'keydown') {
  86. if (['INPUT', 'TEXTAREA', 'SELECT'].includes(e.target.tagName) ||
  87. // https://github.com/vuetifyjs/vuetify/issues/4715
  88. e.target.isContentEditable) return;
  89. var up = [_helpers.keyCodes.up, _helpers.keyCodes.pageup];
  90. var down = [_helpers.keyCodes.down, _helpers.keyCodes.pagedown];
  91. if (up.includes(e.keyCode)) {
  92. e.deltaY = -1;
  93. } else if (down.includes(e.keyCode)) {
  94. e.deltaY = 1;
  95. } else {
  96. return;
  97. }
  98. }
  99. if (e.target === this.overlay || e.type !== 'keydown' && e.target === document.body || this.checkPath(e)) e.preventDefault();
  100. },
  101. hasScrollbar: function hasScrollbar(el) {
  102. if (!el || el.nodeType !== Node.ELEMENT_NODE) return false;
  103. var style = window.getComputedStyle(el);
  104. return ['auto', 'scroll'].includes(style.overflowY) && el.scrollHeight > el.clientHeight;
  105. },
  106. shouldScroll: function shouldScroll(el, delta) {
  107. if (el.scrollTop === 0 && delta < 0) return true;
  108. return el.scrollTop + el.clientHeight === el.scrollHeight && delta > 0;
  109. },
  110. isInside: function isInside(el, parent) {
  111. if (el === parent) {
  112. return true;
  113. } else if (el === null || el === document.body) {
  114. return false;
  115. } else {
  116. return this.isInside(el.parentNode, parent);
  117. }
  118. },
  119. checkPath: function checkPath(e) {
  120. var path = e.path || this.composedPath(e);
  121. var delta = e.deltaY;
  122. if (e.type === 'keydown' && path[0] === document.body) {
  123. var dialog = this.$refs.dialog;
  124. var selected = window.getSelection().anchorNode;
  125. if (dialog && this.hasScrollbar(dialog) && this.isInside(selected, dialog)) {
  126. return this.shouldScroll(dialog, delta);
  127. }
  128. return true;
  129. }
  130. for (var index = 0; index < path.length; index++) {
  131. var el = path[index];
  132. if (el === document) return true;
  133. if (el === document.documentElement) return true;
  134. if (el === this.$refs.content) return true;
  135. if (this.hasScrollbar(el)) return this.shouldScroll(el, delta);
  136. }
  137. return true;
  138. },
  139. /**
  140. * Polyfill for Event.prototype.composedPath
  141. */
  142. composedPath: function composedPath(e) {
  143. if (e.composedPath) return e.composedPath();
  144. var path = [];
  145. var el = e.target;
  146. while (el) {
  147. path.push(el);
  148. if (el.tagName === 'HTML') {
  149. path.push(document);
  150. path.push(window);
  151. return path;
  152. }
  153. el = el.parentElement;
  154. }
  155. return path;
  156. },
  157. hideScroll: function hideScroll() {
  158. if (this.$vuetify.breakpoint.smAndDown) {
  159. document.documentElement.classList.add('overflow-y-hidden');
  160. } else {
  161. (0, _helpers.addPassiveEventListener)(window, 'wheel', this.scrollListener, { passive: false });
  162. window.addEventListener('keydown', this.scrollListener);
  163. }
  164. },
  165. showScroll: function showScroll() {
  166. document.documentElement.classList.remove('overflow-y-hidden');
  167. window.removeEventListener('wheel', this.scrollListener);
  168. window.removeEventListener('keydown', this.scrollListener);
  169. }
  170. }
  171. });
  172. // Types
  173. // Styles
  174. //# sourceMappingURL=overlayable.js.map