tripal_ds.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(
  7. '<div class="tripal_pane-fieldset-buttons">' +
  8. '<div id="tripal-pane-close-button" class="tripal-pane-button">' +
  9. '<i class="fa fa-window-close-o fa-lg"></i>' +
  10. '</div>' +
  11. '</div>'
  12. );
  13. });
  14. // Hide the pane when the close button is clicked
  15. $('#tripal-pane-close-button .fa-lg').each(function (i) {
  16. $(this).click(function () {
  17. var fs = $(this).parents('div.tripal_pane');
  18. if($(fs).hasClass('showTripalPane')) {
  19. $(fs).removeClass('showTripalPane');
  20. $(fs).hide('normal', function () {
  21. $(fs).addClass('hideTripalPane');
  22. });
  23. }
  24. else {
  25. $(fs).hide('normal', function () {
  26. $(fs).addClass('hideTripalPane');
  27. var id = $(fs).attr('id');
  28. var event = $.Event('tripal_ds_pane_collapsed', {
  29. id: id
  30. });
  31. $(id).trigger(event);
  32. });
  33. }
  34. });
  35. });
  36. // Move the tripal pane to the first position when its TOC item is clicked.
  37. $('.tripal_pane-toc-list-item-link').each(function (i) {
  38. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  39. if ($(id).length === 0) {
  40. $(this).parents('.views-row').first().remove();
  41. return;
  42. }
  43. $(this).click(function() {
  44. var prevObj = $(id).prev().attr('class');
  45. if(prevObj.length === 0) {
  46. return;
  47. }
  48. // Highlight the fieldset instead of moving if it's already at the top
  49. if (prevObj.indexOf('group-tripal-pane-content-top') == 0) {
  50. $(id).fadeTo(10, 0.3, function() {});
  51. $(id).fadeTo(200, 1, function() {});
  52. }
  53. if ($(id).hasClass('hideTripalPane')) {
  54. $(id).removeClass('hideTripalPane');
  55. $(id).addClass('showTripalPane');
  56. }
  57. $(id).hide();
  58. var obj = $(id).detach();
  59. $('.group-tripal-pane-content-top').after(obj);
  60. $(id).show(300, function () {
  61. // Trigger expansion event to allow the pane content
  62. // to react to the size change
  63. $(id).trigger($.Event('tripal_ds_pane_expanded', {id: id}));
  64. });
  65. return false;
  66. });
  67. });
  68. }
  69. };
  70. })(jQuery);