Loading javascript for block edit screens

Permalink
I am currently loading a javascript file for the edit screen of my custom block:

$html = Loader::helper('html');
$this->addHeaderItem($html->css(BASE_URL.DIR_REL.'/packages/mtphr_blocks/css/metaboxer.css'));
$this->addHeaderItem($html->javascript(BASE_URL.DIR_REL.'/packages/mtphr_blocks/js/metaboxer.js'));


The issue I'm running into is that the click listeners I have setup in the .js file trigger multiple times after editing more than one block.
The first time I edit a block after page load everything works fine. But, if I edit a block and save, then edit another block, the clicks trigger twice... if I save and edit another block, then the click trigger's 3 times. So, it seems as though the js gets loaded multiple times without being removed, which then fires all the events of the multiple scripts.

Hopefully this makes sense. Is there a solution for this? Or a different way I should go about it?

joemc
 
JohntheFish replied on at Permalink Reply
JohntheFish
Maybe run 3 times so the event listener is added 3 time, but only loaded once? You can check using the network tab of the developer console to record script loading.