FluidbookSearch.prototype = {
init: function () {
- var $this=this;
+ var $this = this;
$(this.fluidbook).on('fluidbook.page.change.end', function (e, pageNr) {
$this.highlightSearchTerms(pageNr);
});
+ $(document).on('change', '#q', function () {
+ $this.setHighlightTerms([]);
+ $this.clearHighlights();
+ return true;
+ });
},
getHints: function (q, callback) {
var $this = this;
},
highlightOccurence: function (position, word, term, color, offset) {
+ if (word != term) {
+ // When we just highlight a part of the word. For example, searched term is brand and word found is brands
+ var width = 0;
+ for (var i = 0; i < term.length; i++) {
+ width += position.lw[i];
+ }
+ } else {
+ width = position.width;
+ }
+
var padding = position.height * 0.2;
var z = this.fluidbook.datas.pageZoomFactor * 1.19;
var h = $('<div class="highlight" data-color="' + color + '"></div>');
- $(h).css({top: (position.y - position.height - padding * 2) * z, left: (position.x - padding) * z + offset, width: (position.width + 2 * padding) * z, height: (position.height + padding * 3) * z});
+ var coords = {top: (position.y - position.height - padding * 2) * z, left: (position.x - padding) * z + offset, width: (width + 2 * padding) * z, height: (position.height + padding * 3) * z};
+ var hash = coords.top + '|' + coords.left + '|' + coords.width + '|' + coords.height;
+ if ($('[data-hash="' + hash + '"]').length > 0) {
+ return;
+ }
+ $(h).attr('data-hash', hash);
+ $(h).css(coords);
$("#searchHighlights").append(h);
}
};