X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FResources.php;h=d2e79f229eb4cb5824ec91efbafdeefa62cbc26a;hb=8e9bbf87cb1d16e59c14f213f7358ba30f0b045f;hp=66e94d2b067360f0063a65bb8d9066acdc595e25;hpb=8c2a3e92b3fca1fb7a03ce17ef5642bdd9b9602b;p=civicrm-core.git diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 66e94d2b06..d2e79f229e 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -1,7 +1,7 @@ addSetting(array('myNamespace' => array('foo' => 'bar'))); + * From javascript: + * CRM.myNamespace.foo // "bar" + * + * @see http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference + * * @param $settings array * @return CRM_Core_Resources */ @@ -214,7 +222,7 @@ class CRM_Core_Resources { } /** - * Add JavaScript variables to the global CRM object. + * Add JavaScript variables to the global CRM object via a callback function. * * @param $callable function * @return CRM_Core_Resources @@ -226,6 +234,9 @@ class CRM_Core_Resources { return $this; } + /** + * Helper fn for addSettingsFactory + */ public function getSettings() { $result = $this->settings; foreach ($this->settingsFactories as $callable) { @@ -253,12 +264,6 @@ class CRM_Core_Resources { * Helper fn for addSetting * Render JavaScript variables for the global CRM object. * - * Example: - * From the server: - * CRM_Core_Resources::singleton()->addSetting(array('myNamespace' => array('foo' => 'bar'))); - * From javascript: - * CRM.myNamespace.foo // "bar" - * * @return string */ public function renderSetting() { @@ -270,7 +275,7 @@ class CRM_Core_Resources { * Add translated string to the js CRM object. * It can then be retrived from the client-side ts() function * Variable substitutions can happen from client-side - * + * * Note: this function rarely needs to be called directly and is mostly for internal use. * @see CRM_Core_Resources::addScriptFile which automatically adds translated strings from js files * @@ -448,15 +453,17 @@ class CRM_Core_Resources { } } - // 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));