Skip to content

Instantly share code, notes, and snippets.

@gillissm
Created February 23, 2016 01:58
Show Gist options
  • Save gillissm/054400cfcfdbf2200e0d to your computer and use it in GitHub Desktop.
Save gillissm/054400cfcfdbf2200e0d to your computer and use it in GitHub Desktop.
JS Snippet taken from Sitecore's Content Editor.js that supports the toggle of field sections
scContentEditor.prototype.toggleSection = function (id, sectionName) {
var el = document.getElementById(id);
if (el == null) {
return;
}
var nextSibling = el.nextSibling;
var visible = nextSibling.style.display == "none";
el.className = visible ? "scEditorSectionCaptionExpanded" : "scEditorSectionCaptionCollapsed";
jQuery(nextSibling).slideToggle(100);
var scSections = document.getElementById("scSections");
var value = scSections.value;
var p = value.toQueryParams();
p[sectionName] = visible ? "0" : "1";
scSections.value = Object.toQueryString(p);
var glyph = document.getElementById(id + "_Glyph");
if (glyph != null) {
var replace = (visible ? "/accordion_down" : "/accordion_up");
var replaceWith = (visible ? "/accordion_up" : "/accordion_down");
scForm.browser.setOuterHtml(glyph, scForm.browser.getOuterHtml(glyph).replace(replace, replaceWith));
}
if (this.onToggleSection) {
for (var k = 0; k < this.onToggleSection.length; k++) {
this.onToggleSection[k](id, sectionName);
}
}
}
//This function is taken from <Sitecore Web Root>\sitecore\shell\Applications\Content Manager\Content Editor.js.
//It is a single snippet showing how field sections are collapsed and expanded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment