this.highlights = [];
this.highlightEnabled = fluidbook.datas.highlightResults;
this.resultPages = [];
+ this.plugins = [];
this.init();
}
res.push([k, v.t]);
}
+ for (var p in this.plugins) {
+ var plugin = this.plugins[p];
+ var h = plugin.getHints(q);
+ console.log(h);
+ res = res.concat(h);
+ }
+
res.sort(this.sortHints);
callback(res.slice(0, 12));
},
}
this.menuSearchHints.html('');
$.each(hints, function (k, v) {
- $this.menuSearchHints.append('<a class="hint" term="' + v[0] + '" href="#/search/' + v[0] + '">' + v[0] + '</a>');
+ var termType = 'word';
+ if (v.length > 2) {
+ termType = v[2];
+ }
+ $this.menuSearchHints.append('<a class="hint" data-termtype="' + termType + '" term="' + v[0] + '" href="#/search/' + termType + '/' + v[0] + '">' + v[0] + '</a>');
});
var qoffset = $("#q").offset();
var top = qoffset.top + $("#q").outerHeight() + 5;
$("#searchHints").css({top: top, left: left}).show();
},
+
killLastSearchHint: function () {
this.kill();
},
+
hideSearchHints: function () {
this.menuSearchHints.html('').hide(); // Clear and hide all hints
},
minScrollbarLength: 40,
//maxScrollbarLength: 60
});
- }
+ },
+ registerPlugin: function (p) {
+ this.plugins.push(p);
+ },
};
var wsref = {};
var normalizeRefCache = {};
+var allrefs = null;
$(function () {
if (fluidbook.datas.basket) {
}
function initWesco() {
+ fluidbook.search.registerPlugin(new WescoSalesSearchPlugin());
+
$(document).on('click', '[data-wescosales-ref]', function (e) {
setWescoSalesPanel($(this).data('wescosales-ref'), e);
return false;
setInteractPanel(ref, updateOnly);
}
+function getAllRefs() {
+ if (allrefs === null) {
+ var res = [];
+ for (var country in DATAS.basketReferences) {
+ var sheet = DATAS.basketReferences[country];
+ for (var linenum in sheet) {
+ var line = sheet[linenum];
+ var r = normalizeRef(line[0].toString());
+ if (res.indexOf(r) === -1) {
+ res.push(r);
+ }
+ }
+ }
+ allrefs = res;
+ }
+ return allrefs;
+}
+
function setInteractPanel(ref, onlyRect) {
if (onlyRect === undefined) {
onlyRect = false;
}
return wsref[ref];
}
+
+function WescoSalesSearchPlugin() {
+
+}
+
+WescoSalesSearchPlugin.prototype = {
+ getHints: function (q) {
+ if (!q.match(/(\d\s*)/gm)) {
+ return [];
+ }
+
+ q = q.replace(/\s/gm, '');
+
+ if (q.length > 5) {
+ return [];
+ }
+ var all = getAllRefs();
+ var res = [];
+ $.each(all, function (k, v) {
+ if (v.indexOf(q) === 0) {
+ res.push([v, 100000, 'ref']);
+ }
+ });
+
+ return res;
+ }
+};