drublic / css-modal

A modal built with pure CSS, enhanced with JavaScript
https://drublic.github.io/css-modal
MIT License
1.82k stars 211 forks source link

Event handlers not registering properly #210

Open jgadbois opened 8 years ago

jgadbois commented 8 years ago

I have a page with a bunch of modals on it which weren't loading content inside properly. After looking through modal.js I finally found that

# modal.js - init function
this.on('hashchange', global, modal.mainHandler);
this.on('load', global, modal.mainHandler);

were not firing. I added some debug statements to the .on and it appears that the event name, element, and callback are all correct.

The strange thing is it is fixed by just doing the following:

  $(global).on('load', modal.mainHandler);
  $(global).on('hashchange', modal.mainHandler);
  //this.on('hashchange', global, modal.mainHandler);
  //this.on('load', global, modal.mainHandler);

I can't figure out for the life of me why that would matter, since this.on seems to register them the exact same way.

Possibly it has to do with having a bunch of modals on the page?