In D6 & D7 our header region seems to always render before drupal's scripts and styles,
whereas Joomla was the opposite. To fix this I have rolled-back the use of JFactory to add scripts,
and weighted our settings region so it will always be the first thing in the header.
CRM_Core_Region::instance('html-header')->add(array(
'callback' => function(&$snippet, &$html) use ($resources) {
$html .= "\n" . $resources->renderSetting();
- }
+ },
+ 'weight' => -100000,
));
$this->addedSettings = TRUE;
}
* @return string
*/
public function renderSetting() {
- $js = 'var CRM = cj.extend(true, ' . json_encode($this->getSettings()) . ', CRM || {});';
+ $js = 'var CRM = ' . json_encode($this->getSettings()) . ';';
return sprintf("<script type=\"text/javascript\">\n%s\n</script>\n", $js);
}
* @access public
*/
public function addScriptUrl($url, $region) {
- if ($region == 'html-header') {
- $document = JFactory::getDocument();
- $document->addScript($url);
- return TRUE;
- }
return FALSE;
}
* @access public
*/
public function addScript($code, $region) {
- if ($region == 'html-header') {
- $document = JFactory::getDocument();
- $document->addScriptDeclaration($code);
- return TRUE;
- }
return FALSE;
}