in openmeetings-util/js/reflow-skin.js [221:355]
function initNavSidebar() {
var navSidebar = $('.navside-menu');
if (navSidebar.length == 0) {
return;
}
/**
* Gets the slug name of first <a> element in nav sidebar.
*/
function findFirstMenu() {
var href = $('.navside-menu a').first();
return href.attr('slug-name');
}
/**
* create a link
* @param {*} slugName
* @param {*} chapter
*/
function hashes(slugName, chapter) {
var hash = '#' + slugName;
if (chapter) {
hash += TOC_SEPARATOR + chapter;
}
return hash;
}
/**
* Split the fragement of url and returns an array containing following info:
* - the slugname of section
* - the chapter in the section
* @param {*} url the url the split
*/
function splitUrl(url) {
var index = url.indexOf(TOC_SEPARATOR, url.indexOf('#'));
if (index >= 0) {
return [url.substring(0, index), url.substring(index + TOC_SEPARATOR.length)];
}
return [url];
}
$window.bind('hashchange', function (evt) {
var originalEvt = evt.originalEvent;
// not load page if is identical
var oldURL;
var newURL;
var identicalPage = false;
// do nothing if same url
if (originalEvt) {
oldURL = originalEvt.oldURL;
newURL = originalEvt.newURL;
if (oldURL === newURL) {
return;
}
}
var item = null;
var hash = window.location.hash;
// set the first page in nav sidebar
if (window.location.hash == '') {
hash = hashes(findFirstMenu());
}
var chapter = '';
var splittedUrl = splitUrl(hash);
var section = splittedUrl[0].substring(1);
if (splittedUrl.length > 1) {
chapter = splittedUrl[1];
} else {
chapter = null;
}
// search the item in nav sidebar corresponding to section
if (section.endsWith('html')) {
item = $('.navside-menu a[href$="' + section + '"]');
} else {
item = $('.navside-menu a[slug-name$="' + section + '"]');
}
if (item.length) {
// expand the parent of item if it is sub-section menu.
var collapsible = item.parents('ul.collapse');
if (collapsible.length > 0) {
collapsible.collapse('show');
}
var slugName = item.attr('slug-name');
window.location.hash = hashes(slugName, chapter);
if (originalEvt) {
oldURL = splitUrl(originalEvt.oldURL);
newURL = splitUrl(originalEvt.newURL);
identicalPage = oldURL[0] === newURL[0];
}
if (identicalPage) {
return;
}
var href = item.attr('href').substring(1);
loadFrame(href, slugName);
}
});
// init fragment url part
var fragment = window.location.hash;
if (!fragment) {
var href = findFirstMenu();
window.location.hash = hashes(href);
} else {
// enforce load frame
$window.trigger('hashchange');
}
// select first menu item on expand
if ($body.hasClass('m-sidenav-select-first-on-select')) {
navSidebar.on('shown.bs.collapse', function (ev) {
var el = $(ev.target);
// break if have already active item
if (el.find('li.active').length > 0) {
return;
}
var href = el.find('li a').first();
window.location.hash = hashes(href.attr('slug-name'));
});
}
// prevent event on collapse clik.
navSidebar.find("a[href=\\#]").click(function (event) {
event.preventDefault();
});
}