Last active
          October 5, 2021 10:19 
        
      - 
      
- 
        Save wparad/6687a200ebbdfac301d56e37ef0729c6 to your computer and use it in GitHub Desktop. 
    Reactive javascript triggered by bootstrap media queries
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | const xs = document.createElement('div'); | |
| xs.setAttribute('class', 'd-inline d-sm-none'); | |
| const sm = document.createElement('div'); | |
| sm.setAttribute('class', 'd-none d-sm-inline d-md-none'); | |
| const md = document.createElement('div'); | |
| md.setAttribute('class', 'd-none d-md-inline d-lg-none'); | |
| const lg = document.createElement('div'); | |
| lg.setAttribute('class', 'd-none d-lg-inline d-xl-none'); | |
| const xl = document.createElement('div'); | |
| xl.setAttribute('class', 'd-none d-xl-inline'); | |
| const breakpoints = { xs, sm, md, lg, xl }; | |
| import Vue from 'vue'; | |
| const activeBreakpoints = Vue.observable(Object.keys(breakpoints).reduce((a, b) => { a[b] = false; return a; }, {})); | |
| function recalculate() { | |
| Object.keys(breakpoints).map(bp => { | |
| const style = window.getComputedStyle(breakpoints[bp]); | |
| Vue.set(activeBreakpoints, bp, !!style.display && style.display !== 'none'); | |
| }); | |
| } | |
| document.addEventListener('DOMContentLoaded', () => { | |
| try { | |
| const body = document.querySelector('body'); | |
| const div = document.createElement('div'); | |
| div.setAttribute('class', 'responsive-bootstrap-toolkit'); | |
| Object.values(breakpoints).forEach(bp => { div.appendChild(bp); }); | |
| body.appendChild(div); | |
| recalculate(); | |
| } catch (error) { /* */ } | |
| }); | |
| window.addEventListener('resize', recalculate); | |
| export default activeBreakpoints; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment