From 5df66809bcfbea35fcda1513c577470da1b4dbc9 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 5 May 2017 11:56:18 +0200 Subject: [PATCH] Workaround for RTD search For details, see https://github.com/rtfd/readthedocs.org/issues/1487 FIX #153 --- docs/extra/extra.css | 8 +++ docs/extra/extra.js | 57 +++++++++++++++++++++ docs/references/features-cross-reference.md | 2 +- mkdocs.yml | 11 ++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 docs/extra/extra.css create mode 100644 docs/extra/extra.js create mode 100644 mkdocs.yml diff --git a/docs/extra/extra.css b/docs/extra/extra.css new file mode 100644 index 00000000..2addeb79 --- /dev/null +++ b/docs/extra/extra.css @@ -0,0 +1,8 @@ +/* Make the huge table always visible */ +table.features-cross-reference { + overflow: visible !important; +} +.rst-content table.features-cross-reference.docutils th, +.rst-content table.features-cross-reference.docutils td { + background-color: white; +} diff --git a/docs/extra/extra.js b/docs/extra/extra.js new file mode 100644 index 00000000..fdef958f --- /dev/null +++ b/docs/extra/extra.js @@ -0,0 +1,57 @@ +var nodemcu = nodemcu || {}; +(function () { + 'use strict'; + + $(document).ready(function () { + fixSearch(); + }); + + /* + * RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see + * https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver + * to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything + * the RTD JS code modified. + */ + function fixSearch() { + var target = document.getElementById('rtd-search-form'); + var config = {attributes: true, childList: true}; + + var observer = new MutationObserver(function (mutations) { + // if it isn't disconnected it'll loop infinitely because the observed element is modified + observer.disconnect(); + var form = $('#rtd-search-form'); + form.empty(); + form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html'); + $('').attr({ + type: "text", + name: "q", + placeholder: "Search docs" + }).appendTo(form); + }); + + if (window.location.origin.indexOf('readthedocs') > -1) { + observer.observe(target, config); + } + } + + /** + * Analyzes the URL of the current page to find out what the selected GitHub branch is. It's usually + * part of the location path. The code needs to distinguish between running MkDocs standalone + * and docs served from RTD. If no valid branch could be determined 'dev' returned. + * + * @returns GitHub branch name + */ + function determineSelectedBranch() { + var branch = 'dev', path = window.location.pathname; + if (window.location.origin.indexOf('readthedocs') > -1) { + // path is like /en///build/ -> extract 'lang' + // split[0] is an '' because the path starts with the separator + var thirdPathSegment = path.split('/')[2]; + // 'latest' is an alias on RTD for the 'dev' branch - which is the default for 'branch' here + if (thirdPathSegment !== 'latest') { + branch = thirdPathSegment; + } + } + return branch; + } +}()); \ No newline at end of file diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md index cdca7001..a1b1e012 100644 --- a/docs/references/features-cross-reference.md +++ b/docs/references/features-cross-reference.md @@ -5,7 +5,7 @@ - Not supported - N/A Cannot be supported - +
diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 00000000..00620004 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,11 @@ +site_name: PhpSpreadsheet Documentation +repo_url: https://github.com/PHPOffice/phpspreadsheet +edit_uri: edit/develop/docs/ + +theme: readthedocs +extra_css: + - extra/extra.css + +extra_javascript: + - extra/extra.js + \ No newline at end of file
Readers