+ */
+ function addLanguageSelectorToRtdFlyOutMenu() {
+ var flyOutWrapper = $('.rst-other-versions');
+ // only relevant on RTD
+ if (flyOutWrapper.size() > 0) {
+ var observer = new MutationObserver(function (mutations) {
+ // since mutation on the target node was triggered we can safely assume the injected RTD div has now been added
+ var injectedDiv = $('.rst-other-versions .injected');
+ var selectedLanguageCode = determineSelectedLanguageCode();
+ var dl = document.createElement('dl');
+ var dt = document.createElement('dt');
+ dl.appendChild(dt);
+ dt.appendChild(document.createTextNode('Languages'));
+ for (var languageCode in languageCodeToNameMap) {
+ dl.appendChild(createLanguageLinkFor(languageCode, selectedLanguageCode === languageCode));
+ }
+ injectedDiv.prepend(dl);
+ // no need for that observer anymore
+ observer.disconnect();
+ });
+
+ // observed target node is the fly-out wrapper, the only event we care about is when children are modified
+ observer.observe(flyOutWrapper[0], {childList: true});
+ }
+ }
+
+ /**
+ * The module doc pages contain relative links to artifacts in the GitHub repository. For those links to work both
+ * on GitHub (i.e. when the page is viewed on GitHub) and on RTD they are defined with a relative URL. This function
+ * replaces the relative path with an absolute path based on the selected branch.
+ */
+ function replaceRelativeLinksWithStaticGitHubUrl() {
+ var relativePath = "../../../..";
+ var gitHubPath = "https://github.com/nodemcu/nodemcu-firmware/tree/" + determineSelectedBranch();
+ var gitHubLinks = $("a[href^='" + relativePath + "']").each(function (index) {
+ var url = $(this).attr('href');
+ $(this).attr('href', url.replace(relativePath, gitHubPath));
+ });
+ }
+
+ function createLanguageLinkFor(languageCode, isCurrentlySelected) {
+ var strong;
+ // split[0] is an '' because the path starts with the separator
+ var pathSegments = window.location.pathname.split('/');
+ var dd = document.createElement("dd");
+ var href = document.createElement("a");
+ href.setAttribute('href', '/' + pathSegments[1] + '/' + pathSegments[2] + '/' + languageCode);
+ href.appendChild(document.createTextNode(languageCode));
+ dd.appendChild(href);
+ if (isCurrentlySelected) {
+ strong = document.createElement("strong");
+ strong.appendChild(dd);
+ return strong;
+ } else {
+ return dd;
+ }
+ }
+
+ /**
+ * Analyzes the URL of the current page to find out what the selected language 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 language could be determined the default language is
+ * returned.
+ *
+ * @returns 2-char language code
+ */
+ function determineSelectedLanguageCode() {
+ var selectedLanguageCode, 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
+ selectedLanguageCode = path.split('/')[3];
+ } else {
+ // path is like //build/ -> extract 'lang'
+ selectedLanguageCode = path.substr(1, 2);
+ }
+ if (!selectedLanguageCode || selectedLanguageCode.length > 2) {
+ selectedLanguageCode = defaultLanguageCode;
+ }
+ return selectedLanguageCode;
+ }
+
+ /**
+ * 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
+ branch = path.split('/')[2];
+ }
+ return branch;
+ }
+
+ function values(associativeArray) {
+ var values = [];
+ for (var key in associativeArray) {
+ if (associativeArray.hasOwnProperty(key)) {
+ values.push(associativeArray[key]);
+ }
+ }
+ return values;
+ }
+}());
diff --git a/mkdocs.yml b/mkdocs.yml
index e11c3d9056b..b46a2e326d0 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -60,6 +60,8 @@ theme: readthedocs
extra_css:
- css/extra.css
+extra_javascript:
+ - js/extra.js
copyright: Copyright © 2017 Broad Institute
# google_analytics: ['identifierID', 'URL.org']