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.0KB

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