3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
13 * This class defines the `visual-bundle.js` asset, which combines `dc.js`,
14 * `d3.js`, and `crossfilter.js` into one asset -- and puts the services
15 * in the `CRM.visual` namespace.
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 class CRM_Utils_VisualBundle
{
24 public static function register() {
25 Civi
::resources()->addScriptUrl(Civi
::service('asset_manager')->getUrl('visual-bundle.js'));
26 Civi
::resources()->addStyleUrl(Civi
::service('asset_manager')->getUrl('visual-bundle.css'));
30 * Generate asset content (when accessed via AssetBuilder).
32 * @param \Civi\Core\Event\GenericHookEvent $event
33 * @see CRM_Utils_hook::buildAsset()
34 * @see \Civi\Core\AssetBuilder
36 public static function buildAssetJs($event) {
37 if ($event->asset
!== 'visual-bundle.js') {
42 'crossfilter' => '[civicrm.bower]/crossfilter-1.3.x/crossfilter.min.js',
43 'd3' => '[civicrm.bower]/d3-3.5.x/d3.min.js',
44 'dc' => '[civicrm.bower]/dc-2.1.x/dc.min.js',
48 $content[] = "(function(){";
49 $content[] = "var backups = {d3: window.d3, crossfilter: window.crossfilter, dc: window.dc}";
50 $content[] = 'window.CRM = window.CRM || {};';
51 $content[] = 'CRM.visual = CRM.visual || {};';
52 foreach ($files as $var => $file) {
53 $content[] = "// File: $file";
54 $content[] = file_get_contents(Civi
::paths()->getPath($file));
56 foreach ($files as $var => $file) {
57 $content[] = "CRM.visual.$var = $var;";
59 foreach ($files as $var => $file) {
60 $content[] = "window.$var = backups.$var;";
64 $event->mimeType
= 'application/javascript';
65 $event->content
= implode("\n", $content);
69 * Generate asset content (when accessed via AssetBuilder).
71 * @param \Civi\Core\Event\GenericHookEvent $event
72 * @see CRM_Utils_hook::buildAsset()
73 * @see \Civi\Core\AssetBuilder
75 public static function buildAssetCss($event) {
76 if ($event->asset
!== 'visual-bundle.css') {
81 '[civicrm.bower]/dc-2.1.x/dc.min.css',
85 foreach ($files as $file) {
86 $content[] = "// File: $file";
87 $content[] = file_get_contents(Civi
::paths()->getPath($file));
90 $event->mimeType
= 'text/css';
91 $event->content
= implode("\n", $content);