Ejemplo n.º 1
0
 public static function renderLinks($inline = FALSE, $index = FALSE)
 {
     // build a var with the included css files
     $scriptincludes = self::$scriptPaths;
     self::$scriptPaths = array();
     // Get the session so we can track what assets are on the page
     $session = Session::instance();
     // If this is a full page load (ie not ajax) then there are no assest already on page
     if (!request::is_ajax()) {
         $session->delete('javascript.onPageAssets');
     }
     // Initialize the vars to track what has been added, and convience wrappers
     $onPageAssets = $session->get('javascript.onPageAssets', array());
     // sort the script include paths by weight
     ksort($scriptincludes);
     // loop all the script includes and determine what needs to go on this page
     // and in what order
     $includes = array();
     foreach ($scriptincludes as $scripts) {
         // make sure there are no duplicates in this array
         $scripts = array_unique($scripts);
         // make sure these css links are not already on the page
         // via ajax/parent or in another weight category (lowest weight wins)
         $scripts = array_diff($scripts, $onPageAssets);
         // add the filtered list to the array of assets to put on the page
         $includes = array_merge($includes, $scripts);
         // keep track of what we add to the pages
         $onPageAssets = array_merge($onPageAssets, $scripts);
     }
     // NOTICE: setting $session here causes segfault during ajax
     // made a hack to move this set outside the event .....
     Bluebox_Controller::$onPageAssets['js'] = $onPageAssets;
     //$session->set('javascript.onPageAssets', $onPageAssets);
     // create a list of links from the script includes
     $linkList = html::script($includes, $index);
     // are we displaying this inline or returning the string
     if ($inline) {
         echo $linkList;
     } else {
         return $linkList;
     }
 }