I am writing a personal feed reader application using Bootstrap on the frontend, and wanted to add a Minimize / Maximize button.
This is my first JavaScript / JQuery code, so I don't know how to debug it other than printing variables in the Firefox Developer Console.
My page structure consists of panels. The user can expand or collapse the panel by clicking on the panel title. And a button to collapse or expand all panels.
My solution works most of the time, but I noticed one strange behavior. This is how I reproduce the problem:
- Open the page for the first time
- Expand one panel by clicking its title.
- Now the Collapse All button minimizes the open panel and expands the rest. It’s as if he is “switching” all the panels, rather than closing them.
- After this odd behavior, everything is fine, I can not reproduce the problem without refreshing the page. At each step, the variable
open_panel_count looks fine.
Here are the methods I use:
$(function() { open_panel_count = 0; function update_toggle_button() { $('#toggle-btn').text((open_panel_count ? "Collapse" : "Expand") + " All") } update_toggle_button();
Can someone tell me what I am doing wrong?
You can see the whole template at: https://github.com/utdemir/furby/blob/master/template.erb And get access to the demo version: http://p.cogunluklazararsiz.org/furby/
source share