node--chado-generic.tpl.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // Purpose: This template provides a generic layout for all Tripal nodes (page)
  3. // get the template type of node (e.g. if type == chado_organism then template type == organism)
  4. $ttype = $variables['type'];
  5. $ttype = preg_replace('/chado_/','', $ttype);
  6. // get the template settings
  7. $template_settings = theme_get_setting('tripal');
  8. // toggle the sidebar if desired
  9. $no_sidebar = 0;
  10. if (is_array($template_settings['tripal_no_sidebar']) and
  11. $template_settings['tripal_no_sidebar'][$ttype]) {
  12. $no_sidebar = 1;
  13. }
  14. if ($teaser) {
  15. print theme('tripal_' . $ttype . '_teaser', $variables);
  16. }
  17. else { ?>
  18. <script type="text/javascript">
  19. (function ($) {
  20. Drupal.behaviors.<?php print $ttype?>Behavior = {
  21. attach: function (context, settings){ <?php
  22. // hide the resource sidbar if requested and strech the details section
  23. if ($no_sidebar) { ?>
  24. $(".tripal_toc").hide();
  25. $(".tripal_details").addClass("tripal_details_full");
  26. $(".tripal_details_full").removeClass("tripal_details"); <?php
  27. }
  28. // use default resource sidebar
  29. else { ?>
  30. $(".tripal-info-box").hide();
  31. // set the widths of the details and sidebar sections so they can work
  32. // seemlessly with any theme.
  33. total_width = $(".tripal_contents").width();
  34. details_width = (total_width * 0.70) - 52; // 52 == 20 x 2 left/right padding + 10 right margin + 2pt border
  35. toc_width = (total_width * 0.30) - 42; // 42 == 20 x 2 left/right padding + 2pt border
  36. // don't let sidebar get wider than 200px
  37. if (toc_width > 200) {
  38. details_width += toc_width - 200;
  39. toc_width = 200;
  40. }
  41. $('#tripal_<?php print $ttype?>_toc').width(toc_width);
  42. $('#tripal_<?php print $ttype?>_details').width(details_width);
  43. <?php
  44. } ?>
  45. // iterate through all of the info boxes and add their titles
  46. // to the table of contents
  47. $(".tripal-info-box-title").each(function(){
  48. var parent = $(this).parent();
  49. var id = $(parent).attr('id');
  50. var title = $(this).text();
  51. $('#tripal_<?php print $ttype?>_toc_list').append('<li><a href="#'+id+'" class="tripal_<?php print $ttype?>_toc_item">'+title+'</a></li>');
  52. });
  53. // when a title in the table of contents is clicked, then
  54. // show the corresponding item in the details box
  55. $(".tripal_<?php print $ttype?>_toc_item").click(function(){
  56. $(".tripal-info-box").hide();
  57. href = $(this).attr('href');
  58. if(href.match(/^#/)){
  59. //alert("correct: " + href);
  60. }
  61. else{
  62. tmp = href.replace(/^.*?#/, "#");
  63. href = tmp;
  64. //alert("fixed: " + href);
  65. }
  66. $(href).fadeIn('slow');
  67. // we want to make sure our table of contents and the details
  68. // box stay the same height
  69. $("#tripal_<?php print $ttype?>_toc").height($(href).parent().height());
  70. return false;
  71. });
  72. // we want the base details to show up when the page is first shown
  73. // unless we're using the feature browser then we want that page to show
  74. var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
  75. if(block == null){
  76. block = window.location.href.match(/[\?|\&]block=(.+)/)
  77. }
  78. if(block != null){
  79. $("#tripal_<?php print $ttype?>-"+block[1]+"-box").show();
  80. }
  81. else {
  82. $("#tripal_<?php print $ttype?>-base-box").show();
  83. }
  84. // make sure the sidebar and details sections are the same hieght
  85. base_height = $("#tripal_<?php print $ttype?>_details").height();
  86. toc_height = $("#tripal_<?php print $ttype?>_toc").height();
  87. if (toc_height > base_height) {
  88. $("#tripal_<?php print $ttype?>_details").height(toc_height);
  89. }
  90. else {
  91. $("#tripal_<?php print $ttype?>_toc").height(base_height);
  92. }
  93. }
  94. };
  95. })(jQuery);
  96. </script>
  97. <div id="tripal_<?php print $ttype?>_content" class="tripal_contents">
  98. <div id="tripal_<?php print $ttype?>_details" class="tripal_details">
  99. <!-- Resource Blocks CCK elements --> <?php
  100. if (property_exists($node, 'field_resource_titles')) {
  101. for ($i = 0; $i < count($node->field_resource_titles); $i++){
  102. if ($node->field_resource_titles[$i]['value']){ ?>
  103. <div id="tripal_<?php print $ttype?>-resource_<?php print $i?>-box" class="tripal_<?php print $ttype?>-info-box tripal-info-box">
  104. <div class="tripal_<?php print $ttype?>-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
  105. <?php print $node->field_resource_blocks[$i]['value']; ?>
  106. </div> <?php
  107. }
  108. }
  109. }?>
  110. <!-- Let modules add more content -->
  111. <?php
  112. foreach ($content as $key => $values) {
  113. if (array_key_exists('#value', $values)) {
  114. print $content[$key]['#value'];
  115. }
  116. }
  117. ?>
  118. </div>
  119. <!-- Table of contents -->
  120. <div id="tripal_<?php print $ttype?>_toc" class="tripal_toc">
  121. <div id="tripal_<?php print $ttype?>_toc_title" class="tripal_toc_title">Resources</i></div>
  122. <span id="tripal_<?php print $ttype?>_toc_desc" class="tripal_toc_desc"></span>
  123. <ul id="tripal_<?php print $ttype?>_toc_list" class="tripal_toc_list">
  124. <!-- Resource Links CCK elements --><?php
  125. if(property_exists($node, 'field_resource_links')) {
  126. for($i = 0; $i < count($node->field_resource_links); $i++){
  127. if($node->field_resource_links[$i]['value']){
  128. $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
  129. <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
  130. }
  131. }
  132. }
  133. ?>
  134. </ul>
  135. </div>
  136. </div>
  137. <?php
  138. } ?>