0

I am working with WaveSurfer.js.
Is it possible to disable the region-click event for a region temporarily? I require this for a smoother workflow of my application.

Problem description:
I have a pop-up menu that gets displayed when a user clicks on a region, after creating it by using the enableDragSelection() method. However, if he clicks on a previously created region (while the pop-up menu is open for the current region), the previous region gets selected instead. This is why I want to disable the click event for previous regions in such cases. Basically keeping only the current region active for clicks. Any suggestions?

My approach:
What I have tried doing to solve this issue is using a flag variable.

if (flag==true){ wsRegions.on('region-clicked', (region) => { //region-clicked workflow }); } 

However, the flag variable does not seem to be able to stop the region-clicked event from getting triggered. What fixes are possible in such a case?

4
  • This above looks correct itself. Commented Apr 2, 2024 at 7:10
  • it did look correct to me too. however, i found a simple fix Commented Apr 2, 2024 at 7:17
  • wsRegions.on is not the triggering part, it is the part that binds the event handler. Once it has been registered, it stays registered. And rather than trying to change anything about that, you should probably just wrap your //region-clicked workflow into if (flag==true) { ... } - let the event fire, but make your event handler not do anything, if your flag condition is not fulfilled. Commented Apr 2, 2024 at 10:38
  • yes @CBroe, that's what i ended up doing. thanks everyone! Commented Apr 2, 2024 at 10:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.