mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Drop JavaScript Frameworks (#10028)
* Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
This commit is contained in:
@@ -1,91 +1,41 @@
|
||||
var DOCUMENTATION_OPTIONS = {};
|
||||
const DOCUMENTATION_OPTIONS = {};
|
||||
|
||||
describe('highlightText', function() {
|
||||
|
||||
describe('jQuery extensions', function() {
|
||||
|
||||
describe('urldecode', function() {
|
||||
|
||||
it('should correctly decode URLs and replace `+`s with a spaces', function() {
|
||||
var test_encoded_string =
|
||||
'%D1%88%D0%B5%D0%BB%D0%BB%D1%8B+%D1%88%D0%B5%D0%BB%D0%BB%D1%8B';
|
||||
var test_decoded_string = 'шеллы шеллы';
|
||||
expect(jQuery.urldecode(test_encoded_string)).toEqual(test_decoded_string);
|
||||
});
|
||||
|
||||
it('+ should result in " "', function() {
|
||||
expect(jQuery.urldecode('+')).toEqual(' ');
|
||||
});
|
||||
const cyrillicTerm = 'шеллы';
|
||||
const umlautTerm = 'gänsefüßchen';
|
||||
|
||||
it('should highlight text incl. special characters correctly in HTML', function() {
|
||||
const highlightTestSpan = new DOMParser().parseFromString(
|
||||
'<span>This is the шеллы and Gänsefüßchen test!</span>', 'text/html').body.firstChild
|
||||
_highlightText(highlightTestSpan, cyrillicTerm, 'highlighted');
|
||||
_highlightText(highlightTestSpan, umlautTerm, 'highlighted');
|
||||
const expectedHtmlString =
|
||||
'This is the <span class=\"highlighted\">шеллы</span> and ' +
|
||||
'<span class=\"highlighted\">Gänsefüßchen</span> test!';
|
||||
expect(highlightTestSpan.innerHTML).toEqual(expectedHtmlString);
|
||||
});
|
||||
|
||||
describe('getQueryParameters', function() {
|
||||
var paramString = '?q=test+this&check_keywords=yes&area=default';
|
||||
var queryParamObject = {
|
||||
area: ['default'],
|
||||
check_keywords: ['yes'],
|
||||
q: ['test this']
|
||||
};
|
||||
|
||||
it('should correctly create query parameter object from string', function() {
|
||||
expect(jQuery.getQueryParameters(paramString)).toEqual(queryParamObject);
|
||||
});
|
||||
|
||||
it('should correctly create query param object from URL params', function() {
|
||||
history.pushState({}, '_', window.location + paramString);
|
||||
expect(jQuery.getQueryParameters()).toEqual(queryParamObject);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('highlightText', function() {
|
||||
|
||||
var cyrillicTerm = 'шеллы';
|
||||
var umlautTerm = 'gänsefüßchen';
|
||||
|
||||
it('should highlight text incl. special characters correctly in HTML', function() {
|
||||
var highlightTestSpan =
|
||||
jQuery('<span>This is the шеллы and Gänsefüßchen test!</span>');
|
||||
jQuery(document.body).append(highlightTestSpan);
|
||||
highlightTestSpan.highlightText(cyrillicTerm, 'highlighted');
|
||||
highlightTestSpan.highlightText(umlautTerm, 'highlighted');
|
||||
var expectedHtmlString =
|
||||
'This is the <span class=\"highlighted\">шеллы</span> and ' +
|
||||
'<span class=\"highlighted\">Gänsefüßchen</span> test!';
|
||||
expect(highlightTestSpan.html()).toEqual(expectedHtmlString);
|
||||
});
|
||||
|
||||
it('should highlight text incl. special characters correctly in SVG', function() {
|
||||
var highlightTestSvg = jQuery(
|
||||
'<span id="svg-highlight-test">' +
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">' +
|
||||
'<text x="0" y="15">' +
|
||||
'This is the шеллы and Gänsefüßchen test!' +
|
||||
'</text>' +
|
||||
'</svg>' +
|
||||
'</span>');
|
||||
jQuery(document.body).append(highlightTestSvg);
|
||||
highlightTestSvg.highlightText(cyrillicTerm, 'highlighted');
|
||||
highlightTestSvg.highlightText(umlautTerm, 'highlighted');
|
||||
/* Note wild cards and ``toMatch``; allowing for some variability
|
||||
seems to be necessary, even between different FF versions */
|
||||
var expectedSvgString =
|
||||
it('should highlight text incl. special characters correctly in SVG', function() {
|
||||
const highlightTestSvg = new DOMParser().parseFromString(
|
||||
'<span id="svg-highlight-test">' +
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">' +
|
||||
'<rect x=".*" y=".*" width=".*" height=".*" class="highlighted">' +
|
||||
'</rect>' +
|
||||
'<rect x=".*" y=".*" width=".*" height=".*" class="highlighted">' +
|
||||
'</rect>' +
|
||||
'<text x=".*" y=".*">' +
|
||||
'This is the ' +
|
||||
'<tspan>шеллы</tspan> and ' +
|
||||
'<tspan>Gänsefüßchen</tspan> test!' +
|
||||
'<text x="0" y="15">' +
|
||||
'This is the шеллы and Gänsefüßchen test!' +
|
||||
'</text>' +
|
||||
'</svg>';
|
||||
expect(highlightTestSvg.html()).toMatch(new RegExp(expectedSvgString));
|
||||
});
|
||||
|
||||
'</svg>' +
|
||||
'</span>', 'text/html').body.firstChild
|
||||
_highlightText(highlightTestSvg, cyrillicTerm, 'highlighted');
|
||||
_highlightText(highlightTestSvg, umlautTerm, 'highlighted');
|
||||
/* Note wild cards and ``toMatch``; allowing for some variability
|
||||
seems to be necessary, even between different FF versions */
|
||||
const expectedSvgString =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">'
|
||||
+ '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
|
||||
+ '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
|
||||
+ '<text x=".*" y=".*">This is the <tspan>шеллы</tspan> and '
|
||||
+ '<tspan>Gänsefüßchen</tspan> test!</text></svg>';
|
||||
expect(new XMLSerializer().serializeToString(highlightTestSvg.firstChild)).toMatch(new RegExp(expectedSvgString));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user