},
_loadTexts: function (callback) {
- if (this.fluidbook.datas.searchWordSelectionAlgorithm == 'expression') {
+ if (this.fluidbook.datas.searchWordSelectionAlgorithm === 'expression') {
loadJSLibrary('data/search.texts.js', function () {
callback();
});
var v;
for (var k in INDEX) {
v = INDEX[k];
- if (k.indexOf(q) != 0) {
+ if (k.indexOf(q) !== 0) {
continue;
}
res.push([k, v.t]);
getSearchWordSelectionAlgorithm: function (q) {
var a = this.fluidbook.datas.searchWordSelectionAlgorithm;
- if (q.indexOf(' ') === -1 && a == 'expression') {
+ if (q.indexOf(' ') === -1 && a === 'expression') {
a = 'begins';
}
return a;
_find: function (q, callback) {
var algo = this.getSearchWordSelectionAlgorithm(q);
- if (algo == 'expression') {
+ if (algo === 'expression') {
return this._findExpression(q, callback);
}
var words = this.normalizeQuery(q, true);
continue;
}
- if (algo == 'begins' && k.indexOf(q) != 0) {
+ if (algo === 'begins' && k.indexOf(q) !== 0) {
continue;
- } else if (algo == 'contains' && k.indexOf(q) == -1) {
+ } else if (algo === 'contains' && k.indexOf(q) === -1) {
continue;
- } else if (algo == 'exact' && k != q) {
+ } else if (algo === 'exact' && k !== q) {
continue;
}
v = INDEX[k];
total = 0;
for (var dpNumber in doublesPages) {
var doublePageOccurences = doublesPages[dpNumber];
- if (Object.keys(doublePageOccurences).length == nbwords || this.fluidbook.datas.searchPageSelectionAlgorithm == 'OR') {
+ if (Object.keys(doublePageOccurences).length === nbwords || this.fluidbook.datas.searchPageSelectionAlgorithm === 'OR') {
var occ = 0;
for (var ww in doublePageOccurences) {
occ += doublePageOccurences[ww];
if (page > maxPage) {
continue;
}
-
+
if (!this.singleMode && (page % 2) === 1) {
page--;
}
}
this.termsToHighlight = terms;
this.highlights = [];
- if (terms.length == 0) {
+ if (terms.length === 0) {
return;
}
var algo = this.getSearchWordSelectionAlgorithm(terms.join(' '));
- if (algo == 'expression') {
+ if (algo === 'expression') {
return;
}
for (var t in terms) {
var term = terms[t];
for (var w in HIGHLIGHTS) {
- if (algo != 'expression' && w.length < this.fluidbook.datas.ignoreWordLimit) {
+ if (algo !== 'expression' && w.length < this.fluidbook.datas.ignoreWordLimit) {
continue;
}
- if (algo == 'begins' && w.indexOf(term) != 0) {
+ if (algo === 'begins' && w.indexOf(term) !== 0) {
continue;
- } else if (algo == 'contains' && w.indexOf(term) == -1) {
+ } else if (algo === 'contains' && w.indexOf(term) === -1) {
continue;
- } else if (algo == 'exact' && w != term) {
+ } else if (algo === 'exact' && w !== term) {
continue;
}
var color = t;
- if (algo == 'expression') {
+ if (algo === 'expression') {
color = 0;
}
return;
}
this.clearHighlights();
- if (this.termsToHighlight.length == 0) {
+ if (this.termsToHighlight.length === 0) {
return;
}
evenPageNumber--;
}
- if (this.resultPages.indexOf(evenPageNumber) == -1) {
+ if (this.resultPages.indexOf(evenPageNumber) === -1) {
return;
}
}
var pageNrs = [];
- if (this.fluidbook.resize.orientation == 'portrait') {
+ if (this.fluidbook.resize.orientation === 'portrait') {
pageNrs.push(pageNr);
} else {
}
}
- if (this.fluidbook.l10n.dir == 'rtl') {
+ if (this.fluidbook.l10n.dir === 'rtl') {
pageNrs.reverse();
}
var qoffset = $("#q").offset();
var top = qoffset.top + $("#q").outerHeight() + 5;
var left = qoffset.left;
- if (this.fluidbook.l10n.dir == 'rtl') {
+ if (this.fluidbook.l10n.dir === 'rtl') {
left = -1 * ($(window).width() - left - $("#q").outerWidth());
}
submitForm: function () {
var q = $("#q").val();
- if (q == '') {
+ if (q === '') {
return false;
}
+ this.closeKeyboardonTouchDevices();
+
window.location.hash = '/search/' + q;
this.fluidbook.stats.track(1, this.fluidbook.currentPage, q);
}
var $this = this;
+ this.closeKeyboardonTouchDevices();
+
// Handle empty result set
if (results.total <= 0) {
this.menuSearchResults.html('<div class="no-results">' + this.fluidbook.l10n.__('no result found') + '</div>');
registerPlugin: function (p) {
this.plugins.push(p);
},
+ closeKeyboardonTouchDevices: function () {
+ if (this.fluidbook.support.iOS || this.fluidbook.support.android) {
+ if (!$("#q").is(':focus')) {
+ return;
+ }
+ $("#q").blur();
+ }
+ }
};