this.menu = $("#menu"); // Renamed from #nav because mmenu animations weren't working (probably due to some other script interference)
this.horizontalNav = $("#horizontalNav");
this._inited = {};
+ this.closeTimeout;
this.setNav('horizontalNav');
if ($("#iconList").html() !== '') {
this.setNav('menu');
},
initMenu: function () {
- var $this = this, dir = this.fluidbook.l10n.dir,
- inverted = this.isInverted(),
+ var $this = this, dir = this.fluidbook.l10n.dir, inverted = this.isInverted(),
side = ((dir === 'ltr' && inverted) || (dir === 'rtl' && !inverted)) ? 'right' : 'left';
- var extensions = ['pagedim-black', 'position-front'];
- if (side === 'right') {
- extensions.push('position-right');
- }
-
- 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: {
- close: function () {
- if (fluidbook.settings.phonegap === 'ios') {
- return !$(this).is('#menu_download,#menu_print');
- }
- return true;
- }, preventDefault: function () {
- return false;
- },
- },
-
- "extensions": extensions, "offCanvas": {
- "position": side, "zposition": "front",
- }, "navbar": {
- //add: false // Removes main title bars completely
- title: "" // Hides the default "Menu" text
- }, "rtl": {
- "use": "detect" // Auto detect when in RTL mode based on html dir attribute
- },
-
- }, {
- offCanvas: {
- page: {
- noSelector: ['#loader']
- }
- }
- });
-
- 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');
- $("nav#menu").addClass('mm-menu_opened');
- $this.menuIsOpen = true;
- setInterval(function () {
- $this.fluidbook.resize.resizeMenu()
- }, 500);
-
- //$('#q').focus(); // Disabled for now because it triggers the keyboard to open on some mobile devices
- });
-
- this.menuAPI.bind("close:finish", function () {
- $('body').removeClass('menu-open');
- $this.menuIsOpen = false;
- });
+ $("#menu").insertAfter('#main');
+ $('<div id="menuOverlay"></div>').insertAfter('#menu');
+
+ // var extensions = ['pagedim-black', 'position-front'];
+ // if (side === 'right') {
+ // extensions.push('position-right');
+ // }
+ //
+ // 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: {
+ // close: function () {
+ // if (fluidbook.settings.phonegap === 'ios') {
+ // return !$(this).is('#menu_download,#menu_print');
+ // }
+ // return true;
+ // }, preventDefault: function () {
+ // return false;
+ // },
+ // },
+ //
+ // "extensions": extensions, "offCanvas": {
+ // "position": side, "zposition": "front",
+ // }, "navbar": {
+ // //add: false // Removes main title bars completely
+ // title: "" // Hides the default "Menu" text
+ // }, "rtl": {
+ // "use": "detect" // Auto detect when in RTL mode based on html dir attribute
+ // },
+ //
+ // }, {
+ // offCanvas: {
+ // page: {
+ // noSelector: ['#loader']
+ // }
+ // }
+ // });
+ //
+ // 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');
+ // $("nav#menu").addClass('mm-menu_opened');
+ // $this.menuIsOpen = true;
+ //
+ // setInterval(function () {
+ // $this.fluidbook.resize.resizeMenu()
+ // }, 500);
+ //
+ // //$('#q').focus(); // Disabled for now because it triggers the keyboard to open on some mobile devices
+ // });
+ //
+ // this.menuAPI.bind("close:finish", function () {
+ // $('body').removeClass('menu-open');
+ // $this.menuIsOpen = false;
+ // });
$(document).on(this.fluidbook.input.clickEvent, '#menuOpener', function (e) {
e.preventDefault();
- $this.menuAPI.open();
+ $this.openMenu();
});
// Close menu when a search result is clicked
$this.fluidbook.resize.resizeMenu();
});
- // Handle swipe to close (it's only really practical to have this because swipe to open would interfere with main Fluidbook swipes)
- // We are not using MMenu's "Drag" add-on because it doesn't close the main menu, only submenus on swipe.
- // Close direction will be towards the same side the menu comes from
- var swipeCloseDirection = this.menuAPI.getInstance().opts.offCanvas.position,
- menuSwipe = new Hammer(document.getElementById('menu'));
-
- // Swipe Handler
- menuSwipe.on('swipe' + swipeCloseDirection, function (e) {
-
- // Only trigger swipe response when menu is actually open
- if (!$this.menuIsOpen) {
- return false;
- }
-
- $this.closeMenu();
- });
-
-
// Add search and share links to main menu panel
$('#menuList').append(this.searchHTML + this.shareLinksHTML);
$('#menuList > ul, #chapterList').perfectScrollbar({
suppressScrollX: true, minScrollbarLength: 40, //maxScrollbarLength: 60
});
+
+ $("#menuOverlay").on(this.fluidbook.input.clickEvent, function () {
+ $this.closeMenu();
+ });
},
+
+ openMenu: function () {
+ clearTimeout(this.closeTimeout);
+ $("#menu,#menuOverlay").show();
+ setTimeout(function () {
+ $("#menu").addClass('open');
+ },10);
+ },
+
+ closeAll: function () {
+ this.closeMenu();
+ },
+
closeMenu: function () {
- this.menuAPI.close();
- }, // getIcon: function (name) {
+ clearTimeout(this.closeTimeout);
+ $("#menu").removeClass('open');
+ this.closeTimeout = setTimeout(function () {
+ $("#menu,#menuOverlay").hide();
+ }, 500);
+ },
+
+ // getIcon: function (name) {
// var src = 'data/images/' + name + '.';
// if (this.fluidbook.support.SVG) {
// src += 'svg';
} else {
return '<a href="' + href + '"' + res + '</a>';
}
- },
- getNavFromType: function (navType) {
+ }, getNavFromType: function (navType) {
switch (navType) {
case 'horizontalNav':
return this.horizontalNav;
console.error('navType ' + navType + ' not found!');
return false;
}
- },
- setNav: function (navType) {
+ }, setNav: function (navType) {
if (typeof navType === 'undefined') {
return false;
if (!this.fluidbook.search.isSearchActive()) {
if (!this.fluidbook.settings.searchFullBurger) {
this.fluidbook.search.initSearchHints(); // Clears menu and only displays search box
- this.menuAPI.closeAllPanels(); // Make sure we're on the main panel with the search box
+ this.closeAll(); // Make sure we're on the main panel with the search box
}
}
this.fluidbook.search.submitForm();
}
} else {
- this.menuAPI.open();
+ this.menu.openMenu();
$('#q').focus(); // Put cursor in the search field
}