this._inited = false;
this.menuIsOpen = false;
this.menu = $("#menu"); // Renamed from #nav because mmenu animations weren't working (probably due to some other script interference)
+ this.chaptersMenuHTML = '';
this.setNav();
}
if (icon == undefined) {
icon = true;
}
- var res = '<a href="' + href + '"';
+
+ var res = '';
+
if (id != undefined) {
res += ' id="' + id + '"';
}
res += ' ' + this.fluidbook.l10n.__(help);
}
- res += '</a>';
- return res;
+ // If there's no link defined, return the text an icon wrapped in a <span> (useful for MMenu)
+ if (href == '') {
+ return '<span' + res + '</span>';
+ } else {
+ return '<a href="' + href + '"' + res + '</a>';
+ }
},
setNav: function () {
if (this._inited == true) {
if (this.fluidbook.datas.chaptersPage != '') {
this.addLink('nav-sommaire', '#/page/' + this.fluidbook.datas.chaptersPage, 'chapters', 'chapters');
} else if (this.fluidbook.datas.chapters.length > 0) {
- this.addLink('nav-sommaire', '#/chapters', 'chapters', 'chapters');
+ // this.addLink('nav-sommaire', '#/chapters', 'chapters', 'chapters');
+ this.addLink('nav-sommaire', '', 'chapters', 'chapters');
+
+ // Get HTML for submenus (appended later)
+ this.chaptersMenuHTML = this.makeChapterLists(this.fluidbook.datas.chapters);
}
}
} else if (icon == 'friend') {
this.addLink('nav-archives', '#/archives', 'archives', '!' + this.fluidbook.datas.archivesLabel);
}
} else if (icon == 'help') {
- this.addLink('nav-help', '#', 'help', '');
+ this.addLink('nav-help', '#', 'help', 'help');
} else if (icon == 'zoom' && !this.fluidbook.support.isMobile) {
this.addLink('nav-zoomin', '#', 'zoomin', 'zoom in');
this.addLink('nav-zoomout', '#', 'zoomout', 'zoom out');
this.setAfterSearch();
}
this.setInterface();
+
+ if (this.chaptersMenuHTML != '') {
+ $('#chapters').parent().append(this.chaptersMenuHTML);
+ }
this.initMenu();
+
$(this.fluidbook).trigger('fluidbooknavready');
},
addMultilangLink: function (langs) {
if (q == '') {
return false;
}
+
window.location.hash = '/search/' + q;
+
+ if ($this.menuIsOpen) {
+ $this.menuAPI.close();
+ }
+
return false;
});
$("#q").keyup(searchHints);
return searchHTML;
},
setAfterSearch: function () {
- this.menu.find('ul').append('<div id="afterSearch"><div class="c">' + this.fluidbook.loader.getImage('data/images/' + this.fluidbook.datas.afterSearch) + '</div><div class="links">' + this.fluidbook.datas.links.aftersearch + '</div></div>');
+ this.menu.find('ul').append('<div id="afterSearch"><div class="c interface-search">' + getSpriteIcon('interface-search') + '</div><div class="links">' + this.fluidbook.datas.links.aftersearch + '</div></div>');
},
setInterface: function () {
$('#interface').append(res);
$(document).on('click', '#next', goNextPage);
$(document).on('click', '#previous', goPreviousPage);
+ },
+
+ // Build nested lists from chapters
+ makeChapterLists: function (chapters) {
+
+ var currentLevel = 0,
+ loopIndex = 0,
+ html = '<ul>';
+
+ // Loop through all chapters and build new ULs based on level/depth
+ chapters.forEach(function(chapter) {
+ loopIndex++;
+
+ if (chapter.level > currentLevel) {
+ html += '<ul>'; // Going one level deeper, start new list
+ // It's assumed that consecutive items will never be more than 1 level deeper than the previous
+ } else if (chapter.level < currentLevel) {
+ var levelDifference = currentLevel - chapter.level;
+ // We need to close a list for every level change (eg. jumping from level 5 back to level 2)
+ for (var i = 0; i < levelDifference; i++) {
+ html += '</li></ul></li>'; // Going one level higher, end previous list
+ }
+ } else {
+ if (loopIndex > 1) { // On the first run through, there's nothing to close
+ html += '</li>'; // Same level so close off current item
+ }
+ }
+
+ currentLevel = chapter.level;
+
+ var page = (this.fluidbook.virtualToPhysical(chapter.page));
+
+ html += '<li><a href="#/page/' + page + '">' + chapter.label + '</a>';
+ });
+
+ html += '</li></ul>';
+
+ return html;
}
};
\ No newline at end of file