tripal_ds.js 3.1 KB

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