tripal_ds.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $(this).click(function() {
  39. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  40. var prevObj = $(id).prev().attr('class');
  41. // Highlight the fieldset instead of moving if it's already at the top
  42. if (prevObj.indexOf('group-tripal-pane-content-top') == 0) {
  43. $(id).fadeTo(10, 0.3, function() {});
  44. $(id).fadeTo(200, 1, function() {});
  45. }
  46. if ($(id).hasClass('hideTripalPane')) {
  47. $(id).removeClass('hideTripalPane');
  48. $(id).addClass('showTripalPane');
  49. }
  50. $(id).hide();
  51. var obj = $(id).detach();
  52. $('.group-tripal-pane-content-top').after(obj);
  53. $(id).show(300, function () {
  54. // Trigger expansion event to allow the pane content
  55. // to react to the size change
  56. $(id).trigger($.Event('tripal_ds_pane_expanded', {id: id}));
  57. });
  58. return false;
  59. });
  60. });
  61. }
  62. };
  63. })(jQuery);