Changeset 20754 for events

Show
Ignore:
Timestamp:
10/05/08 11:07:41 (2 months ago)
Author:
kenji
Message:

Improve javascript output logic

Location:
events/phpframework/codeigniter/trunk/system/application
Files:
4 modified
1 copied

Legend:

Unmodified
Added
Removed
  • events/phpframework/codeigniter/trunk/system/application/config/routes.php

    r18585 r20754  
    4444$route['scaffolding_trigger'] = ""; 
    4545 
     46$route['js/(\S+)'] = "js/index/$1"; 
    4647 
    4748/* End of file routes.php */ 
  • events/phpframework/codeigniter/trunk/system/application/controllers/js.php

    r20297 r20754  
    99        } 
    1010 
    11         function index() 
     11        function index($file = 'default.js') 
    1212        { 
    13                 $this->load->helper('url'); 
    1413                $this->session->keep_flashdata('ticket'); 
    15  
    1614                $this->output->set_header('Content-Type: application/x-javascript; charset=UTF-8'); 
    1715 
    18                 $offset = 60 * 60 * 24; // 1 
     16                $offset = 60 * 60 * 24 * 5;     // 5 
    1917                $this->output->set_header('Expires: '.gmdate('D, d M Y H:i:s', time() + $offset).' GMT'); 
    20                  
    21                 $this->load->view('js/default'); 
     18 
     19                $full_path = APPPATH . 'views/js/' . $file; 
     20 
     21                if (file_exists($full_path)) 
     22                { 
     23                        $this->load->file($full_path); 
     24                } 
     25                else 
     26                { 
     27                        $this->load->helper('url'); 
     28                        $x = explode('.', $file); 
     29                        $ext = '.' . end($x); 
     30                        $file = str_replace($ext, '', $file); 
     31                        $this->load->view('js/' . $file); 
     32                } 
     33 
    2234        } 
    2335 
  • events/phpframework/codeigniter/trunk/system/application/helpers/MY_url_helper.php

    r20454 r20754  
    7575} 
    7676 
    77 function js($js = 'default') 
     77function js($js = 'default', $timestamp = TRUE) 
    7878{ 
    79         $file = APPPATH . 'views/js/' . $js . '.php'; 
    80         $mtime = filemtime($file); 
    81         $date = date('YmdHs', $mtime); 
     79        $x = explode('.', $js); 
     80        $ext = '.' . end($x); 
     81        $file = APPPATH . 'views/js/' . $js; 
     82 
     83        if ($ext != '.js') 
     84        { 
     85                $file = $file . '.php'; 
     86                $js = $js. '.js'; 
     87        } 
     88 
     89        $date = ''; 
    8290         
    83         $str = '<script type="text/javascript" src="' . site_url('js?' . $date) .'"></script>'; 
     91        if ($timestamp) 
     92        { 
     93                $mtime = filemtime($file); 
     94                $date = '?' . date('YmdHs', $mtime); 
     95        } 
     96 
     97        $str = '<script type="text/javascript" src="' . site_url('js/' . $js . $date) .'"></script>'; 
    8498        return $str; 
    8599} 
  • events/phpframework/codeigniter/trunk/system/application/views/layout.php

    r19226 r20754  
    1616<link href="<?=base_url()?>css/import.css" rel="stylesheet" type="text/css" media="all" /> 
    1717<!-- *** javascript *** --> 
    18 <script type="text/javascript" src="<?=base_url()?>js/jquery-1.2.6.min.js"></script> 
     18<?=js('jquery-1.2.6.min.js', FALSE) ?> 
    1919</head> 
    2020