コード例 #1
0
ファイル: Element.php プロジェクト: nOoiser/SimplOnPHP
 public function getJS($method, $returnFormat = 'array', $compress = false)
 {
     $class = $this->getClass('-');
     // gets class' js file
     $a_js = ($local_js = JS::getPath("{$class}.js")) ? array($local_js) : array();
     // gets method's js file
     if ($local_js = JS::getPath("{$class}.{$method}.js")) {
         $a_js[] = $local_js;
     }
     // adds
     foreach ($this->dataAttributes() as $data) {
         foreach ($this->{'O' . $data}()->getJS($method) as $local_js) {
             if ($local_js) {
                 $a_js[] = $local_js;
             }
         }
     }
     sort($a_js);
     // includes libs
     $a_js = array_unique(array_merge(JS::getLibs(), $a_js));
     if ($compress) {
         // @todo: compress in one file and return the file path
     }
     // converts to remote paths
     $a_js = array_unique(array_map(array('\\SimplOn\\Main', 'localToRemotePath'), $a_js));
     switch ($returnFormat) {
         case 'html':
             $html_js = '';
             foreach ($a_js as $js) {
                 $html_js .= '<script type="text/javascript" src="' . $js . '"></script>' . "\n";
             }
             return $html_js;
         default:
         case 'array':
             return $a_js;
     }
 }