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?
wsRegions.onis 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 workflowintoif (flag==true) { ... }- let the event fire, but make your event handler not do anything, if your flag condition is not fulfilled.