for (var t in terms) {
var term = terms[t];
for (var w in HIGHLIGHTS) {
- if (w.indexOf(term) == 0) {
- var h = {occurences: HIGHLIGHTS[w], color: t, word: w, term: term};
- this.highlights.push(h);
+ if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'begins' && w.indexOf(term) != 0) {
+ continue;
+ } else if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'contains' && w.indexOf(term) == -1) {
+ continue;
+ } else if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'exact' && w != term) {
+ continue;
}
+
+ var h = {occurences: HIGHLIGHTS[w], color: t, word: w, term: term};
+ this.highlights.push(h);
}
}
},
},
highlightOccurence: function (position, word, term, color, offset) {
- if (word != term) {
+ if (word == term) {
+ width = position.width;
+ x = 0;
+ } else {
// 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];
+ var x = 0;
+ var startIndex = word.indexOf(term);
+ for (var i = 0; i < word.length; i++) {
+ if (i < startIndex) {
+ x += position.lw[i];
+ } else {
+ width += position.lw[i];
+ }
+ if (i >= term.length) {
+ break;
+ }
}
- } else {
- width = position.width;
}
var padding = position.height * 0.2;
var z = this.fluidbook.datas.cssScale;
var h = $('<div class="highlight" data-color="' + color + '"></div>');
- 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 coords = {top: (position.y - position.height - padding * 2) * z, left: (position.x + 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;