tjcsl / ion

TJ Intranet 3
https://ion.tjhsst.edu
GNU General Public License v2.0
99 stars 91 forks source link

Activity selector toggle breaks after signup #230

Closed gengkev closed 9 years ago

gengkev commented 9 years ago

Hi! This is a bug I found while playing around with Ion on a mobile device. Here's how to reproduce it:

I have no idea how to set up the development version, and the code on ion.tjhsst.edu is obfuscated by PageSpeed, so I'm just guessing by the source. It looks like an event handler in initEighthResponsive() is responsible for expanding the toggle.

However, if initEighthResponsive() is called multiple times, the event handler will be attached twice, so clicking the toggle will open then immediately close the list of blocks. Indeed, after signing up for yet another activity, the toggle works again.

Why is initEighthResponsive() called multiple times? It appears that the only place it is called is in activityListView.render(). That function is called once when the page is loaded, but it is called again in eighth.signUp(), triggering the bug.

jwoglom commented 9 years ago

Thanks for catching this, and providing a great bug description! It seems to be occurring because the ActivityListView Backbone model is being re-rendered. The render() function of that model runs initEighthResponsive(), and was re-adding the event handlers.

For all of the other event handlers besides the switch toggle in that file, it doesn't matter if they're run multiple times. The switch button toggles a class, however, so it does break. It doesn't hurt to run the other re-initializations here so, per https://github.com/tjcsl/ion/commit/f84cb67e5fe3bcf28bf9c27309b361714ce8b99d, I've just added a check to ensure that there aren't more than one click handlers on .switch.

gengkev commented 9 years ago

Glad it helped! Maybe it would have been better to just make sure that all of initEighthResponsive() only ran once, but I haven't read the code carefully enough to make sure that's appropriate. Good luck with the Ion launch!