Ejemplo n.º 1
0
 /**
  * Get strings from files.
  */
 public function testGet()
 {
     $basedir = $this->createExamples();
     $strings = new CRM_Core_Resources_Strings(new CRM_Utils_Cache_Arraycache(NULL));
     $this->assertEquals(array('Hello from Javascript'), $strings->get('example', "{$basedir}/hello.js", "text/javascript"));
     $this->assertEquals(array('Hello from HTML'), $strings->get('example', "{$basedir}/hello.html", "text/html"));
 }
Ejemplo n.º 2
0
 /**
  * Add a JavaScript file to the current page using <SCRIPT SRC>.
  *
  * @param string $ext
  *   extension name; use 'civicrm' for core.
  * @param string $file
  *   file path -- relative to the extension base dir.
  * @param int $weight
  *   relative weight within a given region.
  * @param string $region
  *   location within the file; 'html-header', 'page-header', 'page-footer'.
  * @param bool|string $translate
  *   Whether to load translated strings for this file. Use one of:
  *   - FALSE: Do not load translated strings.
  *   - TRUE: Load translated strings. Use the $ext's default domain.
  *   - string: Load translated strings. Use a specific domain.
  *
  * @return CRM_Core_Resources
  */
 public function addScriptFile($ext, $file, $weight = self::DEFAULT_WEIGHT, $region = self::DEFAULT_REGION, $translate = TRUE)
 {
     if ($translate) {
         $domain = $translate === TRUE ? $ext : $translate;
         $this->addString($this->strings->get($domain, $this->getPath($ext, $file), 'text/javascript'), $domain);
     }
     $this->resolveFileName($file, $ext);
     return $this->addScriptUrl($this->getUrl($ext, $file, TRUE), $weight, $region);
 }
Ejemplo n.º 3
0
 /**
  * Add a JavaScript file to the current page using <SCRIPT SRC>.
  *
  * @param string $ext
  *   extension name; use 'civicrm' for core.
  * @param string $file
  *   file path -- relative to the extension base dir.
  * @param int $weight
  *   relative weight within a given region.
  * @param string $region
  *   location within the file; 'html-header', 'page-header', 'page-footer'.
  * @param bool|string $translate
  *   Whether to load translated strings for this file. Use one of:
  *   - FALSE: Do not load translated strings.
  *   - TRUE: Load translated strings. Use the $ext's default domain.
  *   - string: Load translated strings. Use a specific domain.
  *
  * @return CRM_Core_Resources
  */
 public function addScriptFile($ext, $file, $weight = self::DEFAULT_WEIGHT, $region = self::DEFAULT_REGION, $translate = TRUE)
 {
     if ($translate) {
         $domain = $translate === TRUE ? $ext : $translate;
         $this->addString($this->strings->get($domain, $this->getPath($ext, $file), 'text/javascript'), $domain);
     }
     // Look for non-minified version if we are in debug mode
     if (CRM_Core_Config::singleton()->debug && strpos($file, '.min.js') !== FALSE) {
         $nonMiniFile = str_replace('.min.js', '.js', $file);
         if ($this->getPath($ext, $nonMiniFile)) {
             $file = $nonMiniFile;
         }
     }
     return $this->addScriptUrl($this->getUrl($ext, $file, TRUE), $weight, $region);
 }