-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pfdt
committed
Dec 11, 2020
1 parent
fad9a05
commit 02c14a0
Showing
9 changed files
with
131 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Only run if ResizeObserver is supported. */ | ||
if ('ResizeObserver' in self) { | ||
/* Create a single ResizeObserver instance to handle all container elements. */ | ||
var ro = new ResizeObserver(function(entries) { | ||
/* Default breakpoints that should apply to all observed elements that don't define their own custom breakpoints. */ | ||
var $1em = parseFloat(getComputedStyle(document.body, null).fontSize); | ||
var defaultBreakpoints = {SM: 0, MD: $1em*18*2, LG: $1em*18*3, XL: $1em*18*4}; | ||
|
||
entries.forEach(function(entry) { | ||
/* If breakpoints are defined on the observed element, use them. Otherwise use the defaults. */ | ||
var breakpoints = entry.target.dataset.breakpoints ? | ||
JSON.parse(entry.target.dataset.breakpoints) : | ||
defaultBreakpoints; | ||
|
||
/* Update the matching breakpoints on the observed element. */ | ||
Object.keys(breakpoints).forEach(function(breakpoint) { | ||
var minWidth = breakpoints[breakpoint]; | ||
if (entry.contentRect.width >= minWidth) { | ||
entry.target.classList.add(breakpoint); | ||
} else { | ||
entry.target.classList.remove(breakpoint); | ||
} | ||
}); | ||
}); | ||
let event = new Event('ResizeObserverCompleted'); | ||
document.dispatchEvent(event); | ||
}); | ||
|
||
/* Find all elements with the `data-observe-resizes` attribute and start observing them. */ | ||
var elements = document.querySelectorAll('[data-observe-resizes]'); | ||
for (var element, i = 0; element = elements[i]; i++) { | ||
ro.observe(element); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.