The `dropdown("toggle")` call doesn't seem necessary. I removed it (along with the calls on line 944 and 953) and everything worked fine.