$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();
}
* @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;
}
* @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);
}
/**
$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);
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>