And this works, but I just noticed a bug. Right after I try to add a new block the script is never loaded. So after adding the block it just hangs until I refresh the page.
Thanks in advance!
I use a really dirty solution at the moment, and don't have find a more elegant way to achieve this for now ...
As this is a problem that occurs only when editing, I added something like this to my header theme :
If someone have a best way, I will be glad to use it :)
The problem always arises with assets actually needed by a block's add and edit dialog. Concrete5 doesn't know what is going to be added a page until the actual add dialog is opened, but on_page_view is run by the rendering of the page, before the add/edit dialog is opened.
In view, this is no problem because the block is known to be on the page, the on_page_view event fires, and the assets are loaded.
During an edit, the same applies for on_page_view. You also get anything in auto.js loaded by the edit dialog.
During an add, on_page_view will not fire for that block because it doesn't exist until the add dialog is saved. However auto.js does get loaded with the add dialog.
1. Code the style, link or script elements into (usually the top of) the edit.php or add.php
2. Code similar into a method in the controller that is called back from the add/edit.php.
3. Write a state-aware loader caller in the block controller that it can call from on_block_load, add, edit and view. You need to be careful to call addHeaderItem when is still valid (ie , before headers are output) or use addFooterItem (no use for css).
5. Create a small auto.js that lazy loads the assets.