halfmoonui / halfmoon

Halfmoon is a highly customizable, drop-in Bootstrap replacement. It comes with three built-in core themes, with dark mode support for all themes and components.
https://www.gethalfmoon.com
MIT License
3.01k stars 118 forks source link

Sticky Alerts (Unhandled Rejection (TypeError): Cannot read property 'insertBefore' of undefined) #114

Open timbogdanov opened 3 years ago

timbogdanov commented 3 years ago

Came accross an issue with sticky alerts, I believe this is the correct set up for them, I read and re-read the docs. When ever I try to run a sticky alert I get an error, see below.

image image image

stephannv commented 3 years ago

Maybe your HTML is being loaded after halfmoon initialization. halfmoon fill stickyAlerts on object initialization using:

{
  ...
  stickyAlerts: document.getElementsByClassName("sticky-alerts")[0],
  ...

Maybe this can solve, but without a code sandbox to try it, I'm not sure. On line 22:

  halfmoon.stickyAlerts = document.getElementsByClassName("sticky-alerts")[0]
  halfmoon.initStickyAlert(...)