Skip to content

Commit

Permalink
Fix #1068 bugs where Bootstrap section menu doesn't always highlight …
Browse files Browse the repository at this point in the history
…correctly when some sections on page are hidden
  • Loading branch information
FayCross committed Jan 20, 2022
1 parent 57324ca commit 3b0f2b6
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions modules/site/parent_templates/site/common/js/application.js
Expand Up @@ -1325,16 +1325,29 @@ function x_navigateToPage(force, pageInfo) { // pageInfo = {type, ID}

// link to section
if (pages[i].childNodes.length > 0) {
// only check sections that aren't hidden
var sectionVisibleIndex = 0;

for (var j=0; j<pages[i].childNodes.length; j++) {
if (pages[i].childNodes[j].getAttribute && pages[i].childNodes[j].getAttribute("linkID") == pageInfo.ID) {
var destination = pages[i].getAttribute("linkID");
if (pages[i].getAttribute("customLinkID") != undefined && pages[i].getAttribute("customLinkID") != "") {
// page has customID so use this instead of auto-generated linkID
destination = pages[i].getAttribute("customLinkID");

var hideSection = checkIfHidden(pages[i].childNodes[j].getAttribute('hidePage'), pages[i].childNodes[j].getAttribute('hideOnDate'), pages[i].childNodes[j].getAttribute('hideOnTime'), pages[i].childNodes[j].getAttribute('hideUntilDate'), pages[i].childNodes[j].getAttribute('hideUntilTime'), 'Section');
if ($.isArray(hideSection)) {
hideSection = hideSection[0];
}

if (hideSection == false || authorSupport == true) {
if (pages[i].childNodes[j].getAttribute && pages[i].childNodes[j].getAttribute("linkID") == pageInfo.ID) {
var destination = pages[i].getAttribute("linkID");
if (pages[i].getAttribute("customLinkID") != undefined && pages[i].getAttribute("customLinkID") != "") {
// page has customID so use this instead of auto-generated linkID
destination = pages[i].getAttribute("customLinkID");
}
parseContent({ type: "id", id: destination }, sectionVisibleIndex+1);
found = true;
break;
}
parseContent({ type: "id", id: destination }, j+1);
found = true;
break;

sectionVisibleIndex++;
}
}
}
Expand Down Expand Up @@ -1519,8 +1532,10 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
$('#pageSubTitle').append(' <span class="alertMsg">' + (languageData.find("password")[0] != undefined && languageData.find("password")[0].getAttribute('pageSupport') != null ? languageData.find("password")[0].getAttribute('pageSupport') : 'In live projects, an access code must be entered to view this page') + ': ' + pswds + '</span>');
}

var sectionVisibleIndex = 0;

//create the sections
page.find('section').each( function(index, value){
page.find('section').each( function(sectionIndex, value){

// work out whether the section is hidden or not - can be simply hidden or hidden between specific dates/times
var hideSection = checkIfHidden($(this).attr('hidePage'), $(this).attr('hideOnDate'), $(this).attr('hideOnTime'), $(this).attr('hideUntilDate'), $(this).attr('hideUntilTime'), 'Section');
Expand All @@ -1530,8 +1545,6 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
}

if (hideSection == false || authorSupport == true) {

var sectionIndex = index;

//expand mainContent if section menu hidden and expand option is true
if (page.attr('sectionMenu') == 'true' && page.attr('expandMain') == 'true') {
Expand All @@ -1555,7 +1568,7 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
tocName.find('[style*="background-color"]').css('background-color', 'transparent');
}

var $link = $('<li' + (index==0?' class="active"':'') +'><a href="#' + pageHash + 'section' + (index+1) + '"></a></li>').appendTo('#toc');
var $link = $('<li' + (sectionVisibleIndex==0?' class="active"':'') +'><a href="#' + pageHash + 'section' + (sectionVisibleIndex+1) + '"></a></li>').appendTo('#toc');
$link.find('a').append(tocName);
}

Expand All @@ -1565,8 +1578,7 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
subHeadings = ($(this).attr('menu') != 'menu' && $(this).attr('menu') != 'neither') ? '<h1>' + $(this).attr('name') + '</h1>' : '';

var pageHeader = subHeadings + extraTitle + links != '' ? '<div class="page-header">' + subHeadings + extraTitle + links + '</div>' : '';

var section = $('<section id="' + pageHash + 'section' + (index+1) + '">' + pageHeader + '</section>');
var section = $('<section id="' + pageHash + 'section' + (sectionVisibleIndex+1) + '">' + pageHeader + '</section>');

var pswds = [];
if ($.trim($(this).attr('password')).length > 0) {
Expand All @@ -1580,13 +1592,15 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
}

if (pswds.length > 0) {
passwordSection(this, section, sectionIndex, index, page, pageHash, pageIndex, pswds);
passwordSection(this, section, sectionVisibleIndex, page, pageHash, pageIndex, pswds);
} else {
loadSection(this, section, sectionIndex, index, page, pageHash, pageIndex);
loadSection(this, section, sectionVisibleIndex, page, pageHash, pageIndex);
}

//add the section to the document
$('#mainContent').append(section);

sectionVisibleIndex++;
}
});

Expand Down Expand Up @@ -1614,7 +1628,7 @@ function loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAloneP
afterLoadPage(sectionNum, contentNum, pageIndex, standAlonePage);
}

function loadSection(thisSection, section, sectionIndex, index, page, pageHash, pageIndex, pswds) {
function loadSection(thisSection, section, sectionIndex, page, pageHash, pageIndex, pswds) {

if (authorSupport == true && $(thisSection).attr('passwordPass') == 'true') {
if (section.find('.sectionSubLinks').length > 0) {
Expand All @@ -1640,12 +1654,12 @@ function loadSection(thisSection, section, sectionIndex, index, page, pageHash,
}

var tempLink = validPages.indexOf(pageIndex) != -1 ? 'page' + (validPages.indexOf(pageIndex)+1) : (page.attr("customLinkID") != "" && page.attr("customLinkID") != undefined ? page.attr("customLinkID") : page.attr('linkID'));
var $link = $('<span class="subLink"> ' + (section.find('.sectionSubLinks .subLink').length > 0 && section.find('.sectionSubLinks').hasClass('hlist') ? '| ' : '') + '<a href="#' + tempLink + 'section' + (index+1) + 'content' + (itemIndex+1) + '"></a> </span>').appendTo(section.find('.sectionSubLinks'));
var $link = $('<span class="subLink"> ' + (section.find('.sectionSubLinks .subLink').length > 0 && section.find('.sectionSubLinks').hasClass('hlist') ? '| ' : '') + '<a href="#' + tempLink + 'section' + (sectionIndex+1) + 'content' + (itemIndex+1) + '"></a> </span>').appendTo(section.find('.sectionSubLinks'));
$link.find('a').append(subLinkName);

}

section.append( '<h2 id="' + pageHash + 'section' + (index+1) + 'content' + (itemIndex+1) + '">' + $(this).attr('name') + '</h2>');
section.append( '<h2 id="' + pageHash + 'section' + (sectionIndex+1) + 'content' + (itemIndex+1) + '">' + $(this).attr('name') + '</h2>');
}

if (this.nodeName == 'text'){
Expand Down Expand Up @@ -1877,19 +1891,23 @@ function passwordPage(page, pageHash, sectionNum, contentNum, pageIndex, standAl
}

} else {
loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAlonePage);
if (authorSupport == true) {
loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAlonePage, pswds);
} else {
loadPage(page, pageHash, sectionNum, contentNum, pageIndex, standAlonePage);
}
}
}

