tripal_core.d3js.api.inc

File

tripal_core/api/tripal_core.d3js.api.inc
View source
  1. <?php
  2. /**
  3. *
  4. */
  5. /**
  6. * Implements hook_libraries_info().
  7. */
  8. function tripal_core_libraries_info() {
  9. $libraries = array();
  10. $libraries['d3'] = array(
  11. 'name' => 'D3.js',
  12. 'vendor url' => 'http://d3js.org/',
  13. 'download url' => 'https://github.com/mbostock/d3',
  14. 'version arguments' => array(
  15. 'file' => 'd3.js',
  16. 'pattern' => '/\s*version: "(\d+\.\d+\.\d+)"/',
  17. ),
  18. 'files' => array(
  19. 'js' => array(
  20. 'd3.min.js',
  21. ),
  22. ),
  23. );
  24. return $libraries;
  25. }
  26. /**
  27. * Load D3.js releated javascripts for the current page.
  28. */
  29. function tripal_add_d3js() {
  30. $library = array('loaded' => FALSE);
  31. // First try to load d3.js using the libraries API.
  32. // This will work if the site admin has saved d3.js in their libraries folder.
  33. if (module_exists('libraries_api')) {
  34. $library = libraries_load('d3');
  35. }
  36. // If we were not able to load d3.js using the libraries API
  37. // then revert to loading the remote files manually.
  38. if (!isset($library['loaded']) OR !$library['loaded']) {
  39. // If SSL is being used then use a secure CDN for d3.js
  40. if (isset($_SERVER['HTTPS'])) {
  41. drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js');
  42. }
  43. else {
  44. drupal_add_js('http://d3js.org/d3.v3.min.js');
  45. }
  46. }
  47. }