Collapsible Panels

The script below adds functionality to allow users to expand and collapse panels. Note that this feature can hide important information, such as form validations, which may confuse users. Please consider possible side effects and use it carefully.

  1. Add an image called caret-down-fill.svg like this one to the embedded files in your Application Explorer

  2. Add the CSS below into the stylesheet (if you don’t have a stylesheet in your Application Explorer, you need to enable it in the Application Properties)

.collapsible .panel {
  position:relative;
}
.noTitle .panel {
  padding-top: 30px;
}
.panel-heading {
  padding-left:25px;
}
.collapser {
  background-image:url(/Content/EmbeddedFiles/caret-down-fill.svg);
  background-size:20px 20px;
  background-repeat:no-repeat;
  background-position:left top;
  height:20px;
  width:20px;
  cursor:pointer;
  position:absolute;
  top:10px;
  left:2px;
}
.col_closed {
  transform: rotate(180deg);
  background-position:right bottom;
}
.pan_closed .panel {
  height:45px;
  overflow:hidden;
}
  1. Add the class ‘collapsible’ to all panel that should have the feature. By default the panel will be open. To show it collapsed by default, add the class ‘pan_closed’ to the panel classes as well.

  2. Add a Javascript action into the page.load event with the following script:

$(".collapsible").each(function(){
  if($(this).hasClass("pan_closed")){
    $(this).find(".panel").prepend("<div class='collapser col_closed'></div>");
  } else {
    $(this).find(".panel").prepend("<div class='collapser'></div>");
  }
  console.log($(this).find(".panel-heading").length);
  if(!$(this).find(".panel-heading").length){
    $(this).addClass("noTitle");
  }
});
$(".collapser").click(function(){
  var parent = $(this).closest(".collapsible"); 
  if(parent.hasClass("pan_closed")){
    $(this).removeClass("col_closed");
    parent.removeClass("pan_closed");
  } else {
    $(this).addClass("col_closed");
    parent.addClass("pan_closed");
  }
});

vsi7g9fhsC

1 Like