Dotclear


Ignore:
Timestamp:
12/20/12 23:59:54 (13 years ago)
Author:
JcDenis
Branch:
twig
Message:

Added javascript helpers to load only once scripts files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.admincontext.php

    r1089 r1091  
    2323     protected $globals = array(); 
    2424     protected $protected_globals = array(); 
     25     protected $memory = array(); 
    2526      
    2627     public function __construct($core) 
     
    126127          return array( 
    127128               '__'           => new Twig_Function_Function("__", array('is_safe' => array('html'))), 
    128                'debug_info' => new Twig_Function_Method($this, 'getDebugInfo', array('is_safe' => array('html'))) 
    129                //,'page_menu' => new Twig_Function_Method($this, 'pageMenu', array('is_safe' => array('html'))) 
     129               'debug_info' => new Twig_Function_Method($this, 'getDebugInfo', array('is_safe' => array('html'))), 
     130               'memorize' => new Twig_Function_Method($this, 'setMemory', array('is_safe' => array('html'))), 
     131               'memorized' => new Twig_Function_Method($this, 'getMemory', array('is_safe' => array('html'))) 
    130132          ); 
    131133     } 
     
    461463          return $di; 
    462464     } 
     465      
     466     /** 
     467     Add a value in a namespace memory 
     468      
     469     This help keep variable when recalling Twig macros 
     470      
     471     @param string $ns A namespace 
     472     @param string $str A value to memorize in this namespace 
     473     */ 
     474     public function setMemory($ns,$str) 
     475     { 
     476          if (!array_key_exists($ns,$this->memory) || !in_array($str,$this->memory[$ns])) { 
     477               $this->memory[$ns][] = $str; 
     478          } 
     479     } 
     480      
     481     /** 
     482     Check if a value is previously memorized in a namespace 
     483      
     484     @param string $ns A namespace 
     485     @param string $str A value to search in this namespace 
     486     @return array True if exists 
     487     */ 
     488     public function getMemory($ns,$str) 
     489     { 
     490          return array_key_exists($ns,$this->memory) && in_array($str,$this->memory[$ns]); 
     491     } 
    463492} 
    464493?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map