Strange block behavior with .js files

Permalink
Hi all!

A made an addon, which provides a block for Concrete5 5.6.x. I realized when I add this (or any other) block to an area first time, no javascript file (view.js or js/*.js) is included to the header scripts at all. I tried a tricky way with adding the (first time) missing javascripts thru the view.php with an inline javascript call (ccm_addHeaderItem) but somewhere in the view rendering process something filters my <script> tags out. :(

Is there any way to embed javascript files at the first time block addition?

 
hutman replied on at Permalink Reply
hutman
In your controller for the block you can do $this->addHeaderItem('<script></script>'); and it will be included when the block is viewed.
megant replied on at Permalink Reply
When you add a block, it will be added with an ajax call. If you don't have add.php in your block folder, then rendered content of the view.php will be the ajax response, which will be displayed in the proper block area. In this case addHeaderItem is useless, because there is no page header rendering at all. You need a page refresh at least to a complete page render (including page header render with the added items, eg missing javascript).