$('#menuList > ul > li, #shareLinks').fadeIn(300);
},
- resizeMenu: function () {
-
- //console.warn('calling resizeSR');
- //console.log('menu open?', this.nav.menuIsOpen);
-
- if (!fluidbook.nav.menuIsOpen) return false;
-
- var wh = $(window).height(),
- formHeight = $('#searchForm').height();
- 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.search.menuSearchResults == undefined) {
- fluidbook.search.initSearchResults();
- 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)
- if (fluidbook.search.menuSearchResults !== undefined) {
- fluidbook.search.menuSearchResults.css('maxHeight', searchResultsMaxHeight);
- fluidbook.search.menuSearchResults.css('marginTop', marginTop);
- fluidbook.search.menuSearchResults.perfectScrollbar('update');
- }
-
- // Also set same max-height for search hints
- if (fluidbook.search.menuSearchHints !== undefined) {
- fluidbook.search.menuSearchHints.css('maxHeight', wh - formHeight);
- fluidbook.search.menuSearchHints.perfectScrollbar('update');
- }
- },
-
-
-
-
print: function () {
var $this = this;
var pdf;
};
if (view == 'index') {
this.openIndex(this.fluidbook.l10n.__('overview'), undefined, true, cb);
- } else if (view == 'search') {
- this.searchString = param1;
- var group = param2;
- $("#q").val(param1);
- this.fluidbook.search.find(param1, function (r) {
- $this.displayResults(r, group, cb);
- });
- if (group == undefined) {
- this.fluidbook.stats.track(1, 0, param1);
- }
} else if (view == 'video') {
this.openVideo(param1, cb);
} else if (view == 'audio') {
resize();
}, 420);
},
-
- displayResults: function (data, group, callback) {
-
- var $this = this;
- var results = data.results;
- var hideNoResults = !this.fluidbook.datas.searchShowNoResultsPages;
- if (data.total <= 0) {
- alert(this.fluidbook.l10n.__('no result found'));
- window.location = "#/page/" + this.fluidbook.currentPage;
- return;
- }
-
- this.openIndex(this.fluidbook.l10n.__('search results for') + ' « ' + this.searchString + " »", group, true, function () {
- var hits = [];
- for (var i = 0; i <= $this.fluidbook.datas.pages; i++) {
- hits[i] = 0;
- }
-
- $.each(results, function (k, v) {
- hits[k] += v;
- });
- var e = encodeURIComponent($this.searchString);
- $(".mview .doubleThumb").each(function () {
- var pages = $(this).data('pages').toString().split(',');
- if (pages.indexOf('1') != -1) {
- pages.push('0');
- }
- var hitsp = 0;
- var pagesWithHits = [];
- for (var i in pages) {
- var n = parseInt(pages[i]);
- if (hits[n] > 0) {
- hitsp += hits[n];
- pagesWithHits.push(pages[i]);
- }
- }
-
- if ($(this))
- if ($(this).find('.hits').length > 0) {
- return;
- }
-
- if (hitsp == 0) {
- if (hideNoResults) {
- $(this).remove();
- return;
- }
- $(this).append('<div class="overlay"></div>');
- $(this).append('<div class="hits no">' + $this.fluidbook.l10n.__('no result found') + '</div>');
- } else {
- $(this).append('<div class="hits yes">' + hitsp + ' ' + $this.fluidbook.l10n.__('hit(s)') + '</div>');
- if ($this.fluidbook.pad.enabled) {
- if (pagesWithHits.length == 1) {
- $(this).find('a').attr('href', '#/page/' + pagesWithHits[0]);
- } else {
- $(this).find('a').attr('href', '#/search/' + e + '/' + $(this).attr('page'));
- }
- } else {
- $(this).find('a').attr('href', '#/page/' + $(this).attr('page'));
- }
- }
- });
- $this.fluidbook.search.setHighlightTerms(data.terms);
- $this.fluidbook.search.highlightSearchTerms($this.fluidbook.currentPage);
- if (callback != undefined) {
- callback();
- }
- });
- }
- ,
openMultimedia: function (multimedia, callback) {
var a = $('a[href="#/multimedia/' + multimedia + '"]');
var markup = decodeURIComponent($(a).attr('data-multimedia'));
$('body').addClass('menu-open');
$this.menuIsOpen = true;
- setInterval($this.fluidbook.resizeMenu, 500);
+ setInterval($this.fluidbook.resize.resizeMenu, 500);
//$('#q').focus(); // Disabled for now because it triggers the keyboard to open on some mobile devices
});
});
// Recalculate available size for menu search results
- $(window).on('fluidbookresize', fluidbook.resizeMenu);
+ $(window).on('fluidbookresize', 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.
// Search form handler
$(document).on('submit', '#searchForm', function () {
- var q = $("#q").val();
-
- if (q == '') {
- return false;
- }
-
- $this.fluidbook.search.find(q, function (results) {
-
- // Handle empty result set
- if (results.total <= 0) {
- fluidbook.search.menuSearchResults.html('<div class="no-results">' + this.fluidbook.l10n.__('no result found') + '</div>');
- fluidbook.search.hideSearchHints();
- fluidbook.search.menuSearchResults.fadeIn(300);
- return false;
- }
-
- var hits = [];
-
- // Create a list of all pages so we can record which ones have a hit on the search term
- for (var i = 0; i <= $this.fluidbook.datas.pages; i++) {
- hits[i] = 0;
- }
- // Map result hits to pages
- $.each(results.results, function (k, v) {
- hits[k] += v;
- });
-
- // ToDo: check the purpose of the group variable? Also check tracking
- //$this.displayResults(r, group, cb);
- //console.log('Search results...');
- //console.log(results);
-
- // Display results
- //res += $this.fluidbook.l10n.__('search results for') + ' « ' + q + " »"
-
- // Use the index of all pages as a starting point to filter results thumbnails
- fluidbook.search.menuSearchResults.html($this.fluidbook.menu.index.getView()).hide();
-
- // Process each spread of pages to collect the ones with results
- fluidbook.search.menuSearchResults.find('.doubleThumb').each(function () {
-
- var currentPages = $(this).data('pages').toString().split(','),
- totalHits = 0,
- pagesWithHits = [];
-
- // Get total number of hits for pages in this spread
- for (var i in currentPages) {
- var pageNum = parseInt(currentPages[i]);
- if (hits[pageNum] > 0) {
- totalHits += hits[pageNum];
- pagesWithHits.push(currentPages[i]);
- }
- }
-
-
- // If there's already a .hits element, this spread has already been processed
- if ($(this).find('.hits').length > 0) {
- return;
- }
-
- if (totalHits == 0) {
- // Should pages with no results still be shown?
- if (fluidbook.datas.searchShowNoResultsPages) {
- $(this).append('<div class="overlay"></div>');
- $(this).append('<div class="hits no">' + $this.fluidbook.l10n.__('no result found') + '</div>');
- } else {
- $(this).remove();
- return;
- }
- } else {
- // Add the link to the main result page. Link around the hits div is for better usability (previously wasn't clickable)
- $(this).append('<a href="#/page/' + $(this).attr('page') + '"><div class="hits yes">' + totalHits + ' ' + fluidbook.l10n.__('hit(s)') + '</div></a>');
- if (fluidbook.pad.enabled) {
- if (pagesWithHits.length == 1) {
- $(this).find('a').attr('href', '#/page/' + pagesWithHits[0]);
- } else {
- $(this).find('a').attr('href', '#/search/' + e + '/' + $(this).attr('page'));
- }
- } else {
- $(this).find('a').attr('href', '#/page/' + $(this).attr('page'));
- }
- }
-
- });
-
- // Set Highlighting of results keywords
- $this.fluidbook.search.setHighlightTerms(results.terms);
- $this.fluidbook.search.highlightSearchTerms($this.fluidbook.currentPage);
-
-
- fluidbook.search.hideSearchHints();
- fluidbook.search.menuSearchResults.fadeIn(300).scrollTop(0);
-
- // 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.search.menuSearchResults.perfectScrollbar({
- suppressScrollX: true,
- minScrollbarLength: 40,
- //maxScrollbarLength: 60
- });
-
- });
-
- // window.location.hash = '/search/' + q;
- //
- // if ($this.menuIsOpen) {
- // $this.menuAPI.close();
- // }
-
+ $this.fluidbook.search.submitForm();
return false;
});
// Scale horizontal size and positioning. Transform origin is handled in CSS for LTR/RTL variations
$('#horizontalNav').css({
- 'transform': 'translateY(-'+ 50 * navScale +'%) scale('+ navScale +')'
+ 'transform': 'translateY(-' + 50 * navScale + '%) scale(' + navScale + ')'
})
var headerHeight = this.fluidbook.datas.menuHeight * navScale;
},
getScreenFluidbookWidth: function () {
return $("#fluidbook").outerWidth() * fluidbook.resize.bookScale;
+ },
+ resizeMenu: function () {
+ if (!this.fluidbook.nav.menuIsOpen) return false;
+
+ var wh = $(window).height(),
+ formHeight = $('#searchForm').height();
+ 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 (this.fluidbook.search.menuSearchResults == undefined) {
+ this.fluidbook.search.initSearchResults();
+ 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)
+ if (this.fluidbook.search.menuSearchResults !== undefined) {
+ this.fluidbook.search.menuSearchResults.css('maxHeight', searchResultsMaxHeight);
+ this.fluidbook.search.menuSearchResults.css('marginTop', marginTop);
+ this.fluidbook.search.menuSearchResults.perfectScrollbar('update');
+ }
+
+ // Also set same max-height for search hints
+ if (this.fluidbook.search.menuSearchHints !== undefined) {
+ this.fluidbook.search.menuSearchHints.css('maxHeight', wh - formHeight);
+ this.fluidbook.search.menuSearchHints.perfectScrollbar('update');
+ }
}
};
\ No newline at end of file
var res = {};
var terms = [];
var total = 0;
- var doublesPages = {};
+ var doublesPages = [];
this.resultPages = [];
var q, v, k, kk, word, wordata, page, occurences;
v = INDEX[k];
for (page in v.p) {
var occurences = v.p[page];
+ console.log(page + ' -> ' + occurences);
page = parseInt(page);
if ((page % 2) == 1) {
page--;
}
- if (doublesPages[page] == undefined) {
- doublesPages[page] = {};
+
+ if (doublesPages[page] == null || doublesPages[page] == undefined) {
+ doublesPages[page] = [];
}
- if (doublesPages[page][kk] == undefined) {
+ if (doublesPages[page][kk] == null || doublesPages[page][kk] == undefined) {
doublesPages[page][kk] = 0;
}
doublesPages[page][kk] += occurences;
}
}
- if(this.fluidbook.l10n.dir=='rtl'){
+ if (this.fluidbook.l10n.dir == 'rtl') {
pageNrs.reverse();
}
initSearchResults: function () {
this.menuSearchResults = $('#menuSearchResults');
- this.fluidbook.resizeMenu();
+ this.fluidbook.resize.resizeMenu();
this.menuSearchResults.hide();
},
this.clearHighlights()
this.fluidbook.showMenuItems(); // Show menu items that were hidden previously
},
+
+ submitForm: function () {
+ var q = $("#q").val();
+
+ if (q == '') {
+ return false;
+ }
+
+ var $this = this;
+ this.find(q, function (results) {
+ $this.openResults(results);
+ });
+
+
+ },
+
+ openResults: function (results) {
+ var $this = this;
+
+ // Handle empty result set
+ if (results.total <= 0) {
+ this.menuSearchResults.html('<div class="no-results">' + this.fluidbook.l10n.__('no result found') + '</div>');
+ this.hideSearchHints();
+ this.menuSearchResults.fadeIn(300);
+ return false;
+ }
+
+ var hits = [];
+
+ // Create a list of all pages so we can record which ones have a hit on the search term
+ for (var i = 0; i <= this.fluidbook.datas.pages; i++) {
+ hits[i] = 0;
+ }
+ // Map result hits to pages
+ $.each(results.results, function (k, v) {
+ hits[k] += v;
+ });
+
+ // ToDo: check the purpose of the group variable? Also check tracking
+ //$this.displayResults(r, group, cb);
+ //console.log('Search results...');
+ //console.log(results);
+
+ // Display results
+
+ // Use the index of all pages as a starting point to filter results thumbnails
+ this.menuSearchResults.html(this.fluidbook.menu.index.getView()).hide();
+
+ // Process each spread of pages to collect the ones with results
+ this.menuSearchResults.find('.doubleThumb').each(function () {
+ var currentPages = $(this).data('pages').toString().split(','),
+ totalHits = 0,
+ pagesWithHits = [];
+
+ // Get total number of hits for pages in this spread
+ for (var i in currentPages) {
+ var pageNum = parseInt(currentPages[i]);
+ if (hits[pageNum] > 0) {
+ totalHits += hits[pageNum];
+ pagesWithHits.push(currentPages[i]);
+ }
+ }
+
+
+ // If there's already a .hits element, this spread has already been processed
+ if ($(this).find('.hits').length > 0) {
+ return;
+ }
+
+ if (totalHits == 0) {
+ // Should pages with no results still be shown?
+ if ($this.fluidbook.datas.searchShowNoResultsPages) {
+ $(this).append('<div class="overlay"></div>');
+ $(this).append('<div class="hits no">' + $this.fluidbook.l10n.__('no result found') + '</div>');
+ } else {
+ $(this).remove();
+ return;
+ }
+ } else {
+ // Add the link to the main result page. Link around the hits div is for better usability (previously wasn't clickable)
+ $(this).append('<a href="#/page/' + $(this).attr('page') + '"><div class="hits yes">' + totalHits + ' ' + $this.fluidbook.l10n.__('hit(s)') + '</div></a>');
+ if ($this.fluidbook.pad.enabled) {
+ if (pagesWithHits.length == 1) {
+ $(this).find('a').attr('href', '#/page/' + pagesWithHits[0]);
+ } else {
+ $(this).find('a').attr('href', '#/search/' + e + '/' + $(this).attr('page'));
+ }
+ } else {
+ $(this).find('a').attr('href', '#/page/' + $(this).attr('page'));
+ }
+ }
+
+ });
+
+ // Set Highlighting of results keywords
+ this.setHighlightTerms(results.terms);
+ this.highlightSearchTerms(this.fluidbook.currentPage);
+
+
+ this.hideSearchHints();
+ this.menuSearchResults.fadeIn(300).scrollTop(0);
+
+ // 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(function () {
+ this.fluidbook.resize.resizeMenu();
+ }, 500);
+
+ // Initialise scrollbar after populating so bars appear immediately
+ this.menuSearchResults.perfectScrollbar({
+ suppressScrollX: true,
+ minScrollbarLength: 40,
+ //maxScrollbarLength: 60
+ });
+ }
};
c = ' simple ' + s2;
}
+ if (j == 1) {
+ pages.unshift(0);
+ }
+
ix = ix1 + ix2;
this.normalHTML += '<div class="doubleThumb' + c + '" page="' + i + '" data-pages="' + pages.join(',') + '">' + ix;
this.normalHTML += '</div>';