}
FluidbookNav.prototype = {
- getIcon: function (name) {
- var src = 'data/images/' + name + '.';
- if (this.fluidbook.support.SVG) {
- src += 'svg';
- } else {
- src += 'png';
- }
- if (this._dimensions[name] == undefined) {
- return '';
- }
- return this.fluidbook.loader.getImage(src, this._dimensions[name][0], this._dimensions[name][1]);
+ initMenu: function () {
+ var $this = this;
+
+ this.menu.mmenu({
+
+ // Allow #anchor links to trigger correctly and close the menu
+ // Ref: https://github.com/FrDH/jQuery.mmenu/issues/687#issuecomment-279377172
+ onClick: {
+ preventDefault: function() {
+ $this.menuAPI.close();
+ }
+ },
+
+ "extensions": [
+ "pagedim-black"
+ ],
+ "offCanvas": {
+ "position": "right",
+ "zposition": "front"
+ },
+ "navbar": {
+ //add: false // Removes main title bars completely
+ title: "" // Hides the default "Menu" text
+ }
+ });
+
+ this.menuAPI = this.menu.data('mmenu');
+
+ // Bind API hooks (see http://mmenu.frebsite.nl/documentation/core/off-canvas.html#h4)
+ this.menuAPI.bind("open:finish", function () {
+ $('body').addClass('menu-open');
+ $this.menuIsOpen = true;
+
+ $('#q').focus();
+ });
+
+ this.menuAPI.bind("close:finish", function () {
+ $('body').removeClass('menu-open');
+ $this.menuIsOpen = false;
+ });
+
+
+ $(document).on('click', '#menuOpener', function (e) {
+ e.preventDefault();
+ $this.menuAPI.open();
+ });
+
+ // Close menu when a search result is clicked
+ $(document).on('click', '#menuSearchResults a', function (e) {
+ $this.menuAPI.close();
+ });
+
+ // Recalculate available size for menu search results
+ $(window).on('fluidbookresize', fluidbook.resizeSearchResults);
+
},
- addLink: function (name, href, id, help, before, c) {
- if ($("#nav").find('#' + id).length > 0) {
+ // getIcon: function (name) {
+ // var src = 'data/images/' + name + '.';
+ // if (this.fluidbook.support.SVG) {
+ // src += 'svg';
+ // } else {
+ // src += 'png';
+ // }
+ // if (this._dimensions[name] == undefined) {
+ // return '';
+ // }
+ // return this.fluidbook.loader.getImage(src, this._dimensions[name][0], this._dimensions[name][1]);
+ // },
+ addLink: function (name, href, id, title, help, before, c) {
+ if (this.menu.find('#' + id).length > 0) {
return;
}
- var l = '<li>' + this.getLink(name, href, id, title, help, c) + '</li>';
- var l = $(this.getLink(name, href, id, help, c));
++ var l = $(this.getLink(name, href, id, title, help, c)),
++ li = '<li>' + l[0].outerHTML + '</li>';
if (before == undefined) {
- this.menu.find('ul').append(l);
- $("#nav").append(l);
++ this.menu.find('ul').append(li);
} else {
- this.menu.find("ul #" + before).before(l);
- $("#nav #" + before).before(l);
++ this.menu.find("ul #" + before).before(li);
}
+ return l;
},
-
- getLink: function (name, href, id, help, className, icon) {
+ getLink: function (name, href, id, title, help, className, icon) {
if (icon == undefined) {
icon = true;
}
}
res += '>';
if (icon) {
- res += this.getIcon(name);
+ res += getSpriteIcon(name);
+ }
+
- if (help != undefined && help != '') {
++ if (title != undefined && title != '') {
+ res += ' ' + this.fluidbook.l10n.__(title);
+ }
+
+ // 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>';
}
- res += '</a>';
- return res;
},
setNav: function () {
if (this._inited == true) {
}
try {
if (homeURL != '') {
- this.addLink('nav-home', homeURL, 'home', 'home', 'home');
- link = this.addLink('nav-home', homeURL, 'home', 'home');
++ link = this.addLink('nav-home', homeURL, 'home', 'home', 'home');
}
} catch (err) {
return false;
})
} else if (icon == 'index') {
- this.addLink('interface-index', '#/index', 'index', 'overview', 'overview');
- link = this.addLink('nav-index', '#/index', 'index', 'overview');
++ link = this.addLink('interface-index', '#/index', 'index', 'overview', 'overview');
} else if (icon == 'chapters') {
if (this.fluidbook.datas.displayChaptersIcon) {
if (this.fluidbook.datas.chaptersPage != '') {
- this.addLink('interface-chapters', '#/page/' + this.fluidbook.datas.chaptersPage, 'chapters', 'chapters', 'chapters');
- link = this.addLink('nav-sommaire', '#/page/' + this.fluidbook.datas.chaptersPage, 'chapters', 'chapters');
++ link = this.addLink('interface-chapters', '#/page/' + this.fluidbook.datas.chaptersPage, 'chapters', 'chapters', 'chapters');
} else if (this.fluidbook.datas.chapters.length > 0) {
- link = this.addLink('nav-sommaire', '#/chapters', 'chapters', 'chapters');
+ // this.addLink('nav-sommaire', '#/chapters', 'chapters', 'chapters');
- this.addLink('interface-chapters', '', 'chapters', 'chapters', 'chapters');
++ link = this.addLink('interface-chapters', '', 'chapters', 'chapters', 'chapters');
+
+ // Get HTML for submenus (appended later)
+ this.chaptersMenuHTML = this.makeChapterLists(this.fluidbook.datas.chapters);
}
}
+
+ // Sharing icons - this may contain many different icons
} else if (icon == 'friend') {
- if (this.fluidbook.datas.share) {
- link = this.addLink('nav-friend', '#/share', 'share', 'share');
- $("#share").click(function () {
- if ($this.fluidbook.datas.phonegap != 'android') {
- return true;
- }
- $this.fluidbook.intentShare();
- return false;
- });
+ // if (this.fluidbook.datas.share) {
- // this.addLink('nav-friend', '#/share', 'share', 'share');
++ // link = this.addLink('nav-friend', '#/share', 'share', 'share');
+ // $("#share").click(function () {
+ // if ($this.fluidbook.datas.phonegap != 'android') {
+ // return true;
+ // }
+ // $this.fluidbook.intentShare();
+ // return false;
+ // });
+ // }
+
+ var shareLinks = {},
+ shareHTML = '';
+
+ if (this.fluidbook.datas.friend) {
+ shareLinks['email'] = 'E-mail';
+ }
+ if (this.fluidbook.datas.facebook) {
+ shareLinks['facebook'] = 'Facebook';
+ }
+ if (this.fluidbook.datas.twitter) {
+ shareLinks['twitter'] = 'Twitter';
+ }
+ if (this.fluidbook.datas.googleplus) {
+ shareLinks['googleplus'] = 'Google Plus';
}
+ if (this.fluidbook.datas.linkedin) {
+ shareLinks['linkedin'] = 'LinkedIn';
+ }
+ if (this.fluidbook.datas.viadeo) {
+ shareLinks['viadeo'] = 'Viadeo';
+ }
+
+ // Generate links
+ for (var shareType in shareLinks) {
+ if (shareLinks.hasOwnProperty(shareType)) { // Ensure we don't get inherited properties
+ shareHTML += '<a href="#" data-service="'+ shareType +'" class="share" title="'+ shareLinks[shareType] +'">';
+ shareHTML += '<img src="data/images/share-'+ shareType +'.svg" />';
+ shareHTML += '</a>';
+ }
+ }
+
+ // Append to menu
+ this.menu.find('ul').append('<li id="shareLinks"><div class="mm-nopanel share-icons">'+ shareHTML +'</div></li>');
+
+
} else if (icon == 'bookmark') {
if (this.fluidbook.datas.bookmark) {
- this.addLink('interface-bookmarks', '#/bookmark', 'bookmarks', 'bookmarks', 'bookmarks');
- link = this.addLink('nav-bookmark', '#/bookmark', 'bookmarks', 'bookmarks');
++ link = this.addLink('interface-bookmarks', '#/bookmark', 'bookmarks', 'bookmarks', 'bookmarks');
$("#bookmarks").click(function () {
if (!$this.fluidbook.bookmarks.hasBookmarkedPages()) {
var message = $this.fluidbook.l10n.__("you don't have any bookmarks");
}
});
}
- } else if (icon == 'pdf' || icon == 'print') {
- if ($("#print").length == 0 && (this.fluidbook.datas.print || this.fluidbook.datas.pdf)) {
- link = this.addLink('nav-print', '#', 'print', '!' + this.fluidbook.l10n.__('print') + ' | ' + this.fluidbook.l10n.__('download pdf'));
+ } else if (icon == 'pdf') {
+ if ($("#download").length == 0 && this.fluidbook.datas.pdf) {
- this.addLink('interface-download', '#', 'download', 'download', 'download');
++ link = this.addLink('interface-download', '#', 'download', 'download', 'download');
+ $("#download").on('click', function () {
+ $this.fluidbook.print();
+ return false;
+ });
+ }
+ } else if (icon == 'print') {
+ if ($("#print").length == 0 && this.fluidbook.datas.print) {
- this.addLink('interface-print', '#', 'print', 'print', 'print');
++ link = this.addLink('interface-print', '#', 'print', 'print', 'print');
$("#print").on('click', function () {
$this.fluidbook.print();
return false;
}
} else if (icon == 'archives') {
if (this.fluidbook.datas.archivesLink != '') {
- this.addLink('nav-archives', this.fluidbook.datas.archivesLink, 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);
- link = this.addLink('nav-archives', this.fluidbook.datas.archivesLink, 'archives', '!' + this.fluidbook.datas.archivesLabel);
++ link = this.addLink('nav-archives', this.fluidbook.datas.archivesLink, 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);
} else if (this.fluidbook.datas.externalArchives != '') {
- this.addLink('nav-archives', '#/archives', 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);
- link = this.addLink('nav-archives', '#/archives', 'archives', '!' + this.fluidbook.datas.archivesLabel);
++ link = this.addLink('nav-archives', '#/archives', 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);
}
} else if (icon == 'help') {
- this.addLink('interface-help', '#', 'help', 'help', 'help');
- link = this.addLink('nav-help', '#', 'help', '');
++ link = this.addLink('interface-help', '#', 'help', 'help', 'help');
} else if (icon == 'zoom' && !this.fluidbook.support.isMobile) {
- this.addLink('nav-zoomin', '#', 'zoomin', 'zoom in', 'zoom in');
- this.addLink('nav-zoomout', '#', 'zoomout', 'zoom out', 'zoom out');
- link = this.addLink('nav-zoomin', '#', 'zoomin', 'zoom in');
- link = this.addLink('nav-zoomout', '#', 'zoomout', 'zoom out');
++ link = this.addLink('nav-zoomin', '#', 'zoomin', 'zoom in', 'zoom in');
++ link = this.addLink('nav-zoomout', '#', 'zoomout', 'zoom out', 'zoom out');
$("#zoomin").click(function (e) {
$this.fluidbook.desktop.clickZoom(e, 'in');
return false;
});
} else if (icon == 'fullscreen' && Modernizr.fullscreen && !DATAS.phonegap) {
- this.addLink('interface-fullscreen', '#', 'fullscreen', 'full screen', 'switch between fullscreen and normal');
- link = this.addLink('nav-fullscreen', '#', 'fullscreen', 'switch between fullscreen and normal');
++ link = this.addLink('interface-fullscreen', '#', 'fullscreen', 'full screen', 'switch between fullscreen and normal');
$("#fullscreen").click(function () {
+ $this.menuAPI.close();
screenfull.toggle();
return false;
})
}
+
+ if (!visible) {
+ $(link).addClass('hidden');
+ }
}
- if (this.fluidbook.datas.search) {
- this.setSearch();
- }
+ // if (this.fluidbook.datas.search) {
+ // this.setSearch();
+ // }
if (this.fluidbook.datas.afterSearch != '' && this.fluidbook.datas.themeEnableAfterSearch) {
this.setAfterSearch();
}
return;
}
- $("#nav").append(l);
- $("#nav #locales").css('background-image', 'url("images/flags/' + flag + '.png")');
+ this.menu.append(l);
+ this.menu.find("#locales").css('background-image', 'url("images/flags/' + flag + '.png")');
+
+ return l;
},
- setSearch: function () {
+
+ getMenuCloseButton: function () {
+ var $this = this,
+ buttonID = 'menuClose';
+
+ // Click handler to close menu
+ $(document).on('click', '#' + buttonID, function(e) {
+
+ e.preventDefault();
+
+ // If the search is active, the close button should clear the search
+ // and return the user to the main menu instead of closing the menu
+ if ($this.fluidbook.isSearchActive()) {
+ $this.fluidbook.closeSearch();
+ } else {
+ $this.menuAPI.close();
+ }
+
+
+ });
+
+ return '<a href="#" id="'+ buttonID +'">'+ getSpriteIcon('interface-close') +'</a>';
+ },
+
+ getSearch: function () {
var $this = this;
var res = '<form action="#" id="searchForm" method="post">';
res += '<input type="text" id="q" name="q" type="search" value="" placeholder="' + this.fluidbook.l10n.__('search') + '" autocorrect="off" autocomplete="off" autocapitalize="off" />';
$('#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 id="chapterList">';
+
+ // 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 + '" class="level-' + chapter.level + '">' + chapter.label + '</a>';
+ });
+
+ html += '</li></ul>';
+
+ return html;
}
- };
+ };
+