8000 Use local jQuery source · sphinx-contrib/jquery@e76b2d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e76b2d0

Browse files
committed
Use local jQuery source
- Vendor jQuery within the extension - Include the Sphinx compatability file - Update tests
1 parent 5995de9 commit e76b2d0

8 files changed

+11070
-38
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Release 3.0.0 (in development)
2+
==============================
3+
4+
* Vendor jQuery within the extension and copy the files to the documentation's
5+
``_static`` directory.
6+
* Include the ``_sphinx_javascript_frameworks_compat.js`` compatibility file
7+
from Sphinx 5.
8+
19
Release 2.0.0 (18/10/2022)
210
==========================
311

sphinxcontrib/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

sphinxcontrib/jquery.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

sphinxcontrib/jquery/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from os import makedirs, 8000 path
2+
import shutil
3+
4+
import sphinx
5+
6+
__version__ = "2.0.0"
7+
version_info = (2, 0, 0)
8+
9+
_ROOT_DIR = path.abspath(path.dirname(__file__))
10+
11+
12+
def setup(app):
13+
jquery_installed = getattr(app, "_sphinxcontrib_jquery_installed", False)
14+
if sphinx.version_info[:2] >= (6, 0) and not jquery_installed:
15+
makedirs(path.join(app.outdir, '_static'))
16+
for filename in (
17+
'jquery.js',
18+
'_sphinx_javascript_frameworks_compat.js',
19+
):
20+
app.add_js_file(filename, priority=100)
21+
shutil.copyfile(
22+
path.join(_ROOT_DIR, filename),
23+
path.join(app.outdir, '_static', filename)
24+
)
25+
app._sphinxcontrib_jquery_installed = True
26+
27+
return {
28+
"parallel_read_safe": True,
29+
"parallel_write_safe": True,
30+
"version": __version__,
31+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* Compatability shim for jQuery and underscores.js.
2+
*
3+
* Copyright Sphinx contributors
4+
* Released under the two clause BSD licence
5+
*/
6+
7+
/**
8+
* small helper function to urldecode strings
9+
*
10+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL
11+
*/
12+
jQuery.urldecode = function(x) {
13+
if (!x) {
14+
return x
15+
}
16+
return decodeURIComponent(x.replace(/\+/g, ' '));
17+
};
18+
19+
/**
20+
* small helper function to urlencode strings
21+
*/
22+
jQuery.urlencode = encodeURIComponent;
23+
24+
/**
25+
* This function returns the parsed url parameters of the
26+
* current request. Multiple values per key are supported,
27+
* it will always return arrays of strings for the value parts.
28+
*/
29+
jQuery.getQueryParameters = function(s) {
30+
if (typeof s === 'undefined')
31+
s = document.location.search;
32+
var parts = s.substr(s.indexOf('?') + 1).split('&');
33+
var result = {};
34+
for (var i = 0; i < parts.length; i++) {
35+
var tmp = parts[i].split('=', 2);
36+
var key = jQuery.urldecode(tmp[0]);
37+
var value = jQuery.urldecode(tmp[1]);
38+
if (key in result)
39+
result[key].push(value);
40+
else
41+
result[key] = [value];
42+
}
43+
return result;
44+
};
45+
46+
/**
47+
* highlight a given string on a jquery object by wrapping it in
48+
* span elements with the given class name.
49+
*/
50+
jQuery.fn.highlightText = function(text, className) {
51+
function highlight(node, addItems) {
52+
if (node.nodeType === 3) {
53+
var val = node.nodeValue;
54+
var pos = val.toLowerCase().indexOf(text);
55+
if (pos >= 0 &&
56+
!jQuery(node.parentNode).hasClass(className) &&
57+
!jQuery(node.parentNode).hasClass("nohighlight")) {
58+
var span;
59+
var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
60+
if (isInSVG) {
61+
span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
62+
} else {
63+
span = document.createElement("span");
64+
span.className = className;
65+
}
66+
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
67+
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
68+
document.createTextNode(val.substr(pos + text.length)),
69+
node.nextSibling));
70+
node.nodeValue = val.substr(0, pos);
71+
if (isInSVG) {
72+
var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
73+
var bbox = node.parentElement.getBBox();
74+
rect.x.baseVal.value = bbox.x;
75+
rect.y.baseVal.value = bbox.y;
76+
rect.width.baseVal.value = bbox.width;
77+
rect.height.baseVal.value = bbox.height;
78+
rect.setAttribute('class', className);
79+
addItems.push({
80+
"parent": node.parentNode,
81+
"target": rect});
82+
}
83+
}
84+
}
85+
else if (!jQuery(node).is("button, select, textarea")) {
86+
jQuery.each(node.childNodes, function() {
87+
highlight(this, addItems);
88+
});
89+
}
90+
}
91+
var addItems = [];
92+
var result = this.each(function() {
93+
highlight(this, addItems);
94+
});
95+
for (var i = 0; i < addItems.length; ++i) {
96+
jQuery(addItems[i].parent).before(addItems[i].target);
97+
}
98+
return result;
99+
};
100+
101+
/*
102+
* backward compatibility for jQuery.browser
103+
* This will be supported until firefox bug is fixed.
104+
*/
105+
if (!jQuery.browser) {
106+
jQuery.uaMatch = function(ua) {
107+
ua = ua.toLowerCase();
108+
109+
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
110+
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
111+
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
112+
/(msie) ([\w.]+)/.exec(ua) ||
113+
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
114+
[];
115+
116+
return {
117+
browser: match[ 1 ] || "",
118+
version: match[ 2 ] || "0"
119+
};
120+
};
121+
jQuery.browser = {};
122+
jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
123+
}

0 commit comments

Comments
 (0)
0