Skip to content

Commit 05fa66c

Browse files
committed
Remove AI code; update package.json
1 parent 4a4d012 commit 05fa66c

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

assets/script/search.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var searchIndexUrl = "https://typespublisher.blob.core.windows.net/typespublisher/data/search-index-min.json";
2+
function typeSearch(el) {
3+
var jqueryEl = $(el);
4+
var opts = {
5+
highlight: true,
6+
minLength: 0
7+
};
8+
var data = {
9+
source: createDataSource(),
10+
displayKey: 't',
11+
templates: {
12+
suggestion: function (obj) {
13+
return "<div class=\"suggestion\">\n\t\t\t\t\t\t<span class=\"type-package-name\">" + obj.t + "</span>\n\t\t\t\t\t\t<span class=\"library-name\">" + obj.l + "</span>\n\t\t\t\t\t\t</div>";
14+
}
15+
}
16+
};
17+
jqueryEl.typeahead(opts, data);
18+
jqueryEl.on('typeahead:select', function (unused, obj) { return navigate(obj); });
19+
jqueryEl.keyup(function (k) {
20+
if (k.keyCode === 13) {
21+
var selectables = jqueryEl.siblings(".tt-menu").find(".tt-selectable");
22+
$(selectables[0]).trigger("click");
23+
}
24+
});
25+
function navigate(record) {
26+
window.location.href = "https://www.npmjs.org/package/@types/" + record.t;
27+
}
28+
function createDataSource() {
29+
var query = "";
30+
return new Bloodhound({
31+
// See https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md#options
32+
prefetch: searchIndexUrl,
33+
datumTokenizer: function (entry) {
34+
return [entry.l, entry.p, entry.t].concat(entry.g).concat(entry.m);
35+
},
36+
queryTokenizer: function (input) {
37+
query = input;
38+
return [input];
39+
},
40+
identify: function (e) { return e.t; },
41+
sorter: function (x, y) {
42+
// TODO: Include edit distance as additional weighting factor
43+
// Direct matches should be ranked higher, else rank on basis of download count
44+
if (x.t === query || x.t === (query + "js") || x.t === (query + ".js") || x.t === (query + "-js")) {
45+
return -1;
46+
}
47+
else if (y.t === query || y.t === (query + "js") || y.t === (query + ".js") || y.t === (query + "-js")) {
48+
return 1;
49+
}
50+
else {
51+
return y.d - x.d;
52+
}
53+
}
54+
});
55+
}
56+
}

assets/script/search.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
interface Window {
2-
appInsights: any;
3-
}
4-
const ai = window.appInsights;
5-
61
const searchIndexUrl = "https://typespublisher.blob.core.windows.net/typespublisher/data/search-index-min.json";
72

83
interface MinifiedSearchRecord {
@@ -53,15 +48,7 @@ function typeSearch(el: HTMLInputElement) {
5348
}
5449
});
5550

56-
jqueryEl.focus(() => {
57-
ai.trackEvent('focus');
58-
});
59-
6051
function navigate(record: MinifiedSearchRecord) {
61-
if (ai) {
62-
ai.trackEvent('navigate', { target: record.t });
63-
}
64-
6552
window.location.href = `https://www.npmjs.org/package/@types/${record.t}`;
6653
}
6754

assets/static/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico">
77
<link rel="stylesheet" href="demo.css">
88
<link rel="stylesheet" href="style.css">
9-
<script type="text/javascript">var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t }({ instrumentationKey:"22fd7b1b-c238-412c-8844-887a2ffb1459" }); window.appInsights=appInsights; appInsights.trackPageView();</script>
109
<script src="lib/jquery.min.js"></script>
1110
<script src="lib/typeahead.bundle.min.js"></script>
1211
<script src="script/search.js"></script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"compile-gulpfile": "./node_modules/typescript/bin/tsc",
7+
"compile-gulpfile": "tsc -p .",
88
"build": "npm run compile-gulpfile && node node_modules/gulp/bin/gulp.js build",
99
"test": "echo \"Error: no test specified\" && exit 1"
1010
},

0 commit comments

Comments
 (0)