Javascript & CSS add to block add.php

Permalink
Hi,
I´m working on with quite complexed block.
In edit mode I can use javascript ("package") and CSS files like this:
public function on_page_view() {
      $html = Loader::helper('html');            
      $bv = new BlockView();
      $bv->setBlockObject($this->getBlockObject());
      $this->addHeaderItem($html->css($bv->getBlockURL() . '/blockedit/edit.css'));
      $this->addHeaderItem($html->javascript($bv->getBlockURL() . '/blockedit/edit.js'));
}

and I use also:
auto.js (for another parts of js not "package")

But I want to load edit.js and edit.css when I´m adding my first block in to the page.
In that time on_page_load() doesn´t load.

How can I do it?
Thanks.

OlliSavolainen
 
hutman replied on at Permalink Reply
hutman
If you call those things in the view function rather than the on_page_view function they should load when the block is added even when the page isn't refreshed.
OlliSavolainen replied on at Permalink Reply
OlliSavolainen
$controller->on_page_view()
This function is automatically run when the block is viewed from within a page. That makes it useful when with $controller->addHeaderItem(). This is the only way to inject items into the page's header from within a block.


So that´s not an option.
Is there any way how can I do this? Adding .js + .css file straight from edit.php or add.php
JohntheFish replied on at Permalink Reply
JohntheFish
In edit or add.php, you can write a script tag directly in the html for either linking a script file or inline javascript. You can also write style tags in the html. I don't know if link tags for css files work.

c5 also has a javascript function for lazy loading of header items (script of css). ccm_addHeaderItem() is defined in ccc.base.js

Ready events may not work reliably, so you will need to set up an alternate way to kick a script off if 'ready' is important to it and beware that timing and sequencing will be different between your development systems and assorted live systems.