Skip to content

Instantly share code, notes, and snippets.

@dtan
Created October 5, 2009 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtan/201895 to your computer and use it in GitHub Desktop.
Save dtan/201895 to your computer and use it in GitHub Desktop.
/*
Collapse Sectionfields for Symphony CMS
1.1 Modified by Dale Tan <wtdtan@gmail.com>
- Rewrote methods in private, anonymous function
- Allows for "toggling" when in "collapsed" view
1.0.1 Modified by Stephen Bau <stephen@domain7.com>
- Remove jQuery for Symphony 2.0.3+. jQuery.noConflict mode. Fix margins CSS.
1.0.0 Initial Release by Carsten de Vries <carsten@vrieswerk.nl>
*/
(function($) {
var collapsedInfo = {
opened: true,
containers: {},
showCollapsedHeader : function() {
// Add a label with the title of the field to the header
if ($('ol.orderable li').find('label.fieldtitle').length < 1) {
$('ol.orderable li h4').each(
function (index) {
var fieldtitle = $('[name="fields[' + index + '][label]"]').val();
$(this).after('<label class="meta fieldtitle">' + fieldtitle + '</label>');
}
);
} else {
$('ol.orderable li').find('label.fieldtitle').show();
}
},
hideFieldTitle: function(el) {
// Hide the label with the title of the field
var $el = el || $('ol.orderable li');
$el.find('label.fieldtitle').hide();
},
resetStatus: function() {
// Reset all "opened" stati to false
for (var p in collapsedInfo.containers) {
collapsedInfo.containers[p].opened = false;
}
}
}
$(function() {
// Insert anchor that will act as toggle to collapse/uncollapse the sectionfields
$('div.subsection h3').append('&nbsp;(<a title="Toggle collapse" class="togglecollapse">Collapse</a>)');
$('a.togglecollapse').toggle(
function () {
collapsedInfo.opened = false;
// Collapse fields that are just added
$('ol.orderable li').css({'height' : 'auto'});
// Hide all children
$('ol.orderable li').children().hide();
// Except the header of the field and remove bottom margin
$('ol.orderable li h4').show().css('margin-bottom', '0');
collapsedInfo.showCollapsedHeader();
// Change the link text to represent the collapsed state
$('a.togglecollapse').text('Uncollapse');
}
,
function () {
collapsedInfo.opened = true;
// Show all fields
$('ol.orderable li').children().show();
collapsedInfo.hideFieldTitle();
collapsedInfo.resetStatus();
// Change the link text to represent the uncollapsed state
$('a.togglecollapse').text('Collapse');
}
)
$('ol.orderable.subsection li h4').dblclick(function(e) {
var $this = $(this);
var holder = $this.text().replace(/\s+\W+/i, '');
var $par = $this.parent();
if (!collapsedInfo.opened) {
if (!collapsedInfo.containers[holder]) {
collapsedInfo.containers[holder] = {};
collapsedInfo.containers[holder].opened = false;
}
if (!collapsedInfo.containers[holder].opened) {
collapsedInfo.containers[holder].opened = true;
$par.children().show();
collapsedInfo.hideFieldTitle($par);
} else {
collapsedInfo.containers[holder].opened = false;
$this.siblings().hide();
collapsedInfo.showCollapsedHeader();
}
}
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment