CRM-13930 - fix jquery.menu namespace
[civicrm-core.git] / CRM / Core / Resources.php
index 4868cba49132936777476d4bac2b034a56e348a5..c9ead5ed52e3a5fdb2528a15e64d4df985b53783 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -201,7 +201,7 @@ class CRM_Core_Resources {
    * From javascript:
    * CRM.myNamespace.foo // "bar"
    *
-   * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/Javascript+Reference
+   * @see http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference
    *
    * @param $settings array
    * @return CRM_Core_Resources
@@ -428,40 +428,31 @@ class CRM_Core_Resources {
       $this->addedCoreResources[$region] = TRUE;
       $config = CRM_Core_Config::singleton();
 
-      // Add resources from jquery.files.tpl
-      $files = self::parseTemplate('CRM/common/jquery.files.tpl');
+      // Add resources from coreResourceList
+      $files = $this->coreResourceList();
       $jsWeight = -9999;
-      foreach ($files as $file => $type) {
-        if ($type == 'js') {
+      foreach ($files as $file) {
+        if (substr($file, -2) == 'js') {
           // Don't bother  looking for ts() calls in packages, there aren't any
           $translate = (substr($file, 0, 9) != 'packages/');
           $this->addScriptFile('civicrm', $file, $jsWeight++, $region, $translate);
         }
-        elseif ($type == 'css') {
+        else {
           $this->addStyleFile('civicrm', $file, -100, $region);
         }
       }
 
-      // Add localized calendar js
-      // Search for i18n file in order of specificity (try fr-CA, then fr)
-      list($lang) = explode('_', $config->lcMessages);
-      foreach (array(str_replace('_', '-', $config->lcMessages), $lang) as $language) {
-        $localizationFile = "packages/jquery/jquery-ui-1.9.0/development-bundle/ui/i18n/jquery.ui.datepicker-{$language}.js";
-        if ($this->getPath('civicrm', $localizationFile)) {
-          $this->addScriptFile('civicrm', $localizationFile, $jsWeight++, $region, FALSE);
-          break;
-        }
-      }
-
-      // Initialize CRM.url
+      // Initialize CRM.url and CRM.formatMoney
       $url = CRM_Utils_System::url('civicrm/example', 'placeholder', FALSE, NULL, FALSE);
-      $js = "CRM.url('init', '$url');";
+      $js = "CRM.url('init', '$url');\n";
+      $js .= "CRM.formatMoney('init', " . json_encode(CRM_Utils_Money::format(1234.56)) . ");";
       $this->addScript($js, $jsWeight++, $region);
 
       // Add global settings
       $settings = array(
         'userFramework' => $config->userFramework,
         'resourceBase' => $config->resourceBase,
+        'lcMessages' => $config->lcMessages,
       );
       $this->addSetting(array('config' => $settings));
 
@@ -489,11 +480,10 @@ class CRM_Core_Resources {
       // Load custom or core css
       $config = CRM_Core_Config::singleton();
       if (!empty($config->customCSSURL)) {
-        $this->addStyleUrl($config->customCSSURL, -99, $region);
+        $this->addStyleUrl($config->customCSSURL, 99, $region);
       }
-      else {
+      if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'disable_core_css')) {
         $this->addStyleFile('civicrm', 'css/civicrm.css', -99, $region);
-        $this->addStyleFile('civicrm', 'css/extras.css', -98, $region);
       }
     }
     return $this;
@@ -533,20 +523,70 @@ class CRM_Core_Resources {
   }
 
   /**
-   * Read resource files from a template
+   * List of core resources we add to every CiviCRM page
    *
-   * @param $tpl (str) template file name
-   * @return array: filename => filetype
+   * @return array
    */
-  static function parseTemplate($tpl) {
-    $items = array();
-    $template = CRM_Core_Smarty::singleton();
-    $buffer = $template->fetch($tpl);
-    $lines = preg_split('/\s+/', $buffer);
-    foreach ($lines as $line) {
-      $line = trim($line);
-      if ($line) {
-        $items[$line] = substr($line, 1 + strrpos($line, '.'));
+  public function coreResourceList() {
+    $config = CRM_Core_Config::singleton();
+    // Use minified files for production, uncompressed in debug mode
+    $min = $config->debug ? '' : '.min';
+
+    $items = array(
+      "packages/jquery/jquery-1.10.2.min.js",
+      "packages/jquery/jquery-migrate-1.2.1.js",
+      "packages/jquery/jquery-ui/js/jquery-ui-1.10.3.custom$min.js",
+      "packages/jquery/jquery-ui/css/black-tie/jquery-ui-1.10.3.custom$min.css",
+        
+      "packages/jquery/plugins/jquery.autocomplete.js",
+      "packages/jquery/css/jquery.autocomplete.css",
+
+      "packages/jquery/plugins/jquery.menu$min.js",
+      "packages/jquery/css/menu.css",
+
+      "packages/jquery/plugins/jquery.tableHeader.js",
+
+      "packages/jquery/plugins/jquery.textarearesizer.js",
+
+      "packages/jquery/plugins/jquery.form$min.js",
+
+      "packages/jquery/plugins/jquery.tokeninput$min.js",
+      "packages/jquery/css/token-input-facebook.css",
+
+      "packages/jquery/plugins/jquery.timeentry$min.js",
+
+      "packages/jquery/plugins/DataTables/media/css/demo_table_jui.css",
+      "packages/jquery/plugins/DataTables/media/js/jquery.dataTables$min.js",
+
+      "packages/jquery/plugins/jquery.FormNavigate$min.js",
+
+      "packages/jquery/plugins/jquery.validate$min.js",
+      "packages/jquery/plugins/jquery.ui.datepicker.validation.pack.js",
+
+      "packages/jquery/plugins/jquery.jeditable$min.js",
+
+      "packages/jquery/plugins/jquery.blockUI$min.js",
+
+      "packages/jquery/plugins/jquery.notify$min.js",
+
+      "js/rest.js",
+      "js/Common.js",
+
+      "js/jquery/jquery.crmeditable.js",
+      "js/jquery/jquery.crmasmselect.js",
+    );
+
+    // Add localized jQuery UI files
+    if ($config->lcMessages && $config->lcMessages != 'en_US') {
+      // Search for i18n file in order of specificity (try fr-CA, then fr)
+      list($lang) = explode('_', $config->lcMessages);
+      $path = "packages/jquery/jquery-ui/development-bundle/ui/" . ($min ? 'minified/' : '') . "i18n";
+      foreach (array(str_replace('_', '-', $config->lcMessages), $lang) as $language) {
+        $localizationFile = "$path/jquery.ui.datepicker-{$language}{$min}.js";
+        if ($this->getPath('civicrm', $localizationFile)) {
+          $items[] = $localizationFile;
+          break;
+        }
       }
     }
     return $items;