return i + 1;
},
- hideMenuItems: function (exception) {
- exception = exception || '';
- $('#menuList > ul > li').not(exception).fadeOut(100);
+ hideMenuItems: function () {
+ $('#menuList > ul > li, #shareLinks').fadeOut(100);
},
- showMenuItems: function (exception) {
- exception = exception || '';
- $('#menuList > ul > li').not(exception).fadeIn(300);
+ showMenuItems: function () {
+ $('#menuList > ul > li, #shareLinks').fadeIn(300);
},
initSearchResults: function () {
this.menuSearchResults = $('#menuSearchResults');
- this.resizeSearchResults();
+ this.resizeMenu();
this.menuSearchResults.hide();
},
- resizeSearchResults: function () {
+ resizeMenu: function () {
//console.warn('calling resizeSR');
//console.log('menu open?', this.nav.menuIsOpen);
var wh = $(window).height(),
formHeight = $('#searchForm').height();
- marginTop = marginBottom = 50,
- maxHeight = wh - formHeight - marginTop - marginBottom;
+ marginTop = marginBottom = Math.min(Math.round(wh * 0.075), 50); // Relative margins with a max of 50
+ searchResultsMaxHeight = wh - formHeight - marginTop - marginBottom,
+ mainMenuMaxHeight = wh - $('#menuSearch').height() - $('#shareLinks').outerHeight();
// Search results element may not exist when resize is called
if (fluidbook.menuSearchResults == undefined) {
return false; // initSearchResults will call this resize function anyway
}
+ // Max-height for the top level of the main menu so it can scroll between the search box and sharing bar
+ $('#menuList > ul').css('maxHeight', mainMenuMaxHeight);
+
// Set max-height for search results section (using CSS vh units was unreliable)
- fluidbook.menuSearchResults.css('maxHeight', maxHeight);
- fluidbook.menuSearchResults.perfectScrollbar('update');
+ if (fluidbook.menuSearchResults !== undefined) {
+ fluidbook.menuSearchResults.css('maxHeight', searchResultsMaxHeight);
+ fluidbook.menuSearchResults.css('marginTop', marginTop);
+ fluidbook.menuSearchResults.perfectScrollbar('update');
+ }
+
+ // Also set same max-height for search hints
+ if (fluidbook.menuSearchHints !== undefined) {
+ fluidbook.menuSearchHints.css('maxHeight', wh - formHeight);
+ fluidbook.menuSearchHints.perfectScrollbar('update');
+ }
},
initSearchHints: function () {
this.menuSearchHints = $('#menuSearchHints');
- this.hideMenuItems('#menuSearch'); // Hide everything except the search form so we can have space for the hints
+ this.hideMenuItems(); // Hide menu items to give space for hints div
this.menuSearchHints.fadeIn(300);
if (this.l10n.dir == 'rtl') {
left = -1 * ($(window).width() - left - $("#q").outerWidth());
}
+
+ this.menuSearchHints.perfectScrollbar({
+ suppressScrollX: true,
+ minScrollbarLength: 40
+ });
+
$("#searchHints").css({top: top, left: left}).show();
},
killLastSearchHint: function () {
this._dimensions = this.fluidbook.datas.iconsDimensions;
this.menuIsOpen = false;
this.chaptersMenuHTML = '';
+ this.searchHTML = '';
+ this.shareLinksHTML = '';
this.menu = $("#menu"); // Renamed from #nav because mmenu animations weren't working (probably due to some other script interference)
this.horizontalNav = $("#horizontalNav");
this._inited = {};
$('body').addClass('menu-open');
$this.menuIsOpen = true;
- $('#q').focus();
+ setInterval($this.fluidbook.resizeMenu, 500);
+
+ //$('#q').focus(); // Disabled for now because it triggers the keyboard to open on some mobile devices
});
this.menuAPI.bind("close:finish", function () {
});
// Recalculate available size for menu search results
- $(window).on('fluidbookresize', fluidbook.resizeSearchResults);
+ $(window).on('fluidbookresize', fluidbook.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.
+ // Add search and share links to main menu panel
+ $('#menuList').append(this.searchHTML + this.shareLinksHTML);
+
+ // Add scrollbar to main menu
+ $('#menuList > ul, #chapterList').perfectScrollbar({
+ suppressScrollX: true,
+ minScrollbarLength: 40,
+ //maxScrollbarLength: 60
+ });
},
// getIcon: function (name) {
// var src = 'data/images/' + name + '.';
// Add Search form, or if disabled, add "Menu" label in its place
var searchElement = (this.fluidbook.datas.search) ? this.getSearch() : '<span>' + this.fluidbook.l10n.__('Menu') + '</span>';
- $('#menuList').prepend('<li id="menuSearch">' + searchElement + '</li>');
+ this.searchHTML = '<div id="menuSearch">' + searchElement + '</div>'; // Save for later so it can be injected after MMenu is rendered
// Horizontal icon nav
} else if (navType == 'horizontalNav') {
}
}
- // Append to menu
- this.menu.find('ul').append('<li id="shareLinks"><div class="mm-nopanel share-icons">' + shareHTML + '</div></li>');
+ // Save HTML so it can be added to menu once MMenu is initialised
+ this.shareLinksHTML = '<div id="shareLinks"><div class="share-icons">' + shareHTML + '</div></div>';
}
$this.menuAPI.closeAllPanels(); // Make sure we're on the main panel with the search box
}
$this.menuAPI.open();
+
+ $('#q').focus(); // Put cursor in the search field
});
// Full screen toggle
fluidbook.hideSearchHints();
fluidbook.menuSearchResults.fadeIn(300);
+ // On some phones, the height of the search results is miscalculated due to the
+ // keyboard being open and reducing the available window height. We need to wait until
+ // the keyboard closes before trying to resize again...
+ setTimeout(fluidbook.resizeMenu, 500);
+
+
// Initialise scrollbar after populating so bars appear immediately
fluidbook.menuSearchResults.perfectScrollbar({
suppressScrollX: true,