From afc22c6215a7201f7041065a4b315b98034ba1aa Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 15 Jul 2021 16:15:07 -0400 Subject: [PATCH] vendor searchtools.js this is to work around https://github.com/sphinx-doc/sphinx/issues/9456 which is emitting dozens of unused network calls on search --- zzzeeksphinx/__init__.py | 2 +- .../themes/zsbase/static/searchtools.js | 525 ++++++++++++++++++ 2 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 zzzeeksphinx/themes/zsbase/static/searchtools.js diff --git a/zzzeeksphinx/__init__.py b/zzzeeksphinx/__init__.py index 6e23fd1..94f9cf3 100644 --- a/zzzeeksphinx/__init__.py +++ b/zzzeeksphinx/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.2.4" +__version__ = "1.2.5" def setup(app): diff --git a/zzzeeksphinx/themes/zsbase/static/searchtools.js b/zzzeeksphinx/themes/zsbase/static/searchtools.js new file mode 100644 index 0000000..75e1f2e --- /dev/null +++ b/zzzeeksphinx/themes/zsbase/static/searchtools.js @@ -0,0 +1,525 @@ +/* + * searchtools.js + * ~~~~~~~~~~~~~~~~ + * + * Sphinx JavaScript utilities for the full-text search. + * + * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. + * :license: BSD, see LICENSE for details. + * + * NOTE: edited by zzzeek for + * https://github.com/sphinx-doc/sphinx/issues/9456 + * + */ + +if (!Scorer) { + /** + * Simple result scoring code. + */ + var Scorer = { + // Implement the following function to further tweak the score for each result + // The function takes a result array [filename, title, anchor, descr, score] + // and returns the new score. + /* + score: function(result) { + return result[4]; + }, + */ + + // query matches the full name of an object + objNameMatch: 11, + // or matches in the last dotted part of the object name + objPartialMatch: 6, + // Additive scores depending on the priority of the object + objPrio: {0: 15, // used to be importantResults + 1: 5, // used to be objectResults + 2: -5}, // used to be unimportantResults + // Used when the priority is not in the mapping. + objPrioDefault: 0, + + // query found in title + title: 15, + partialTitle: 7, + // query found in terms + term: 5, + partialTerm: 2 + }; +} + +if (!splitQuery) { + function splitQuery(query) { + return query.split(/\s+/); + } +} + +/** + * Search Module + */ +var Search = { + + _index : null, + _queued_query : null, + _pulse_status : -1, + + htmlToText : function(htmlString) { + var virtualDocument = document.implementation.createHTMLDocument('virtual'); + var htmlElement = $(htmlString, virtualDocument); + htmlElement.find('.headerlink').remove(); + docContent = htmlElement.find('[role=main]')[0]; + if(docContent === undefined) { + console.warn("Content block not found. Sphinx search tries to obtain it " + + "via '[role=main]'. Could you check your theme or template."); + return ""; + } + return docContent.textContent || docContent.innerText; + }, + + init : function() { + var params = $.getQueryParameters(); + if (params.q) { + var query = params.q[0]; + $('input[name="q"]')[0].value = query; + this.performSearch(query); + } + }, + + loadIndex : function(url) { + $.ajax({type: "GET", url: url, data: null, + dataType: "script", cache: true, + complete: function(jqxhr, textstatus) { + if (textstatus != "success") { + document.getElementById("searchindexloader").src = url; + } + }}); + }, + + setIndex : function(index) { + var q; + this._index = index; + if ((q = this._queued_query) !== null) { + this._queued_query = null; + Search.query(q); + } + }, + + hasIndex : function() { + return this._index !== null; + }, + + deferQuery : function(query) { + this._queued_query = query; + }, + + stopPulse : function() { + this._pulse_status = 0; + }, + + startPulse : function() { + if (this._pulse_status >= 0) + return; + function pulse() { + var i; + Search._pulse_status = (Search._pulse_status + 1) % 4; + var dotString = ''; + for (i = 0; i < Search._pulse_status; i++) + dotString += '.'; + Search.dots.text(dotString); + if (Search._pulse_status > -1) + window.setTimeout(pulse, 500); + } + pulse(); + }, + + /** + * perform a search for something (or wait until index is loaded) + */ + performSearch : function(query) { + // create the required interface elements + this.out = $('#search-results'); + this.title = $('

' + _('Searching') + '

').appendTo(this.out); + this.dots = $('').appendTo(this.title); + this.status = $('

 

').appendTo(this.out); + this.output = $('