Guest User

Untitled

a guest
Mar 13th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. /*
  2. Collapse Sectionfields for Symphony CMS
  3.  
  4. 1.1 Modified by Dale Tan <wtdtan@gmail.com>
  5. - Rewrote methods in private, anonymous function
  6. - Allows for "toggling" when in "collapsed" view
  7.  
  8. 1.0.1 Modified by Stephen Bau <stephen@domain7.com>
  9. - Remove jQuery for Symphony 2.0.3+. jQuery.noConflict mode. Fix margins CSS.
  10.  
  11. 1.0.0 Initial Release by Carsten de Vries <carsten@vrieswerk.nl>
  12.  
  13. */
  14.  
  15. (function($) {
  16.  
  17. var collapsedInfo = {
  18. opened: true,
  19. containers: {},
  20. showCollapsedHeader : function() {
  21. // Add a label with the title of the field to the header
  22. if ($('ol.orderable li').find('label.fieldtitle').length < 1) {
  23. $('ol.orderable li h4').each(
  24. function (index) {
  25. var fieldtitle = $('[name="fields[' + index + '][label]"]').val();
  26. $(this).after('<label class="meta fieldtitle">' + fieldtitle + '</label>');
  27. }
  28. );
  29. } else {
  30. $('ol.orderable li').find('label.fieldtitle').show();
  31. }
  32. },
  33. hideFieldTitle: function(el) {
  34. // Hide the label with the title of the field
  35. var $el = el || $('ol.orderable li');
  36. $el.find('label.fieldtitle').hide();
  37. },
  38. resetStatus: function() {
  39. // Reset all "opened" stati to false
  40. for (var p in collapsedInfo.containers) {
  41. collapsedInfo.containers[p].opened = false;
  42. }
  43. }
  44.  
  45. }
  46.  
  47. $(function() {
  48.  
  49. // Insert anchor that will act as toggle to collapse/uncollapse the sectionfields
  50. $('div.subsection h3').append('&nbsp;(<a title="Toggle collapse" class="togglecollapse">Collapse</a>)');
  51.  
  52. $('a.togglecollapse').toggle(
  53. function () {
  54. collapsedInfo.opened = false;
  55.  
  56. // Collapse fields that are just added
  57. $('ol.orderable li').css({'height' : 'auto'});
  58.  
  59. // Hide all children
  60. $('ol.orderable li').children().hide();
  61.  
  62. // Except the header of the field and remove bottom margin
  63. $('ol.orderable li h4').show().css('margin-bottom', '0');
  64.  
  65. collapsedInfo.showCollapsedHeader();
  66.  
  67. // Change the link text to represent the collapsed state
  68. $('a.togglecollapse').text('Uncollapse');
  69. }
  70. ,
  71. function () {
  72. collapsedInfo.opened = true;
  73.  
  74. // Show all fields
  75. $('ol.orderable li').children().show();
  76.  
  77. collapsedInfo.hideFieldTitle();
  78. collapsedInfo.resetStatus();
  79.  
  80. // Change the link text to represent the uncollapsed state
  81. $('a.togglecollapse').text('Collapse');
  82. }
  83. )
  84. $('ol.orderable.subsection li h4').dblclick(function(e) {
  85. var $this = $(this);
  86. var holder = $this.text().replace(/\s+\W+/i, '');
  87. var $par = $this.parent();
  88. if (!collapsedInfo.opened) {
  89. if (!collapsedInfo.containers[holder]) {
  90. collapsedInfo.containers[holder] = {};
  91. collapsedInfo.containers[holder].opened = false;
  92. }
  93.  
  94. if (!collapsedInfo.containers[holder].opened) {
  95. collapsedInfo.containers[holder].opened = true;
  96. $par.children().show();
  97. collapsedInfo.hideFieldTitle($par);
  98. } else {
  99. collapsedInfo.containers[holder].opened = false;
  100. $this.siblings().hide();
  101. collapsedInfo.showCollapsedHeader();
  102. }
  103. }
  104. });
  105. });
  106. })(jQuery);
Add Comment
Please, Sign In to add comment