tripal_ds.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $('.field-group-fieldset .fieldset-legend').each(function (i) {
  6. $(this).append('<div class="tripal_pane-fieldset-close_button"><div id="tripal-pane-close-button" class="tripal-pane-button">CLOSE</div></div>');
  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).parent().parent().parent().parent().parent();
  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. // Hightlight the fieldset instead of moving if it's already at the top
  34. if (prevObj.indexOf('group-tripal-pane-content-top') == 0) {
  35. $(id + ' fieldset').fadeTo(10, 0.3, function() {});
  36. $(id + ' fieldset').fadeTo(200, 1, function() {});
  37. }
  38. if ($(id).hasClass('hideTripalPane')) {
  39. $(id).removeClass('hideTripalPane');
  40. $(id).addClass('showTripalPane');
  41. }
  42. $(id + ' fieldset .fieldset-wrapper').hide();
  43. var obj = $(id).detach();
  44. $('.group-tripal-pane-content-top').after(obj);
  45. $(id + ' fieldset .fieldset-wrapper').show(300);
  46. return false;
  47. });
  48. });
  49. },
  50. };
  51. })(jQuery);