Temporarily disable jquery events connected through other functions / plugins

Is there a way to temporarily untie event handlers that were connected through a third party (i.e. I did not connect them myself) and then restore them?

For example, I use jQuery UI tabs.

I would like to disable all the default tab bindings until a certain point when I would like to bind them to the backup.

So for example:

  • The jquery user interface creates tabs and associates clicks (and other) events with each tab
  • my script then caches events for each tab and then unties them
  • my script will then reset the cached events for each tab one by one based on another variable

The untied events seem easy enough, but I'm not sure how to do this before I untie them, and then they can be restored again.

+4
source share
2 answers

Add your own handlers to the events that occurred before the plugins.

In your handlers, check if you want the plugin handlers to be executed, and if you do not use them, call event.stopImmediatePropagation .

+3
source

You can also push event handlers on top of the stack so that you have control, even if you cannot bind a handler to third-party handlers. https://github.com/private-face/jquery.bind-first

0
source

Source: https://habr.com/ru/post/1301738/


All Articles