예제 #1
0
 /**
  * Wrapped CPath->getUrl as shortcut
  * @param type $key
  * @return type
  */
 public static function getUrl($key)
 {
     $path = CPath::getInstance();
     return $path->getUrl($key);
 }
예제 #2
0
 /**
  *
  * @param type $file
  */
 public static function addScript($file)
 {
     $assetsFile = CFactory::getPath('template://js/' . $file . '.js');
     if ($assetsFile) {
         $assetsDir = dirname($assetsFile);
     } else {
         /* This file is not located under template */
         $assetsFile = CFactory::getPath('assets://' . $file . '.js');
         if ($assetsFile) {
             $assetsDir = dirname($assetsFile);
         }
     }
     if (isset($assetsDir)) {
         /**
          * @todo Update CAssets
          */
         CFactory::attach($file . '.js', 'js', CPath::getInstance()->toUrl($assetsDir) . '/');
     }
 }
예제 #3
0
 /**
  * Init assets
  * @param type $name
  */
 public function _init($name)
 {
     $document = JFactory::getDocument();
     if ($document->getType() == 'html') {
         $document->addScriptDeclaration("joms_base_url = '" . JURI::root() . "';");
         $document->addScriptDeclaration("joms_assets_url = '" . JURI::root(true) . "/components/com_community/assets/';");
         // Legacy script relative path.
         $document->addScriptDeclaration("joms_script_url = '" . JURI::root(true) . "/components/com_community/assets/_release/js/';");
         // Language translation.
         $this->_loadLanguageTranslation();
     }
     // $this->attach('assets/joms.jquery-1.8.1.min.js', 'js');
     // $this->attach('assets/script-1.2.js', 'js');
     /* Assets init */
     $assetFile = CFactory::getPath('assets://default.json');
     if ($assetFile) {
         $assets = json_decode(file_get_contents($assetFile));
         foreach ($assets->core->css as $css) {
             $cssFile = CFactory::getPath('assets://' . $css . '.css');
             if ($cssFile) {
                 $this->attach(JFile::getName($css) . '.css', 'css', CPath::getInstance()->toUrl(dirname($cssFile)) . '/');
             }
         }
         foreach ($assets->core->js as $js) {
             $jsFile = CFactory::getPath('assets://' . $js . '.js');
             if ($jsFile) {
                 $this->attach(JFile::getName($js) . '.js', 'js', CPath::getInstance()->toUrl(dirname($jsFile)) . '/');
             }
         }
     }
     if (JFactory::getApplication()->isSite()) {
         /* Template init */
         $lang = JFactory::getLanguage();
         $templateFile = CFactory::getPath('template://assets/' . $name . '.json');
         if ($templateFile) {
             $assets = json_decode(file_get_contents($templateFile));
             /* Load template core files */
             foreach ($assets->core->css as $css) {
                 $cssFile = CFactory::getPath('template://assets/css/' . $css . '.css');
                 if ($cssFile) {
                     $this->attach(JFile::getName($css) . '.css', 'css', CPath::getInstance()->toUrl(dirname($cssFile)) . '/');
                 }
             }
             foreach ($assets->core->js as $js) {
                 $jsFile = CFactory::getPath('template://assets/js/' . $js . '.js');
                 if ($jsFile) {
                     $this->attach(JFile::getName($js) . '.js', 'js', CPath::getInstance()->toUrl(dirname($jsFile)) . '/');
                 }
             }
             /* Load template view files */
             $view = JFactory::getApplication()->input->getWord('view');
             if (isset($assets->views->{$view})) {
                 if (isset($assets->views->{$view}->css)) {
                     foreach ($assets->views->{$view}->css as $css) {
                         $cssFile = CFactory::getPath('template://assets/css/view.' . $css . '.css');
                         if ($cssFile) {
                             $this->attach('view.' . JFile::getName($css) . '.css', 'css', CPath::getInstance()->toUrl(dirname($cssFile)) . '/');
                         }
                     }
                 }
             }
             if (isset($assets->views->{$view})) {
                 if (isset($assets->views->{$view}->js)) {
                     foreach ($assets->views->{$view}->js as $js) {
                         $jsFile = CFactory::getPath('template://assets/js/view.' . $js . '.js');
                         if ($jsFile) {
                             $this->attach('view.' . JFile::getName($js) . '.js', 'js', CPath::getInstance()->toUrl(dirname($jsFile)) . '/');
                         }
                     }
                 }
             }
         }
     }
 }