]> _ Git - fluidbook-html5.git/commitdiff
fix #1641 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Oct 2017 17:20:51 +0000 (19:20 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Oct 2017 17:20:51 +0000 (19:20 +0200)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.resize.js
js/libs/fluidbook/fluidbook.search.js
js/libs/fluidbook/menu/fluidbook.index.js

index b7f5ca730eebdcbefead2e1860230c1359d2c9ad..d73b637fb7e655d49462c63f18c3605953d9c639 100644 (file)
@@ -740,45 +740,6 @@ Fluidbook.prototype = {
         $('#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;
index a1db912ad74e64faf982544c47a95d5f68372a30..a86b891eaf6898fe83836ec06933c15260367880 100644 (file)
@@ -76,16 +76,6 @@ FluidbookMenu.prototype = {
         };
         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') {
@@ -137,76 +127,6 @@ FluidbookMenu.prototype = {
             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') + ' &laquo; ' + this.searchString + " &raquo;", 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'));
index 7bdf14284f308f3eef2cc134d742308ad0e5fbf0..db4e315350ddaa22108731e39d50c4e6b43e43a5 100644 (file)
@@ -52,7 +52,7 @@ FluidbookNav.prototype = {
             $('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
         });
@@ -74,7 +74,7 @@ FluidbookNav.prototype = {
         });
 
         // 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.
@@ -653,120 +653,7 @@ FluidbookNav.prototype = {
 
         // 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') + ' &laquo; ' + q + " &raquo;"
-
-                // 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;
         });
 
index 8bb55da01e03f261380f2802b957c7f7776d780e..c11fd29e5b052d62d65dd88e165ab50eeeacab28 100644 (file)
@@ -170,7 +170,7 @@ FluidbookResize.prototype = {
 
         // 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;
@@ -312,5 +312,36 @@ FluidbookResize.prototype = {
     },
     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
index d17276d3b5a54e90542a17deb50e6358ebcc453d..4e34127eaa7ef12e2b746114741938f12619a074 100644 (file)
@@ -76,7 +76,7 @@ FluidbookSearch.prototype = {
         var res = {};
         var terms = [];
         var total = 0;
-        var doublesPages = {};
+        var doublesPages = [];
         this.resultPages = [];
 
         var q, v, k, kk, word, wordata, page, occurences;
@@ -99,14 +99,16 @@ FluidbookSearch.prototype = {
                 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;
@@ -245,7 +247,7 @@ FluidbookSearch.prototype = {
             }
         }
 
-        if(this.fluidbook.l10n.dir=='rtl'){
+        if (this.fluidbook.l10n.dir == 'rtl') {
             pageNrs.reverse();
         }
 
@@ -298,7 +300,7 @@ FluidbookSearch.prototype = {
 
     initSearchResults: function () {
         this.menuSearchResults = $('#menuSearchResults');
-        this.fluidbook.resizeMenu();
+        this.fluidbook.resize.resizeMenu();
         this.menuSearchResults.hide();
     },
 
@@ -379,5 +381,121 @@ FluidbookSearch.prototype = {
         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
+        });
+    }
 };
 
index 60de61543c4ab0fc953cc591d2064e5208de5d36..8a2232d6446b33810f8d4ba5017e7b26781779b7 100644 (file)
@@ -73,6 +73,10 @@ FluidbookIndex.prototype = {
                     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>';