Merge pull request #3572 from totten/master-casetype-tweaks
[civicrm-core.git] / CRM / Core / Resources.php
index 799d1ee2cafe2ceb7490369d6b42a5462cf326ef..706d80de9a923354ca92e37a7a4b643d5f9ffb21 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -37,7 +37,7 @@
  * should incorporte services for aggregation, minimization, etc.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -128,6 +128,8 @@ class CRM_Core_Resources {
    * Construct a resource manager
    *
    * @param CRM_Extension_Mapper $extMapper Map extension names to their base path or URLs.
+   * @param CRM_Utils_Cache_Interface $cache JS-localization cache
+   * @param string|null $cacheCodeKey Random code to append to resource URLs; changing the code forces clients to reload resources
    */
   public function __construct($extMapper, $cache, $cacheCodeKey = NULL) {
     $this->extMapper = $extMapper;
@@ -159,6 +161,13 @@ class CRM_Core_Resources {
     if ($translate) {
       $this->translateScript($ext, $file);
     }
+    // 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);
   }
 
@@ -232,7 +241,7 @@ class CRM_Core_Resources {
   /**
    * Add JavaScript variables to the global CRM object via a callback function.
    *
-   * @param $callable function
+   * @param callable $callable
    * @return CRM_Core_Resources
    */
   public function addSettingsFactory($callable) {
@@ -377,7 +386,7 @@ class CRM_Core_Resources {
    * @param $ext string, extension name; use 'civicrm' for core
    * @param $file string, file path -- relative to the extension base dir
    *
-   * @return (string|bool), full file path or FALSE if not found
+   * @return bool|string (string|bool), full file path or FALSE if not found
    */
   public function getPath($ext, $file) {
     // TODO consider caching results
@@ -393,6 +402,8 @@ class CRM_Core_Resources {
    *
    * @param $ext string, extension name; use 'civicrm' for core
    * @param $file string, file path -- relative to the extension base dir
+   * @param bool $addCacheCode
+   *
    * @return string, URL
    */
   public function getUrl($ext, $file = NULL, $addCacheCode = FALSE) {
@@ -406,10 +417,16 @@ class CRM_Core_Resources {
     return $this->extMapper->keyToUrl($ext) . '/' . $file;
   }
 
+  /**
+   * @return string
+   */
   public function getCacheCode() {
     return $this->cacheCode;
   }
 
+  /**
+   * @param $value
+   */
   public function setCacheCode($value) {
     $this->cacheCode = $value;
     if ($this->cacheCodeKey) {
@@ -428,6 +445,7 @@ class CRM_Core_Resources {
    * TODO: Separate the functional code (like addStyle/addScript) from the policy code
    * (like addCoreResources/addCoreStyles).
    *
+   * @param string $region
    * @return CRM_Core_Resources
    * @access public
    */
@@ -538,7 +556,7 @@ class CRM_Core_Resources {
    */
   function addLocalization(&$js) {
     $config = CRM_Core_Config::singleton();
-    
+
     // Localize select2 strings
     $contactSearch = json_encode($config->includeEmailInName ? ts('Start typing a name or email...') : ts('Start typing a name...'));
     $otherSearch = json_encode(ts('Enter search term...'));
@@ -563,13 +581,13 @@ class CRM_Core_Resources {
   public function coreResourceList() {
     $config = CRM_Core_Config::singleton();
     // Use minified files for production, uncompressed in debug mode
+    // Note, $this->addScriptFile would automatically search for the non-minified file in debug mode but this is probably faster
     $min = $config->debug ? '' : '.min';
 
     // Scripts needed by everyone, everywhere
     // FIXME: This is too long; list needs finer-grained segmentation
     $items = array(
       "packages/jquery/jquery-1.11.0$min.js",
-      "packages/jquery/jquery-migrate-1.2.1.js", // TODO: Remove before 4.5 release
       "packages/jquery/jquery-ui/js/jquery-ui-1.10.4.custom$min.js",
       "packages/jquery/jquery-ui/css/theme/jquery-ui-1.10.4.custom$min.css",
 
@@ -577,13 +595,9 @@ class CRM_Core_Resources {
 
       "packages/jquery/plugins/jquery.mousewheel$min.js",
 
-      "packages/jquery/plugins/select2/select2.js", // No mini until release of select2 3.4.6
+      "packages/jquery/plugins/select2/select2$min.js",
       "packages/jquery/plugins/select2/select2.css",
 
-      // TODO: Remove before 4.5 release
-      "packages/jquery/plugins/jquery.autocomplete.js",
-      "packages/jquery/css/jquery.autocomplete.css",
-
       "packages/jquery/plugins/jquery.tableHeader.js",
 
       "packages/jquery/plugins/jquery.textarearesizer.js",
@@ -593,8 +607,7 @@ class CRM_Core_Resources {
       "packages/jquery/plugins/jquery.timeentry$min.js",
 
       "packages/jquery/plugins/DataTables/media/js/jquery.dataTables$min.js",
-
-      "packages/jquery/plugins/jquery.FormNavigate$min.js",
+      "packages/jquery/plugins/DataTables/media/css/jquery.dataTables$min.css",
 
       "packages/jquery/plugins/jquery.validate$min.js",
       "packages/jquery/plugins/jquery.ui.datepicker.validation.pack.js",
@@ -611,10 +624,6 @@ class CRM_Core_Resources {
       $items[] = "packages/jquery/plugins/jquery.blockUI$min.js";
       $items[] = "packages/jquery/plugins/jquery.notify$min.js";
       $items[] = "js/jquery/jquery.crmeditable.js";
-
-      // TODO: tokeninput is deprecated in favor of select2 and will be removed soon
-      $items[] = "packages/jquery/plugins/jquery.tokeninput$min.js";
-      $items[] = "packages/jquery/css/token-input-facebook.css";
     }
 
     // Enable administrators to edit option lists in a dialog