summaryrefslogtreecommitdiff
path: root/tests/FunctionalTests/features/protected/pages/MyJavascriptLib.php
blob: 72e6061edcddf7b91f9065ef10b014a768654746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

class MyJavascriptLib extends TComponent
{
    private $_packages=array(); //keep track of all registrations

	private $_manager;

	protected function __construct(TPage $owner)
	{
		$this->_manager = $owner->getClientScript();
		$owner->onPreRenderComplete = array($this, 'registerScriptLoader');
	}

	public static function registerPackage(TControl $control, $name)
	{
		static $instance;
		if($instance===null)
			$instance=new self($control->getPage());
		$instance->_packages[$name]=true;
	}

	protected function registerScriptLoader()
	{
		$dir = dirname(__FILE__).'/myscripts'; //contains my javascript files
		$scripts = array_keys($this->_packages);
		$url = $this->_manager->registerJavascriptPackages($dir, $scripts);
		$this->_manager->registerScriptFile($url,$url);
	}
}

?>