function passwordSection(thisSection, $section, sectionIndex, index, page, pageHash, pageIndex, pswds) {
function passwordSection(thisSection, $section, sectionIndex, page, pageHash, pageIndex, pswds) {

if ($(thisSection).attr('passwordPass') != 'true') {

if (authorSupport == true) {

$(thisSection).attr('passwordPass', true);

loadSection(thisSection, $section, sectionIndex, index, page, pageHash, pageIndex, pswds);
loadSection(thisSection, $section, sectionIndex, page, pageHash, pageIndex, pswds);

} else {

Expand All @@ -1909,7 +1927,7 @@ function passwordSection(thisSection, $section, sectionIndex, index, page, pageH
$(thisSection).attr('passwordPass', true);
$section.find('.pswdBlock').remove();
$section.find('.sectionSubLinks').show();
loadSection(thisSection, $section, sectionIndex, index, page, pageHash, pageIndex);
loadSection(thisSection, $section, sectionIndex, page, pageHash, pageIndex);
updateContent($section);

} else {
Expand All @@ -1927,7 +1945,7 @@ function passwordSection(thisSection, $section, sectionIndex, index, page, pageH
}

} else {
loadSection(thisSection, $section, sectionIndex, index, page, pageHash, pageIndex);
loadSection(thisSection, $section, sectionIndex, page, pageHash, pageIndex);
}
}

Expand Down

0 comments on commit 3b0f2b6

Please sign in to comment.