Skip to content

Instantly share code, notes, and snippets.

@rvanzon
Last active March 22, 2019 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvanzon/0210cd5f9199b9a4346df68a7d4862e5 to your computer and use it in GitHub Desktop.
Save rvanzon/0210cd5f9199b9a4346df68a7d4862e5 to your computer and use it in GitHub Desktop.
Framework 7 backdrop remover and reopener when used with hot reload (HRM)
export default function ($f7, reopenPopup = true) {
if (module.hot) {
module.hot.addStatusHandler(status => {
if (status === 'idle') {
const activePopup = document.querySelector('.modal-in')
// next tick
setTimeout(() => {
// remove all popup backdrops if all popups are closed
if (!document.querySelectorAll('.modal-in').length) {
const popupBackdrop = document.querySelector('.popup-backdrop')
if (popupBackdrop) {
popupBackdrop.classList.remove('backdrop-in')
}
if (reopenPopup && activePopup && activePopup.id) {
$f7.popup.open(`#${activePopup.id}`, false)
}
}
}, 0)
}
})
}
}
@rvanzon
Copy link
Author

rvanzon commented Mar 15, 2019

usage:

import f7hotreload from '@/helpers/f7hotreload'

with Framework7 Vue

mounted () {
...
    f7hotreload(this.$f7)
...
}

with vanilla js (not tested):

var app = new Framework7({
  on: {
    init: function () {
      f7hotreload(this.$f7)
    }
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment