3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This class defines the `visual-bundle.js` asset, which combines `dc.js`,
30 * `d3.js`, and `crossfilter.js` into one asset -- and puts the services
31 * in the `CRM.visual` namespace.
34 * @copyright CiviCRM LLC https://civicrm.org/licensing
38 class CRM_Utils_VisualBundle
{
40 public static function register() {
41 Civi
::resources()->addScriptUrl(Civi
::service('asset_manager')->getUrl('visual-bundle.js'));
42 Civi
::resources()->addStyleUrl(Civi
::service('asset_manager')->getUrl('visual-bundle.css'));
46 * Generate asset content (when accessed via AssetBuilder).
48 * @param \Civi\Core\Event\GenericHookEvent $event
49 * @see CRM_Utils_hook::buildAsset()
50 * @see \Civi\Core\AssetBuilder
52 public static function buildAssetJs($event) {
53 if ($event->asset
!== 'visual-bundle.js') {
58 'crossfilter' => '[civicrm.bower]/crossfilter-1.3.x/crossfilter.min.js',
59 'd3' => '[civicrm.bower]/d3-3.5.x/d3.min.js',
60 'dc' => '[civicrm.bower]/dc-2.1.x/dc.min.js',
64 $content[] = "(function(){";
65 $content[] = "var backups = {d3: window.d3, crossfilter: window.crossfilter, dc: window.dc}";
66 $content[] = 'window.CRM = window.CRM || {};';
67 $content[] = 'CRM.visual = CRM.visual || {};';
68 foreach ($files as $var => $file) {
69 $content[] = "// File: $file";
70 $content[] = file_get_contents(Civi
::paths()->getPath($file));
72 foreach ($files as $var => $file) {
73 $content[] = "CRM.visual.$var = $var;";
75 foreach ($files as $var => $file) {
76 $content[] = "window.$var = backups.$var;";
80 $event->mimeType
= 'application/javascript';
81 $event->content
= implode("\n", $content);
85 * Generate asset content (when accessed via AssetBuilder).
87 * @param \Civi\Core\Event\GenericHookEvent $event
88 * @see CRM_Utils_hook::buildAsset()
89 * @see \Civi\Core\AssetBuilder
91 public static function buildAssetCss($event) {
92 if ($event->asset
!== 'visual-bundle.css') {
97 '[civicrm.bower]/dc-2.1.x/dc.min.css',
101 foreach ($files as $file) {
102 $content[] = "// File: $file";
103 $content[] = file_get_contents(Civi
::paths()->getPath($file));
106 $event->mimeType
= 'text/css';
107 $event->content
= implode("\n", $content);