tripal_ds.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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('<div class="tripal_pane-fieldset-close_button">'+
  7. '<div id="tripal-pane-close-button" class="tripal-pane-button">'+
  8. '<i class="fa fa-window-close-o fa-lg"></i>'+
  9. '</div>'+
  10. '</div>'
  11. );
  12. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  13. });
  14. // Hide the pane when the close button is clicked
  15. $('.tripal_pane-fieldset-close_button').each(function (i) {
  16. $(this).css('float', 'right');
  17. $(this).css('cursor', 'pointer');
  18. $(this).css('margin', '0px 5px');
  19. $(this).click(function () {
  20. var fs = $(this).parents('div.tripal_pane');
  21. if($(fs).hasClass('showTripalPane')) {
  22. $(fs).removeClass('showTripalPane');
  23. $(fs).addClass('hideTripalPane');
  24. }
  25. else {
  26. $(fs).addClass('hideTripalPane');
  27. }
  28. });
  29. });
  30. // Move the tripal pane to the first position when its TOC item is clicked.
  31. $('.tripal_pane-toc-list-item-link').each(function (i) {
  32. $(this).click(function() {
  33. var id = '.tripal_pane-fieldset-' + $(this).attr('id');
  34. var prevObj = $(id).prev().attr('class');
  35. // If the user clicks on other TOC item, move its fieldset to the top
  36. $(id + ' fieldset').removeClass('collapsed');
  37. $(id + ' fieldset .fieldset-wrapper').show();
  38. console.log(prevObj);
  39. console.log(id);
  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 + ' fieldset').fadeTo(10, 0.3, function() {});
  43. $(id + ' fieldset').fadeTo(200, 1, function() {});
  44. }
  45. if ($(id).hasClass('hideTripalPane')) {
  46. $(id).removeClass('hideTripalPane');
  47. $(id).addClass('showTripalPane');
  48. }
  49. $(id + ' fieldset .fieldset-wrapper').hide();
  50. var obj = $(id).detach();
  51. $('.group-tripal-pane-content-top').after(obj);
  52. $(id + ' fieldset .fieldset-wrapper').show(300);
  53. return false;
  54. });
  55. });
  56. },
  57. };
  58. })(jQuery);