Module: Allow to define additional Javascript files

refs #9702
This commit is contained in:
Johannes Meyer 2015-08-06 15:10:54 +02:00
parent 51aa22d429
commit 712d545f48
1 changed files with 38 additions and 1 deletions

View File

@ -169,6 +169,13 @@ class Module
*/
protected $cssFiles = array();
/**
* The Javascript files this module provides
*
* @var array
*/
protected $jsFiles = array();
/**
* Routes to add to the route chain
*
@ -445,6 +452,19 @@ class Module
return $files;
}
/**
* Provide an additional Javascript file
*
* @param string $path The path to the file, relative to self::$jsdir
*
* @return $this
*/
protected function provideJsFile($path)
{
$this->jsFiles[] = $this->jsdir . DIRECTORY_SEPARATOR . $path;
return $this;
}
/**
* Test if module provides js
*
@ -452,7 +472,12 @@ class Module
*/
public function hasJs()
{
return file_exists($this->getJsFilename());
if (file_exists($this->getJsFilename())) {
return true;
}
$this->launchConfigScript();
return !empty($this->jsFiles);
}
/**
@ -465,6 +490,18 @@ class Module
return $this->jsdir . '/module.js';
}
/**
* Return the Javascript files this module provides
*
* @return array
*/
public function getJsFiles()
{
$files = $this->jsFiles;
$files[] = $this->getJsFilename();
return $files;
}
/**
* Get the module name
*