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.

breakpoint.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6. exports.default = breakpoint;
  7. var _vue = require('vue');
  8. var _vue2 = _interopRequireDefault(_vue);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. var BREAKPOINTS_DEFAULTS = {
  11. thresholds: {
  12. xs: 600,
  13. sm: 960,
  14. md: 1280,
  15. lg: 1920
  16. },
  17. scrollbarWidth: 16
  18. };
  19. /**
  20. * Factory function for the breakpoint mixin.
  21. */
  22. function breakpoint() {
  23. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  24. if (!opts) {
  25. opts = {};
  26. }
  27. return _vue2.default.extend({
  28. data: function data() {
  29. return _extends({
  30. clientHeight: getClientHeight(),
  31. clientWidth: getClientWidth(),
  32. resizeTimeout: undefined
  33. }, BREAKPOINTS_DEFAULTS, opts);
  34. },
  35. computed: {
  36. breakpoint: function breakpoint() {
  37. var xs = this.clientWidth < this.thresholds.xs;
  38. var sm = this.clientWidth < this.thresholds.sm && !xs;
  39. var md = this.clientWidth < this.thresholds.md - this.scrollbarWidth && !(sm || xs);
  40. var lg = this.clientWidth < this.thresholds.lg - this.scrollbarWidth && !(md || sm || xs);
  41. var xl = this.clientWidth >= this.thresholds.lg - this.scrollbarWidth;
  42. var xsOnly = xs;
  43. var smOnly = sm;
  44. var smAndDown = (xs || sm) && !(md || lg || xl);
  45. var smAndUp = !xs && (sm || md || lg || xl);
  46. var mdOnly = md;
  47. var mdAndDown = (xs || sm || md) && !(lg || xl);
  48. var mdAndUp = !(xs || sm) && (md || lg || xl);
  49. var lgOnly = lg;
  50. var lgAndDown = (xs || sm || md || lg) && !xl;
  51. var lgAndUp = !(xs || sm || md) && (lg || xl);
  52. var xlOnly = xl;
  53. var name = void 0;
  54. switch (true) {
  55. case xs:
  56. name = 'xs';
  57. break;
  58. case sm:
  59. name = 'sm';
  60. break;
  61. case md:
  62. name = 'md';
  63. break;
  64. case lg:
  65. name = 'lg';
  66. break;
  67. default:
  68. name = 'xl';
  69. break;
  70. }
  71. return {
  72. // Definite breakpoint.
  73. xs: xs,
  74. sm: sm,
  75. md: md,
  76. lg: lg,
  77. xl: xl,
  78. // Useful e.g. to construct CSS class names dynamically.
  79. name: name,
  80. // Breakpoint ranges.
  81. xsOnly: xsOnly,
  82. smOnly: smOnly,
  83. smAndDown: smAndDown,
  84. smAndUp: smAndUp,
  85. mdOnly: mdOnly,
  86. mdAndDown: mdAndDown,
  87. mdAndUp: mdAndUp,
  88. lgOnly: lgOnly,
  89. lgAndDown: lgAndDown,
  90. lgAndUp: lgAndUp,
  91. xlOnly: xlOnly,
  92. // For custom breakpoint logic.
  93. width: this.clientWidth,
  94. height: this.clientHeight,
  95. thresholds: this.thresholds,
  96. scrollbarWidth: this.scrollbarWidth
  97. };
  98. }
  99. },
  100. created: function created() {
  101. if (typeof window === 'undefined') return;
  102. window.addEventListener('resize', this.onResize, { passive: true });
  103. },
  104. beforeDestroy: function beforeDestroy() {
  105. if (typeof window === 'undefined') return;
  106. window.removeEventListener('resize', this.onResize);
  107. },
  108. methods: {
  109. onResize: function onResize() {
  110. clearTimeout(this.resizeTimeout);
  111. // Added debounce to match what
  112. // v-resize used to do but was
  113. // removed due to a memory leak
  114. // https://github.com/vuetifyjs/vuetify/pull/2997
  115. this.resizeTimeout = window.setTimeout(this.setDimensions, 200);
  116. },
  117. setDimensions: function setDimensions() {
  118. this.clientHeight = getClientHeight();
  119. this.clientWidth = getClientWidth();
  120. }
  121. }
  122. });
  123. }
  124. // Cross-browser support as described in:
  125. // https://stackoverflow.com/questions/1248081
  126. function getClientWidth() {
  127. if (typeof document === 'undefined') return 0; // SSR
  128. return Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  129. }
  130. function getClientHeight() {
  131. if (typeof document === 'undefined') return 0; // SSR
  132. return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  133. }
  134. //# sourceMappingURL=breakpoint.js.map