From: Coleman Watts Date: Sat, 13 Apr 2013 22:01:08 +0000 (-0700) Subject: Move settings to html-header region CRM-12339 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d759bd1039fca99f5b638adb57f76ef62ee64f6b;p=civicrm-core.git Move settings to html-header region CRM-12339 --- diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index e2f18b9a7f..5be786320e 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -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("\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); diff --git a/templates/CRM/common/scripts.tpl b/templates/CRM/common/scripts.tpl index 1d9dfb154b..61b25aedcc 100644 --- a/templates/CRM/common/scripts.tpl +++ b/templates/CRM/common/scripts.tpl @@ -42,13 +42,8 @@ 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}