3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 (c) 2004-2017
38 class CRM_Utils_VisualBundle
{
40 public static function register() {
41 Civi
::resources()->addScriptUrl(Civi
::service('asset_manager')->getUrl('visual-bundle.js'));
45 * Generate asset content (when accessed via AssetBuilder).
47 * @param \Civi\Core\Event\GenericHookEvent $event
48 * @see CRM_Utils_hook::buildAsset()
49 * @see \Civi\Core\AssetBuilder
51 public static function buildAsset($event) {
52 if ($event->asset
!== 'visual-bundle.js') {
57 'crossfilter' => '[civicrm.bower]/crossfilter-1.3.x/crossfilter.min.js',
58 'd3' => '[civicrm.bower]/d3-3.5.x/d3.min.js',
59 'dc' => '[civicrm.bower]/dc-2.1.x/dc.min.js',
63 $content[] = "(function(){";
64 $content[] = "var backups = {d3: window.d3, crossfilter: window.crossfilter, dc: window.dc}";
65 $content[] = 'window.CRM = window.CRM || {};';
66 $content[] = 'CRM.visual = CRM.visual || {};';
67 foreach ($files as $var => $file) {
68 $content[] = "// File: $file";
69 $content[] = file_get_contents(Civi
::paths()->getPath($file));
71 foreach ($files as $var => $file) {
72 $content[] = "CRM.visual.$var = $var;";
74 foreach ($files as $var => $file) {
75 $content[] = "window.$var = backups.$var;";
79 $event->mimeType
= 'application/javascript';
80 $event->content
= implode("\n", $content);