tripal_ds.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function($) {
  2. Drupal.behaviors.tripal_ds = {
  3. attach: function (context, settings){
  4. // Add a close button for each pane except for the te_base
  5. $('div.tripal_pane').each(function (i) {
  6. $(this).prepend('<div class="tripal_pane-fieldset-close_button"><div id="tripal-pane-close-button" class="tripal-pane-button"><i class="fa fa-eye-slash fa-lg"></i></div></div><span class="download-icon"><i class="fa fa-download fa-lg" aria-hidden="true"></i></span>');
  7. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  8. });
  9. // Hide the pane when the close button is clicked
  10. $('.tripal_pane-fieldset-close_button').each(function (i) {
  11. $(this).css('float', 'right');
  12. $(this).css('cursor', 'pointer');
  13. $(this).css('margin', '0px 5px');
  14. $(this).click(function () {
  15. var fs = $(this).parents('div.tripal_pane');
  16. if($(fs).hasClass('showTripalPane')) {
  17. $(fs).removeClass('showTripalPane');
  18. $(fs).addClass('hideTripalPane');
  19. }
  20. else {
  21. $(fs).addClass('hideTripalPane');
  22. }
  23. });
  24. });
  25. // Move the tripal pane to the first position when its TOC item is clicked.
  26. $('.tripal_pane-toc-list-item-link').each(function (i) {
  27. $(this).click(function() {
  28. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  29. var prevObj = $(id).prev().attr('class');
  30. // If the user clicks on other TOC item, move its fieldset to the top
  31. $(id + ' fieldset').removeClass('collapsed');
  32. $(id + ' fieldset .fieldset-wrapper').show();
  33. console.log(prevObj);
  34. console.log(id);
  35. // Highlight the fieldset instead of moving if it's already at the top
  36. if (prevObj.indexOf('group-tripal-pane-content-top') == 0) {
  37. $(id + ' fieldset').fadeTo(10, 0.3, function() {});
  38. $(id + ' fieldset').fadeTo(200, 1, function() {});
  39. }
  40. if ($(id).hasClass('hideTripalPane')) {
  41. $(id).removeClass('hideTripalPane');
  42. $(id).addClass('showTripalPane');
  43. }
  44. $(id + ' fieldset .fieldset-wrapper').hide();
  45. var obj = $(id).detach();
  46. $('.group-tripal-pane-content-top').after(obj);
  47. $(id + ' fieldset .fieldset-wrapper').show(300);
  48. return false;
  49. });
  50. });
  51. },
  52. };
  53. })(jQuery);