tripal_ds.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 event = $.Event('tripal_ds_pane_collapsed', {
  28. id: $(fs).attr('id')
  29. });
  30. $(id).trigget(event);
  31. });
  32. }
  33. });
  34. });
  35. // Move the tripal pane to the first position when its TOC item is clicked.
  36. $('.tripal_pane-toc-list-item-link').each(function (i) {
  37. $(this).click(function() {
  38. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  39. var prevObj = $(id).prev().attr('class');
  40. // Highlight the fieldset instead of moving if it's already at the top
  41. if (prevObj.indexOf('group-tripal-pane-content-top') == 0) {
  42. $(id).fadeTo(10, 0.3, function() {});
  43. $(id).fadeTo(200, 1, function() {});
  44. }
  45. if ($(id).hasClass('hideTripalPane')) {
  46. $(id).removeClass('hideTripalPane');
  47. $(id).addClass('showTripalPane');
  48. }
  49. $(id).hide();
  50. var obj = $(id).detach();
  51. $('.group-tripal-pane-content-top').after(obj);
  52. $(id).show(300, function () {
  53. // Trigger expansion event to allow the pane content
  54. // to react to the size change
  55. $(id).trigget($.Event('tripal_ds_pane_expanded', {id: id}));
  56. });
  57. return false;
  58. });
  59. });
  60. }
  61. };
  62. })(jQuery);