Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
15 | * @copyright CiviCRM LLC | |
6a488035 TO |
16 | * |
17 | */ | |
18 | ||
19 | /** | |
20 | * Add a Javascript file to a specific part of the page | |
21 | * | |
16b10e64 CW |
22 | * @param array $params |
23 | * Array with keys: | |
24 | * - ext: string, extension name. see CRM_Core_Resources::addScriptFile | |
25 | * - file: string, relative file path. see CRM_Core_Resources::addScriptFile | |
26 | * - url: string. see CRM_Core_Resources::addScriptURL | |
27 | * - weight: int; default: CRM_Core_Resources::DEFAULT_WEIGHT (0) | |
28 | * - region: string; default: CRM_Core_Resources::DEFAULT_REGION ('html-header') | |
29 | * @param CRM_Core_Smarty $smarty | |
77b97be7 EM |
30 | * |
31 | * @throws Exception | |
6a488035 TO |
32 | */ |
33 | function smarty_function_crmScript($params, &$smarty) { | |
be2fb01f | 34 | $params += [ |
64967ca1 CW |
35 | 'weight' => CRM_Core_Resources::DEFAULT_WEIGHT, |
36 | 'region' => CRM_Core_Resources::DEFAULT_REGION, | |
37 | 'ext' => 'civicrm', | |
be2fb01f | 38 | ]; |
6a488035 TO |
39 | |
40 | if (array_key_exists('file', $params)) { | |
64967ca1 | 41 | Civi::resources()->addScriptFile($params['ext'], $params['file'], $params['weight'], $params['region']); |
0db6c3e1 TO |
42 | } |
43 | elseif (array_key_exists('url', $params)) { | |
64967ca1 | 44 | Civi::resources()->addScriptUrl($params['url'], $params['weight'], $params['region']); |
0db6c3e1 TO |
45 | } |
46 | else { | |
6a488035 TO |
47 | CRM_Core_Error::debug_var('crmScript_params', $params); |
48 | throw new Exception("crmScript requires url or ext+file"); | |
49 | } | |
50 | } |