source: ammosreader/doc/html/_static/doctools.js@ 299c79c

AmmosSource guix
Last change on this file since 299c79c was 299c79c, checked in by Enrico Schwass <ennoausberlin@…>, 3 years ago

sphinx-apidoc run

  • Property mode set to 100644
File size: 10.5 KB
Line 
1/*
2 * doctools.js
3 * ~~~~~~~~~~~
4 *
5 * Sphinx JavaScript utilities for all documentation.
6 *
7 * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
8 * :license: BSD, see LICENSE for details.
9 *
10 */
11
12/**
13 * select a different prefix for underscore
14 */
15$u = _.noConflict();
16
17/**
18 * make the code below compatible with browsers without
19 * an installed firebug like debugger
20if (!window.console || !console.firebug) {
21 var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
22 "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
23 "profile", "profileEnd"];
24 window.console = {};
25 for (var i = 0; i < names.length; ++i)
26 window.console[names[i]] = function() {};
27}
28 */
29
30/**
31 * small helper function to urldecode strings
32 *
33 * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL
34 */
35jQuery.urldecode = function(x) {
36 if (!x) {
37 return x
38 }
39 return decodeURIComponent(x.replace(/\+/g, ' '));
40};
41
42/**
43 * small helper function to urlencode strings
44 */
45jQuery.urlencode = encodeURIComponent;
46
47/**
48 * This function returns the parsed url parameters of the
49 * current request. Multiple values per key are supported,
50 * it will always return arrays of strings for the value parts.
51 */
52jQuery.getQueryParameters = function(s) {
53 if (typeof s === 'undefined')
54 s = document.location.search;
55 var parts = s.substr(s.indexOf('?') + 1).split('&');
56 var result = {};
57 for (var i = 0; i < parts.length; i++) {
58 var tmp = parts[i].split('=', 2);
59 var key = jQuery.urldecode(tmp[0]);
60 var value = jQuery.urldecode(tmp[1]);
61 if (key in result)
62 result[key].push(value);
63 else
64 result[key] = [value];
65 }
66 return result;
67};
68
69/**
70 * highlight a given string on a jquery object by wrapping it in
71 * span elements with the given class name.
72 */
73jQuery.fn.highlightText = function(text, className) {
74 function highlight(node, addItems) {
75 if (node.nodeType === 3) {
76 var val = node.nodeValue;
77 var pos = val.toLowerCase().indexOf(text);
78 if (pos >= 0 &&
79 !jQuery(node.parentNode).hasClass(className) &&
80 !jQuery(node.parentNode).hasClass("nohighlight")) {
81 var span;
82 var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
83 if (isInSVG) {
84 span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
85 } else {
86 span = document.createElement("span");
87 span.className = className;
88 }
89 span.appendChild(document.createTextNode(val.substr(pos, text.length)));
90 node.parentNode.insertBefore(span, node.parentNode.insertBefore(
91 document.createTextNode(val.substr(pos + text.length)),
92 node.nextSibling));
93 node.nodeValue = val.substr(0, pos);
94 if (isInSVG) {
95 var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
96 var bbox = node.parentElement.getBBox();
97 rect.x.baseVal.value = bbox.x;
98 rect.y.baseVal.value = bbox.y;
99 rect.width.baseVal.value = bbox.width;
100 rect.height.baseVal.value = bbox.height;
101 rect.setAttribute('class', className);
102 addItems.push({
103 "parent": node.parentNode,
104 "target": rect});
105 }
106 }
107 }
108 else if (!jQuery(node).is("button, select, textarea")) {
109 jQuery.each(node.childNodes, function() {
110 highlight(this, addItems);
111 });
112 }
113 }
114 var addItems = [];
115 var result = this.each(function() {
116 highlight(this, addItems);
117 });
118 for (var i = 0; i < addItems.length; ++i) {
119 jQuery(addItems[i].parent).before(addItems[i].target);
120 }
121 return result;
122};
123
124/*
125 * backward compatibility for jQuery.browser
126 * This will be supported until firefox bug is fixed.
127 */
128if (!jQuery.browser) {
129 jQuery.uaMatch = function(ua) {
130 ua = ua.toLowerCase();
131
132 var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
133 /(webkit)[ \/]([\w.]+)/.exec(ua) ||
134 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
135 /(msie) ([\w.]+)/.exec(ua) ||
136 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
137 [];
138
139 return {
140 browser: match[ 1 ] || "",
141 version: match[ 2 ] || "0"
142 };
143 };
144 jQuery.browser = {};
145 jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
146}
147
148/**
149 * Small JavaScript module for the documentation.
150 */
151var Documentation = {
152
153 init : function() {
154 this.fixFirefoxAnchorBug();
155 this.highlightSearchWords();
156 this.initIndexTable();
157 this.initOnKeyListeners();
158 },
159
160 /**
161 * i18n support
162 */
163 TRANSLATIONS : {},
164 PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; },
165 LOCALE : 'unknown',
166
167 // gettext and ngettext don't access this so that the functions
168 // can safely bound to a different name (_ = Documentation.gettext)
169 gettext : function(string) {
170 var translated = Documentation.TRANSLATIONS[string];
171 if (typeof translated === 'undefined')
172 return string;
173 return (typeof translated === 'string') ? translated : translated[0];
174 },
175
176 ngettext : function(singular, plural, n) {
177 var translated = Documentation.TRANSLATIONS[singular];
178 if (typeof translated === 'undefined')
179 return (n == 1) ? singular : plural;
180 return translated[Documentation.PLURALEXPR(n)];
181 },
182
183 addTranslations : function(catalog) {
184 for (var key in catalog.messages)
185 this.TRANSLATIONS[key] = catalog.messages[key];
186 this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
187 this.LOCALE = catalog.locale;
188 },
189
190 /**
191 * add context elements like header anchor links
192 */
193 addContextElements : function() {
194 $('div[id] > :header:first').each(function() {
195 $('<a class="headerlink">\u00B6</a>').
196 attr('href', '#' + this.id).
197 attr('title', _('Permalink to this headline')).
198 appendTo(this);
199 });
200 $('dt[id]').each(function() {
201 $('<a class="headerlink">\u00B6</a>').
202 attr('href', '#' + this.id).
203 attr('title', _('Permalink to this definition')).
204 appendTo(this);
205 });
206 },
207
208 /**
209 * workaround a firefox stupidity
210 * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075
211 */
212 fixFirefoxAnchorBug : function() {
213 if (document.location.hash && $.browser.mozilla)
214 window.setTimeout(function() {
215 document.location.href += '';
216 }, 10);
217 },
218
219 /**
220 * highlight the search words provided in the url in the text
221 */
222 highlightSearchWords : function() {
223 var params = $.getQueryParameters();
224 var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
225 if (terms.length) {
226 var body = $('div.body');
227 if (!body.length) {
228 body = $('body');
229 }
230 window.setTimeout(function() {
231 $.each(terms, function() {
232 body.highlightText(this.toLowerCase(), 'highlighted');
233 });
234 }, 10);
235 $('<p class="highlight-link"><a href="javascript:Documentation.' +
236 'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
237 .appendTo($('#searchbox'));
238 }
239 },
240
241 /**
242 * init the domain index toggle buttons
243 */
244 initIndexTable : function() {
245 var togglers = $('img.toggler').click(function() {
246 var src = $(this).attr('src');
247 var idnum = $(this).attr('id').substr(7);
248 $('tr.cg-' + idnum).toggle();
249 if (src.substr(-9) === 'minus.png')
250 $(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
251 else
252 $(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
253 }).css('display', '');
254 if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
255 togglers.click();
256 }
257 },
258
259 /**
260 * helper function to hide the search marks again
261 */
262 hideSearchWords : function() {
263 $('#searchbox .highlight-link').fadeOut(300);
264 $('span.highlighted').removeClass('highlighted');
265 var url = new URL(window.location);
266 url.searchParams.delete('highlight');
267 window.history.replaceState({}, '', url);
268 },
269
270 /**
271 * helper function to focus on search bar
272 */
273 focusSearchBar : function() {
274 $('input[name=q]').first().focus();
275 },
276
277 /**
278 * make the url absolute
279 */
280 makeURL : function(relativeURL) {
281 return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
282 },
283
284 /**
285 * get the current relative url
286 */
287 getCurrentURL : function() {
288 var path = document.location.pathname;
289 var parts = path.split(/\//);
290 $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
291 if (this === '..')
292 parts.pop();
293 });
294 var url = parts.join('/');
295 return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
296 },
297
298 initOnKeyListeners: function() {
299 // only install a listener if it is really needed
300 if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
301 !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
302 return;
303
304 $(document).keydown(function(event) {
305 var activeElementType = document.activeElement.tagName;
306 // don't navigate when in search box, textarea, dropdown or button
307 if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
308 && activeElementType !== 'BUTTON') {
309 if (event.altKey || event.ctrlKey || event.metaKey)
310 return;
311
312 if (!event.shiftKey) {
313 switch (event.key) {
314 case 'ArrowLeft':
315 if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
316 break;
317 var prevHref = $('link[rel="prev"]').prop('href');
318 if (prevHref) {
319 window.location.href = prevHref;
320 return false;
321 }
322 break;
323 case 'ArrowRight':
324 if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
325 break;
326 var nextHref = $('link[rel="next"]').prop('href');
327 if (nextHref) {
328 window.location.href = nextHref;
329 return false;
330 }
331 break;
332 case 'Escape':
333 if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
334 break;
335 Documentation.hideSearchWords();
336 return false;
337 }
338 }
339
340 // some keyboard layouts may need Shift to get /
341 switch (event.key) {
342 case '/':
343 if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
344 break;
345 Documentation.focusSearchBar();
346 return false;
347 }
348 }
349 });
350 }
351};
352
353// quick alias for translations
354_ = Documentation.gettext;
355
356$(document).ready(function() {
357 Documentation.init();
358});
Note: See TracBrowser for help on using the repository browser.