tripal_jbrowse.module 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @file
  4. * Core functions of this module.
  5. */
  6. /**
  7. * Implements hook_theme().
  8. */
  9. function tripal_jbrowse_theme($existing, $type, $theme, $path) {
  10. $items = array(
  11. 'node__jbrowse_instance' => array(
  12. // Don't specify the path in the template name.
  13. // Unless you have your template inside a directory within this module.
  14. 'template' => 'theme/node--jbrowse-instance',
  15. 'variables' => array('node' => (object)array()),
  16. ),
  17. );
  18. return $items;
  19. }
  20. /**
  21. * Implements node preprocess hook.
  22. */
  23. function tripal_jbrowse_preprocess_node(&$vars) {
  24. if ($vars['node']->type == 'jbrowse_instance') {
  25. $node = $vars['node'];
  26. // Determine the URL of the JBrowse based on the node properties
  27. $vars['url_prefix'] = $node->field_jburl['und'][0]['url'];
  28. $vars['location'] = (!empty($node->field_jbloc)) ? $node->field_jbloc['und'][0]['safe_value'] : '';
  29. $vars['tracks'] = (!empty($node->field_jbtracks)) ? $node->field_jbtracks['und'][0]['safe_value'] : '';
  30. $vars['url'] = $vars['url_prefix'] . "/?q=loc=" . $vars['location'] . "&tracks=" . $vars['tracks'];
  31. // Add inline JS for jbrowse to display an error.
  32. drupal_add_js('
  33. window.onerror=function(msg){
  34. if( document.body )
  35. document.body.setAttribute("JSError",msg);
  36. }
  37. if(window.process&&process.versions&&process.versions.electron) {
  38. window.electronRequire = require;
  39. delete window.require;
  40. }', 'inline');
  41. // Currently hardcoding the path just to get it working ;-)
  42. // My JBrowse is just unpacked in the files directory as you can see below.
  43. // @error failing to load chunks. Look into how to set root path for webpack?
  44. drupal_add_js('sites/default/files/JBrowse-1.14.1/dist/main.bundle.js');
  45. }
  46. }