1

I am using jQuery to manage a keypress on my document and open a new window:

$(document).keypress(function(event){
    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13') {
        // Open a new window
    }
});

The problem is I have a jQuery accordion that I want to stay CLOSED until a user explicitly clicks on it. I managed to get the accordion to not open on the 'enter' keypress, but if another window opens in a new tab and becomes active, the accordion opens.

Problem is I have no idea to find out what even is getting fired on the accordion that allows it to open.

Is there a way to nuke all events on an element and then just add back the one that you want (in my case the mouse down or click)? Or to report which events are being handled by that element so that I could just try to unbind that one?

Nicros
  • 5,031
  • 12
  • 57
  • 101
  • `event.type` will give you the type... – gdoron Jan 29 '13 at 22:32
  • @gdoron How do I subscribe to a generic 'event' to see what the type is? – Nicros Jan 29 '13 at 22:34
  • @Nicros What do you mean by "generic 'event'"? – natlee75 Jan 29 '13 at 22:37
  • 2
    @Nicros Have you tried extending the accordion plugin to impose the restrictions you need? – natlee75 Jan 29 '13 at 22:38
  • @Roy tried $("#accordion).unbind(), the accordion still opens when the browser launches a new pane. – Nicros Jan 29 '13 at 22:39
  • If the Accordion code is being called after the new window is opening, you could try "event.stopPropagation()". – LNendza Jan 29 '13 at 22:40
  • @natlee75 gdoron's suggestion was to use event.type. But I have to subscribe to an event to get that event object- if I knew what to subscribe to I wouldn't need event.type. So I just meant to subscribe to ALL events on the element, then I could check event.type – Nicros Jan 29 '13 at 22:41
  • @natlee75 I haven't tried extending the accordion yet- was thinking there would be a very simple way to get this. – Nicros Jan 29 '13 at 22:42
  • @LNendza I played with that a bit but no luck so far... but I will spend more time with it and see if I can get it to work. – Nicros Jan 29 '13 at 22:43
  • When you set breakpoints, what's hitting first? – LNendza Jan 29 '13 at 22:47
  • @LNendza I can only see the breakpoint getting hit when the window gets opened- because I don't know what to subscribe to on the accordion to see when it's getting activated... – Nicros Jan 29 '13 at 22:59
  • I would look into the accordion code then and figure out where it's hitting. This may sound hackish, but have you tried to closing the accordion as soon as the new window is open? – LNendza Jan 29 '13 at 23:04
  • @LNendza Yep :( The window opens and even explicitly inactivating the accordion doesnt close it... but I have to say its hard to see exactly whats going on as breakpoints aren't hit, and there is now a new window covering the accordion (you are in a new tab anyways) – Nicros Jan 30 '13 at 00:30
  • Any chance you can post it to fiddle? – LNendza Jan 30 '13 at 03:46
  • So I found an alternative- I was having so much trouble I thought I would try something new- I gave the JQWidgets expander a go and it works great- none of the problems I had with the accordion. Feels like a bit of a cop out, but it does what I want... – Nicros Jan 30 '13 at 05:48

2 Answers2

2

Have you tried reading through the "active" portion in

http://api.jqueryui.com/accordion/#option-active ?

i.e Setting active to false will collapse all panels

Rahul
  • 391
  • 4
  • 17
  • I had- I initially set active to false because I want the panels collapsed by default. But that is an interesting point, the event is probably activating the accordion again... Ill try explicitly setting it inactive when the window opens – Nicros Jan 29 '13 at 22:47
  • yup, that's what I meant, it probably overrides the default somehow. Finding the root cause would be the best solution though – Rahul Jan 29 '13 at 22:48
  • 1
    As a followup, I haven't tried this but you should be able to see what is calling what by using : http://stackoverflow.com/questions/743876/list-all-javascript-events-wired-up-on-a-page-using-jquery – Rahul Jan 29 '13 at 23:07
2

I've found this scriptlet to be really helpful when trying to find out which events are attached to which dom elements. I might help you work out what's going on - Visual Event

levelnis
  • 7,665
  • 6
  • 37
  • 61