Whenever we have Accordion/Tab component in author mode,
placeholder in each tab would not be aligned properly as the tabs are not active. So
it confuses the author and difficult to edit the content inside each tab.
To set the visibility of the parent wrapper DIV of each
parsys, setting it as hidden is not a solution. If we do so it only hides
exact DIV, but other parsys artifacts would still be improperly aligned.
Therefore, we need to hide each CQ parsys artifacts when these are not active.
Therefore, we need to hide each CQ parsys artifacts when these are not active.
Use the below JavaScript spinet to fix this issue.
Steps:
1.
In Accordion.jsp , pass parsys path to JS function by
<div
class="panel">
<div class="panel-heading" role="tab"
id="heading${i}">
Tab Title
</div>
<div id="faq${i}" class="panel-collapse collapse
${in}" role="tabpanel" aria-labelledby="heading${i}" data-component-id="<%=
currentNode.getPath() %>/accord${i}">
<div class="panel-body">
<cq:include path="accord${i}"
resourceType="foundation/components/parsys"/> </div>
</div>
2. In JS script, hide all parsys when page
loads
<script>
$(window).load(function(){
var
elems = $('.panel-collapse.collapse:not(.in)');
$.each(elems,function(){
var classNames =
$(this).attr('class');
var component =
$(this).attr('data-component-id'); //Parsys Path
var parsysComp =
CQ.WCM.getEditable(component);
if (parsysComp)
{
parsysComp.hide();
}
});
});
Above JS function,
hides all parsys when page loads so all the parsys would disappear except for the active tab which has CSS class "in".
3. Hides the parsys when tabs are not active.
$('#accordion').on('hide.bs.collapse',
function (e) {
var component =
$(e.target).attr('data-component-id');
var parsysComp =
CQ.WCM.getEditable(component);
if (parsysComp)
{
parsysComp.hide();
}
});
4. Shows the
parsys when tabs are active.
$('#accordion').on('show.bs.collapse',
function (e) {
var component =
$(e.target).attr('data-component-id');
var parsysComp =
CQ.WCM.getEditable(component);
if (parsysComp)
{
parsysComp.show();
}
});
</script>
Final Screen:
This all sounds fantastic and is exactly what I need, but I can't seem to figure out how to reference "CQ.WCM.getEditable" in my JS script. I'm getting a "CQ is not defined" error. I'm referencing this in a Sightly JS-Use script. What am I missing?
ReplyDeleteHi Matt,
DeleteI used this script in JSP and i didnt try for Sightly so as of now please try any any solutions from here..http://stackoverflow.com/questions/28736116/uncaught-referenceerror-cq-is-not-defined.
Hi,
ReplyDeleteIs there any css for this to show and hide the Parsys ....
Thanks,
Pavan
Hi,
DeleteTwitter Bootstrap CSS is only used for accordion function and JS used to hide/show the parsys..
Thanks,
Naveen