Skip to content

Commit 9645ebd

Browse files
committed
DOCS-1829 - Search beta
1 parent ac3d7ab commit 9645ebd

File tree

6 files changed

+506
-631
lines changed

6 files changed

+506
-631
lines changed

Diff for: _static/customjs.js

-191
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
/* Layout File -- Start */
2-
// $(window).scroll(function () {
3-
// var scrollDistance = $(window).scrollTop();
4-
// // Assign active class to nav links while scolling
5-
// $('.bodywrapper .section a.headerlink').each(function (i) {
6-
// //console.log("$(this).position().top: " + $(this).position().top);
7-
// if ($(this).position().top <= scrollDistance) {
8-
// //console.log("aaaa");
9-
// $('.TOCL2 a.active').removeClass('active');
10-
// $('.TOCL2 a').eq(i).addClass('active');
11-
// }
12-
// });
13-
// }).scroll();
14-
151
$(document).ready(function () {
162

173

@@ -122,38 +108,6 @@ $(document).ready(function () {
122108
});
123109
// left Side TOC ====>>END
124110

125-
var modal = document.getElementById('myModal');
126-
127-
var span = document.getElementsByClassName("close")[0];
128-
129-
130-
$(".close").on("click", function () {
131-
//$("#myModal").css("display","none");
132-
$("#myModal").fadeOut("5000");
133-
134-
$("#searchQuery").val('');
135-
});
136-
137-
$("#searchQuery").keyup(function (event) {
138-
if (event.which === 13) {
139-
$("#modal-search-text").val('');
140-
var searchQueryVAL = $("#searchQuery").val();
141-
$("#modal-search-text").val(searchQueryVAL);
142-
$(".new-modal-header").css("border-bottom", "2px solid #33AAFF");
143-
144-
$("#searchbtn").click();
145-
}
146-
});
147-
148-
$("#modal-search-text").keyup(function (event) {
149-
if (event.which === 13) {
150-
var modal_search_text_val = $("#modal-search-text").val();
151-
152-
$("#searchQuery").val(modal_search_text_val);
153-
$("#searchbtn").click();
154-
}
155-
});
156-
157111
$("#mainTOC .sphinxsidebarwrapper ul li.toctree-l1 a, #mobileSideBar .sphinxsidebarwrapper ul li.toctree-l1 a").each(function () {
158112

159113
//var achorHtml = $(this).html()
@@ -190,151 +144,6 @@ $(document).ready(function () {
190144
$(this).next('a').get(0).click();
191145
});
192146

193-
$("#searchbtn").click(function () {
194-
//$(".popup-overlay, .popup-content").addClass("active");
195-
// $("#myModal").css("display","block");
196-
$("#myModal").fadeIn("5000");
197-
198-
var searchQuery = $("#searchQuery").val();
199-
200-
201-
$("#modal-search-text").focus();
202-
203-
if (searchQuery) {
204-
var query = searchQuery;
205-
206-
//var docssearchApiUrl = 'https://docs.staging.splunk.com/api/userutility/observabilitysearch';
207-
var docssearchApiUrl = 'https://docs.splunk.com/api/userutility/observabilitysearch?query=' + query + '&offset=0&limit=100';
208-
console.info("URL:", docssearchApiUrl);
209-
$('#search-progress').text(_('Preparing search...'));
210-
$(".new-modal-header").css("display", "none");
211-
$(".new-modal-footer").css("display", "none");
212-
$("#search-results").empty();
213-
$('.page_navigation').empty();
214-
215-
$.post(docssearchApiUrl, {query: query})
216-
.done(function (data) {
217-
var items = [];
218-
var jsonResult = JSON.parse(data);
219-
var jsonResultCount = jsonResult.data[0].message.results.length;
220-
var jsonResultSet = jsonResult.data[0].message.results;
221-
222-
// var items = '<div class="searchSummary"><h2>Search Results</h2><p class="search-summary">Search finished, found '+jsonResultCount+' page(s) matching the search query.</p></div>';
223-
// items += '<ul class="search" style="overflow-y:scroll; height:376px">';
224-
var show_search_result_count = 'Showing ' + jsonResultCount + ' result(s) for "' + query + '"';
225-
$(".search-result-count").html(show_search_result_count);
226-
227-
var items = '<ul class="search"> ';
228-
229-
$.each(jsonResult.data[0].message.results, function (key, val) {
230-
items += '<li class="search-li" style="text-align: left; margin-right: 25px;"><a class="search-title-link" href=' + val['link'] + '>' + val['title'] + '</a><div class="context search-context" style="text-align:justify; margin-left:0px;">' + val['description'] + '</div></li>';
231-
232-
});
233-
234-
items += '</ul></div>';
235-
// const sample = jsonResult[0]['message'][0]['results'][0]['title'];
236-
console.info("sample: ", items);
237-
$('#search-progress').empty();
238-
$(".new-modal-header").css("display", "block");
239-
$(".new-modal-footer").css("display", "block");
240-
$("#search-results").html(items);
241-
242-
var maxLength = 180;
243-
$(".search-context").each(function () {
244-
var myStr = $(this).text();
245-
246-
if ($.trim(myStr).length > maxLength) {
247-
var newStr = myStr.substring(0, maxLength) + "...";
248-
var removedStr = myStr.substring(maxLength, $.trim(myStr).length);
249-
$(this).empty().html(newStr);
250-
}
251-
});
252-
showPage(1);
253-
// console.info("DATAAAA: ", jsonResult.data[0].message.results);
254-
}).fail(function () {
255-
$('#search-progress').empty();
256-
var noResult = "<h2>No Result Found</h2>";
257-
$("#search-results").html(noResult);
258-
console.info("NO DATA");
259-
});
260-
} else {
261-
var noResult = "<div style='text-align:center;'><h2>No Result Found</h2></div>";
262-
$("#modal-search-text").val('');
263-
$("#search-results").html(noResult);
264-
$(".search-result-count").empty();
265-
$('.page_navigation').empty();
266-
console.info("NO DATA");
267-
}
268-
269-
return false;
270-
271-
});
272-
273-
makePager = function (page) {
274-
var show_per_page = 10;
275-
var number_of_items = $('#search-results ul li').length;
276-
var number_of_pages = Math.ceil(number_of_items / show_per_page);
277-
var number_of_pages_todisplay = 5;
278-
var navigation_html = '';
279-
var current_page = page;
280-
var current_link = (number_of_pages_todisplay >= current_page ? 1 : number_of_pages_todisplay + 1);
281-
if (current_page > 1)
282-
current_link = current_page;
283-
//if (current_link != 1) navigation_html += "<a class='nextbutton' href=\"javascript:first();\">« Start&nbsp;</a>&nbsp;<a class='nextbutton' href=\"javascript:previous();\">« Prev&nbsp;</a>&nbsp;";
284-
if (current_link != 1) navigation_html += "<a class='nextbutton' href=\"javascript:previous();\">« Prev&nbsp;</a>&nbsp;";
285-
if (current_link == number_of_pages - 1) current_link = current_link - 3;
286-
else if (current_link == number_of_pages) current_link = current_link - 4;
287-
else if (current_link > 2) current_link = current_link - 2;
288-
else current_link = 1;
289-
var pages = number_of_pages_todisplay;
290-
while (pages != 0) {
291-
if (number_of_pages < current_link) {
292-
break;
293-
}
294-
if (current_link >= 1)
295-
navigation_html += "<a class='" + ((current_link == current_page) ? "currentPageButton" : "numericButton") + "' href=\"javascript:showPage(" + current_link + ")\" longdesc='" + current_link + "'>" + (current_link) + "</a>&nbsp;";
296-
current_link++;
297-
pages--;
298-
}
299-
if (number_of_pages > current_page) {
300-
//navigation_html += "<a class='nextbutton' href=\"javascript:next()\">Next »</a>&nbsp;<a class='nextbutton' href=\"javascript:last(" + number_of_pages + ");\">Last »</a>";
301-
navigation_html += "<a class='nextbutton' href=\"javascript:next()\">Next »</a>";
302-
}
303-
$('.page_navigation').html(navigation_html);
304-
}
305-
var pageSize = 10;
306-
showPage = function (page) {
307-
console.info("page: ", page);
308-
$("#search-results ul li").hide();
309-
$('#current_page').val(page);
310-
$("#search-results ul li").each(function (n) {
311-
console.info("NUM: ", n);
312-
if (n >= pageSize * (page - 1) && n < pageSize * page)
313-
$(this).show();
314-
});
315-
makePager(page);
316-
}
317-
318-
next = function () {
319-
new_page = parseInt($('#current_page').val()) + 1;
320-
showPage(new_page);
321-
}
322-
last = function (number_of_pages) {
323-
new_page = number_of_pages;
324-
$('#current_page').val(new_page);
325-
showPage(new_page);
326-
}
327-
first = function () {
328-
var new_page = "1";
329-
$('#current_page').val(new_page);
330-
showPage(new_page);
331-
}
332-
previous = function () {
333-
new_page = parseInt($('#current_page').val()) - 1;
334-
$('#current_page').val(new_page);
335-
showPage(new_page);
336-
}
337-
338147
});
339148

340149

0 commit comments

Comments
 (0)