From b5cc317af0a8b9750f7de3d1cae9fe908325cc3d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 29 Jan 2026 17:27:17 +0100 Subject: [PATCH] wait #7950 @2.5 --- js/libs/fluidbook/fluidbook.search.js | 72 ++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 94118c4e..43d67605 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -1,6 +1,7 @@ function FluidbookSearch(fluidbook) { this.fluidbook = fluidbook; this.indexLoaded = false; + this.indexLoading = false; this.termsToHighlight = []; this.highlights = []; this.highlightEnabled = fluidbook.settings.highlightResults; @@ -238,21 +239,29 @@ FluidbookSearch.prototype = { }, _loadLib: function (callback) { - if (this.indexLoaded) { + if (this.indexLoading || this.indexLoaded) { return callback(); } + this.indexLoaded = true; var $this = this; + var __callback = function () { + if (this.fluidbook.settings.searchWords) { + $this._addLinkWords(); + } + $this.indexLoaded = true; + $this.indexLoading = false; + callback(); + }; + let __loadTexts = function () { $this._loadTexts(function () { if ($this.highlightEnabled) { loadJSLibrary($this.fluidbook.loader.getURL('data/search.highlight.js?j=' + this.fluidbook.settings.cacheDate), function () { - $this.indexLoaded = true; - callback(); + __callback(); }); } else { - $this.indexLoaded = true; - callback(); + __callback(); } }); }; @@ -266,6 +275,50 @@ FluidbookSearch.prototype = { } }, + _addLinkWords: function () { + let $this = this; + let z = 1; + // Add words added by links to the INDEX + $.each(this.fluidbook.settings.searchWords, function (word, data) { + if (INDEX[word] === undefined) { + INDEX[word] = {t: 0, p: {}}; + } + + $.each(data, function (k, d) { + INDEX[word].t++; + if (INDEX[word].p[d.page] === undefined) { + INDEX[word].p[d.page] = 0; + } + INDEX[word].p[d.page]++; + }); + }); + + // Add words to the HIGHLIGHT data + $.each(this.fluidbook.settings.searchWords, function (word, data) { + if (HIGHLIGHTS[word] === undefined) { + HIGHLIGHTS[word] = []; + } + + $.each(data, function (k, d) { + let lw = []; + let letters = word.split(''); + $.each(letters, function (kk, letter) { + lw.push(((d.coords.width * z) / letters.length)); + }); + HIGHLIGHTS[word].push({ + page: d.page, + y: (d.coords.y + d.coords.height) * z, + x: (d.coords.x) * z, + width: d.coords.width * z, + height: d.coords.height * z, + scaleY: 1, + lw: lw, + padding: 0, + }); + }); + }); + }, + _loadTexts: function (callback) { if (this.robust || this.fluidbook.settings.searchWordSelectionAlgorithm === 'expression') { loadJSLibrary(this.fluidbook.loader.getURL('data/search.texts.js?j=' + this.fluidbook.settings.cacheDate), function () { @@ -704,9 +757,11 @@ FluidbookSearch.prototype = { } } - var padding = position.height * 0.2; + + var padding = position.padding == undefined ? position.height * 0.2 : position.padding; + var z = this.fluidbook.settings.cssScale; - var h = $('
'); + var coords = { top: (position.y - position.height - padding * 2) * z, left: (position.x + x - padding) * z + offset, @@ -744,11 +799,14 @@ FluidbookSearch.prototype = { allCoords.push(coords); } + console.log(allCoords); + $.each(allCoords, function (i, coords) { var hash = coords.top + '|' + coords.left + '|' + coords.width + '|' + coords.height; if ($('[data-hash="' + hash + '"]').length > 0) { return; } + var h = $('
'); $(h).attr('data-hash', hash); $(h).css(coords).transform(transform); if ($this.fluidbook.elasticslide.isActive()) { -- 2.39.5