Move settings to html-header region CRM-12339
authorColeman Watts <coleman@civicrm.org>
Sat, 13 Apr 2013 22:01:08 +0000 (15:01 -0700)
committerColeman Watts <coleman@civicrm.org>
Sun, 14 Apr 2013 00:56:17 +0000 (17:56 -0700)
CRM/Core/Resources.php
templates/CRM/common/scripts.tpl

index e2f18b9a7fc3c6926d117c5355c9c7954954b836..5be786320e923461ef26de2fc0e83e6040ffe86a 100644 (file)
@@ -202,7 +202,7 @@ class CRM_Core_Resources {
     $this->settings = $this->mergeSettings($this->settings, $settings);
     if (!$this->addedSettings) {
       $resources = $this;
-      CRM_Core_Region::instance('settings')->add(array(
+      CRM_Core_Region::instance('html-header')->add(array(
         'callback' => function(&$snippet, &$html) use ($resources) {
           $html .= "\n" . $resources->renderSetting();
         }
@@ -219,7 +219,6 @@ class CRM_Core_Resources {
    * @return CRM_Core_Resources
    */
   public function addSettingsFactory($callable) {
-    $this->addSetting(array()); // ensure that 'settings' region is created, even if empty
     $this->settingsFactories[] = $callable;
     return $this;
   }
@@ -260,7 +259,8 @@ class CRM_Core_Resources {
    * @return string
    */
   public function renderSetting() {
-    return 'CRM = cj.extend(true, ' . json_encode($this->getSettings()) . ', CRM);';
+    $js = 'var CRM = cj.extend(true, ' . json_encode($this->getSettings()) . ', CRM || {});';
+    return sprintf("<script type=\"text/javascript\">\n%s\n</script>\n", $js);
   }
 
   /**
@@ -450,6 +450,13 @@ class CRM_Core_Resources {
       $js = "CRM.url('init', '$url');";
       $this->addScript($js, $jsWeight++, $region);
 
+      // Add global settings
+      $settings = array(
+        'userFramework' => json_encode($config->userFramework),
+        'resourceBase' => json_encode($config->resourceBase),
+      );
+      $this->addSetting(array('config' => $settings));
+
       // Give control of jQuery back to the CMS - this loads last
       $this->addScriptFile('civicrm', 'js/noconflict.js', 9999, $region, FALSE);
 
index 1d9dfb154b52dea78594e47f3445a52b4ef6e825..61b25aedccb6f5e55ef075c52f9391c852b3d8bc 100644 (file)
     strings: {},
     config: {{/literal}
       urlIsPublic: {if $urlIsPublic}true{else}false{/if},
-      userFramework: '{$config->userFramework}',
-      resourceBase: '{$config->resourceBase}',
       search_autocomplete_count: {crmSetting name="search_autocomplete_count" group="Search Preferences"}
     {literal}},
   }, CRM);
   {/literal}
-  {* Dynamically add server-side variables to the CRM object *}
-  {crmRegion name='settings'}
-  {/crmRegion}
 </script>