on master help sign in
Mobile search fix
c36eab8francescanarea
static/scripts.js+4−37
@@ -1,7 +1,4 @@
1−//
2− // styling of input fields
1+// styling of input fields
3−//
4−
5var inputElements = document.querySelectorAll('input.tlon-input');
2var inputElements = document.querySelectorAll('input.tlon-input');
6for (var i = 0; i < inputElements.length; i++) {
3for (var i = 0; i < inputElements.length; i++) {
7 //listen for changes in input
4 //listen for changes in input
@@ -30,10 +27,7 @@ for (var i = 0; i < inputElements.length; i++) {
30 });
27 });
31}
28}
32
29
33−//
34− // toggling of navigation menus
30+// toggling of navigation menus
35−//
36−
37var toggleMainNav = document.getElementById('js-main-nav-toggle');
31var toggleMainNav = document.getElementById('js-main-nav-toggle');
38if (toggleMainNav !== null) {
32if (toggleMainNav !== null) {
39 toggleMainNav.onclick = function() {
33 toggleMainNav.onclick = function() {
@@ -48,20 +42,6 @@ if (toggleContentNav !== null) {
48 }
42 }
49}
43}
50
44
51−/*function initToggleMenu() {
52− var menu = document.querySelector(".menu");
53− var menuIcon = document.querySelector(".menu-icon");
54− var page = document.querySelector(".page");
55− menuIcon.addEventListener("click", function() {
56− menu.classList.toggle("menu-hidden");
57− page.classList.toggle("page-without-menu");
58− });
59−}*/
60−
61−//
62− // hotkeys
63−//
64−
65function initHotKeys() {
45function initHotKeys() {
66
46
67 var bodyEl = document.body;
47 var bodyEl = document.body;
@@ -98,10 +78,8 @@ function initHotKeys() {
98 });
78 });
99};
79};
100
80
101−//
102− // search functionality
103−//
104
81
82+// search functionality
105function debounce(func, wait) {
83function debounce(func, wait) {
106 var timeout;
84 var timeout;
107
85
@@ -135,19 +113,10 @@ function makeTeaser(body, terms) {
135 //var TEASER_MAX_WORDS = 17;
113 //var TEASER_MAX_WORDS = 17;
136 var TEASER_MAX_CHARS = 63;
114 var TEASER_MAX_CHARS = 63;
137
115
138−
139 var stemmedTerms = terms.map(function (w) {
116 var stemmedTerms = terms.map(function (w) {
140 return elasticlunr.stemmer(w.toLowerCase());
117 return elasticlunr.stemmer(w.toLowerCase());
141 });
118 });
142
119
143− console.log(stemmedTerms);
144− // create array with full word + partial Words (smallest fragment is 2 characters)
145− // first iteration is full word, then next is subset of the original word
146− /*var stemmedTerms = [];
147− for (var i = terms[0].length; i>=2; i--) {
148− stemmedTerms.push(terms[0].substring(0,i));
149− }
150− console.log(stemmedTerms);*/
151 var termFound = false;
120 var termFound = false;
152 var index = 0;
121 var index = 0;
153 var weighted = []; // contains elements of ["word", weight, index_in_document]
122 var weighted = []; // contains elements of ["word", weight, index_in_document]
@@ -290,7 +259,7 @@ function initSearch() {
290
259
291 var options = {
260 var options = {
292 bool: "AND",
261 bool: "AND",
293− expand: true,
262+ expand: true, // turn on partial word search
294 fields: {
263 fields: {
295 title: {boost: 2},
264 title: {boost: 2},
296 body: {boost: 1},
265 body: {boost: 1},
@@ -342,8 +311,6 @@ function initSearch() {
342 return;
311 return;
343 }
312 }
344
313
345− // change query in order to make partial words work
346−
347 var results = index.search(term, options).filter(function (r) {
314 var results = index.search(term, options).filter(function (r) {
348 return r.doc.body !== "";
315 return r.doc.body !== "";
349 });
316 });
templates/partials/navigation-docs.html+3−1
@@ -1,8 +1,10 @@
1{% block content %}
1{% block content %}
2<div id="js-content-nav-toggle" class="content-nav-icon"></div>
2<div id="js-content-nav-toggle" class="content-nav-icon"></div>
3<nav class="content-nav">
3<nav class="content-nav">
4− <button id="js-search-window-toggle" type="button" class="search-bar content-nav__search-bar mb2">Search</button>
5 <ul class="list content-nav__index">
4 <ul class="list content-nav__index">
5+ <li class="list__item content-nav__index__item">
6+ <button id="js-search-window-toggle" type="button" class="search-bar content-nav__search-bar mb2">Search</button>
7+ </li>
6 {% block menu %}
8 {% block menu %}
7 {% set index = get_section(path="docs/_index.md") %}
9 {% set index = get_section(path="docs/_index.md") %}
8 {% for s in index.subsections %}
10 {% for s in index.subsections %}