| Conditions | 7 |
| Total Lines | 24 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import type { DirectiveBinding } from 'vue/types/options'; |
||
| 23 | inserted(el: HTMLElement, binding: ResponsiveDirectiveBinding) { |
||
| 24 | const timeout = typeof binding.value?.timeout === 'number' ? binding.value.timeout : 200; |
||
| 25 | |||
| 26 | const handleResize: ResizeObserverCallback = Shopware.Utils.throttle((entries: ResizeObserverEntry[]) => { |
||
| 27 | entries.forEach(entry => { |
||
| 28 | const elementSizeValues = entry.contentRect; |
||
| 29 | |||
| 30 | Object.entries(binding.value ?? {}).forEach(([breakpointClass, breakpointCallback]) => { |
||
| 31 | if (typeof breakpointCallback !== 'function') { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | |||
| 35 | if (breakpointCallback(elementSizeValues)) { |
||
| 36 | el.classList.add(breakpointClass); |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | el.classList.remove(breakpointClass); |
||
| 41 | }); |
||
| 42 | }); |
||
| 43 | }, timeout); |
||
| 44 | |||
| 45 | const observer = new ResizeObserver(handleResize); |
||
| 46 | observer.observe(el); |
||
| 47 | }, |
||
| 50 |