Static mdbook::theme::JS[][src]

pub static JS: &'static [u8] = b"\"use strict\";\n\n// Fix back button cache problem\nwindow.onunload = function () { };\n\n// Global variable, shared between modules\nfunction playpen_text(playpen) {\n    let code_block = playpen.querySelector(\"code\");\n\n    if (window.ace && code_block.classList.contains(\"editable\")) {\n        let editor = window.ace.edit(code_block);\n        return editor.getValue();\n    } else {\n        return code_block.textContent;\n    }\n}\n\n(function codeSnippets() {\n    // Hide Rust code lines prepended with a specific character\n    var hiding_character = \"#\";\n\n    function fetch_with_timeout(url, options, timeout = 6000) {\n        return Promise.race([\n            fetch(url, options),\n            new Promise((_, reject) => setTimeout(() => reject(new Error(\'timeout\')), timeout))\n        ]);\n    }\n\n    var playpens = Array.from(document.querySelectorAll(\".playpen\"));\n    if (playpens.length > 0) {\n        fetch_with_timeout(\"https://play.rust-lang.org/meta/crates\", {\n            headers: {\n                \'Content-Type\': \"application/json\",\n            },\n            method: \'POST\',\n            mode: \'cors\',\n        })\n        .then(response => response.json())\n        .then(response => {\n            // get list of crates available in the rust playground\n            let playground_crates = response.crates.map(item => item[\"id\"]);\n            playpens.forEach(block => handle_crate_list_update(block, playground_crates));\n        });\n    }\n\n    function handle_crate_list_update(playpen_block, playground_crates) {\n        // update the play buttons after receiving the response\n        update_play_button(playpen_block, playground_crates);\n\n        // and install on change listener to dynamically update ACE editors\n        if (window.ace) {\n            let code_block = playpen_block.querySelector(\"code\");\n            if (code_block.classList.contains(\"editable\")) {\n                let editor = window.ace.edit(code_block);\n                editor.addEventListener(\"change\", function (e) {\n                    update_play_button(playpen_block, playground_crates);\n                });\n            }\n        }\n    }\n\n    // updates the visibility of play button based on `no_run` class and\n    // used crates vs ones available on http://play.rust-lang.org\n    function update_play_button(pre_block, playground_crates) {\n        var play_button = pre_block.querySelector(\".play-button\");\n\n        // skip if code is `no_run`\n        if (pre_block.querySelector(\'code\').classList.contains(\"no_run\")) {\n            play_button.classList.add(\"hidden\");\n            return;\n        }\n\n        // get list of `extern crate`\'s from snippet\n        var txt = playpen_text(pre_block);\n        var re = /extern\\s+crate\\s+([a-zA-Z_0-9]+)\\s*;/g;\n        var snippet_crates = [];\n        var item;\n        while (item = re.exec(txt)) {\n            snippet_crates.push(item[1]);\n        }\n\n        // check if all used crates are available on play.rust-lang.org\n        var all_available = snippet_crates.every(function (elem) {\n            return playground_crates.indexOf(elem) > -1;\n        });\n\n        if (all_available) {\n            play_button.classList.remove(\"hidden\");\n        } else {\n            play_button.classList.add(\"hidden\");\n        }\n    }\n\n    function run_rust_code(code_block) {\n        var result_block = code_block.querySelector(\".result\");\n        if (!result_block) {\n            result_block = document.createElement(\'code\');\n            result_block.className = \'result hljs language-bash\';\n\n            code_block.append(result_block);\n        }\n\n        let text = playpen_text(code_block);\n\n        var params = {\n            version: \"stable\",\n            optimize: \"0\",\n            code: text\n        };\n\n        if (text.indexOf(\"#![feature\") !== -1) {\n            params.version = \"nightly\";\n        }\n\n        result_block.innerText = \"Running...\";\n\n        fetch_with_timeout(\"https://play.rust-lang.org/evaluate.json\", {\n            headers: {\n                \'Content-Type\': \"application/json\",\n            },\n            method: \'POST\',\n            mode: \'cors\',\n            body: JSON.stringify(params)\n        })\n        .then(response => response.json())\n        .then(response => result_block.innerText = response.result)\n        .catch(error => result_block.innerText = \"Playground Communication: \" + error.message);\n    }\n\n    // Syntax highlighting Configuration\n    hljs.configure({\n        tabReplace: \'    \', // 4 spaces\n        languages: [],      // Languages used for auto-detection\n    });\n\n    if (window.ace) {\n        // language-rust class needs to be removed for editable\n        // blocks or highlightjs will capture events\n        Array\n            .from(document.querySelectorAll(\'code.editable\'))\n            .forEach(function (block) { block.classList.remove(\'language-rust\'); });\n\n        Array\n            .from(document.querySelectorAll(\'code:not(.editable)\'))\n            .forEach(function (block) { hljs.highlightBlock(block); });\n    } else {\n        Array\n            .from(document.querySelectorAll(\'code\'))\n            .forEach(function (block) { hljs.highlightBlock(block); });\n    }\n\n    // Adding the hljs class gives code blocks the color css\n    // even if highlighting doesn\'t apply\n    Array\n        .from(document.querySelectorAll(\'code\'))\n        .forEach(function (block) { block.classList.add(\'hljs\'); });\n\n    Array.from(document.querySelectorAll(\"code.language-rust\")).forEach(function (block) {\n\n        var code_block = block;\n        var pre_block = block.parentNode;\n        // hide lines\n        var lines = code_block.innerHTML.split(\"\\n\");\n        var first_non_hidden_line = false;\n        var lines_hidden = false;\n        var trimmed_line = \"\";\n\n        for (var n = 0; n < lines.length; n++) {\n            trimmed_line = lines[n].trim();\n            if (trimmed_line[0] == hiding_character && trimmed_line[1] != hiding_character) {\n                if (first_non_hidden_line) {\n                    lines[n] = \"<span class=\\\"hidden\\\">\" + \"\\n\" + lines[n].replace(/(\\s*)# ?/, \"$1\") + \"</span>\";\n                }\n                else {\n                    lines[n] = \"<span class=\\\"hidden\\\">\" + lines[n].replace(/(\\s*)# ?/, \"$1\") + \"\\n\" + \"</span>\";\n                }\n                lines_hidden = true;\n            }\n            else if (first_non_hidden_line) {\n                lines[n] = \"\\n\" + lines[n];\n            }\n            else {\n                first_non_hidden_line = true;\n            }\n            if (trimmed_line[0] == hiding_character && trimmed_line[1] == hiding_character) {\n                lines[n] = lines[n].replace(\"##\", \"#\")\n            }\n        }\n        code_block.innerHTML = lines.join(\"\");\n\n        // If no lines were hidden, return\n        if (!lines_hidden) { return; }\n\n        var buttons = document.createElement(\'div\');\n        buttons.className = \'buttons\';\n        buttons.innerHTML = \"<button class=\\\"fa fa-expand\\\" title=\\\"Show hidden lines\\\" aria-label=\\\"Show hidden lines\\\"></button>\";\n\n        // add expand button\n        pre_block.insertBefore(buttons, pre_block.firstChild);\n\n        pre_block.querySelector(\'.buttons\').addEventListener(\'click\', function (e) {\n            if (e.target.classList.contains(\'fa-expand\')) {\n                var lines = pre_block.querySelectorAll(\'span.hidden\');\n\n                e.target.classList.remove(\'fa-expand\');\n                e.target.classList.add(\'fa-compress\');\n                e.target.title = \'Hide lines\';\n                e.target.setAttribute(\'aria-label\', e.target.title);\n\n                Array.from(lines).forEach(function (line) {\n                    line.classList.remove(\'hidden\');\n                    line.classList.add(\'unhidden\');\n                });\n            } else if (e.target.classList.contains(\'fa-compress\')) {\n                var lines = pre_block.querySelectorAll(\'span.unhidden\');\n\n                e.target.classList.remove(\'fa-compress\');\n                e.target.classList.add(\'fa-expand\');\n                e.target.title = \'Show hidden lines\';\n                e.target.setAttribute(\'aria-label\', e.target.title);\n\n                Array.from(lines).forEach(function (line) {\n                    line.classList.remove(\'unhidden\');\n                    line.classList.add(\'hidden\');\n                });\n            }\n        });\n    });\n\n    Array.from(document.querySelectorAll(\'pre code\')).forEach(function (block) {\n        var pre_block = block.parentNode;\n        if (!pre_block.classList.contains(\'playpen\')) {\n            var buttons = pre_block.querySelector(\".buttons\");\n            if (!buttons) {\n                buttons = document.createElement(\'div\');\n                buttons.className = \'buttons\';\n                pre_block.insertBefore(buttons, pre_block.firstChild);\n            }\n\n            var clipButton = document.createElement(\'button\');\n            clipButton.className = \'fa fa-copy clip-button\';\n            clipButton.title = \'Copy to clipboard\';\n            clipButton.setAttribute(\'aria-label\', clipButton.title);\n            clipButton.innerHTML = \'<i class=\\\"tooltiptext\\\"></i>\';\n\n            buttons.insertBefore(clipButton, buttons.firstChild);\n        }\n    });\n\n    // Process playpen code blocks\n    Array.from(document.querySelectorAll(\".playpen\")).forEach(function (pre_block) {\n        // Add play button\n        var buttons = pre_block.querySelector(\".buttons\");\n        if (!buttons) {\n            buttons = document.createElement(\'div\');\n            buttons.className = \'buttons\';\n            pre_block.insertBefore(buttons, pre_block.firstChild);\n        }\n\n        var runCodeButton = document.createElement(\'button\');\n        runCodeButton.className = \'fa fa-play play-button\';\n        runCodeButton.hidden = true;\n        runCodeButton.title = \'Run this code\';\n        runCodeButton.setAttribute(\'aria-label\', runCodeButton.title);\n\n        var copyCodeClipboardButton = document.createElement(\'button\');\n        copyCodeClipboardButton.className = \'fa fa-copy clip-button\';\n        copyCodeClipboardButton.innerHTML = \'<i class=\"tooltiptext\"></i>\';\n        copyCodeClipboardButton.title = \'Copy to clipboard\';\n        copyCodeClipboardButton.setAttribute(\'aria-label\', copyCodeClipboardButton.title);\n\n        buttons.insertBefore(runCodeButton, buttons.firstChild);\n        buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);\n\n        runCodeButton.addEventListener(\'click\', function (e) {\n            run_rust_code(pre_block);\n        });\n\n        let code_block = pre_block.querySelector(\"code\");\n        if (window.ace && code_block.classList.contains(\"editable\")) {\n            var undoChangesButton = document.createElement(\'button\');\n            undoChangesButton.className = \'fa fa-history reset-button\';\n            undoChangesButton.title = \'Undo changes\';\n            undoChangesButton.setAttribute(\'aria-label\', undoChangesButton.title);\n\n            buttons.insertBefore(undoChangesButton, buttons.firstChild);\n\n            undoChangesButton.addEventListener(\'click\', function () {\n                let editor = window.ace.edit(code_block);\n                editor.setValue(editor.originalCode);\n                editor.clearSelection();\n            });\n        }\n    });\n})();\n\n(function themes() {\n    var html = document.querySelector(\'html\');\n    var themeToggleButton = document.getElementById(\'theme-toggle\');\n    var themePopup = document.getElementById(\'theme-list\');\n    var themeColorMetaTag = document.querySelector(\'meta[name=\"theme-color\"]\');\n    var stylesheets = {\n        ayuHighlight: document.querySelector(\"[href$=\'ayu-highlight.css\']\"),\n        tomorrowNight: document.querySelector(\"[href$=\'tomorrow-night.css\']\"),\n        highlight: document.querySelector(\"[href$=\'highlight.css\']\"),\n    };\n\n    function showThemes() {\n        themePopup.style.display = \'block\';\n        themeToggleButton.setAttribute(\'aria-expanded\', true);\n        themePopup.querySelector(\"button#\" + document.body.className).focus();\n    }\n\n    function hideThemes() {\n        themePopup.style.display = \'none\';\n        themeToggleButton.setAttribute(\'aria-expanded\', false);\n        themeToggleButton.focus();\n    }\n\n    function set_theme(theme) {\n        let ace_theme;\n\n        if (theme == \'coal\' || theme == \'navy\') {\n            stylesheets.ayuHighlight.disabled = true;\n            stylesheets.tomorrowNight.disabled = false;\n            stylesheets.highlight.disabled = true;\n\n            ace_theme = \"ace/theme/tomorrow_night\";\n        } else if (theme == \'ayu\') {\n            stylesheets.ayuHighlight.disabled = false;\n            stylesheets.tomorrowNight.disabled = true;\n            stylesheets.highlight.disabled = true;\n\n            ace_theme = \"ace/theme/tomorrow_night\";\n        } else {\n            stylesheets.ayuHighlight.disabled = true;\n            stylesheets.tomorrowNight.disabled = true;\n            stylesheets.highlight.disabled = false;\n\n            ace_theme = \"ace/theme/dawn\";\n        }\n\n        setTimeout(function () {\n            themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;\n        }, 1);\n\n        if (window.ace && window.editors) {\n            window.editors.forEach(function (editor) {\n                editor.setTheme(ace_theme);\n            });\n        }\n\n        var previousTheme;\n        try { previousTheme = localStorage.getItem(\'mdbook-theme\'); } catch (e) { }\n        if (previousTheme === null || previousTheme === undefined) { previousTheme = \'light\'; }\n\n        try { localStorage.setItem(\'mdbook-theme\', theme); } catch (e) { }\n\n        document.body.className = theme;\n        html.classList.remove(previousTheme);\n        html.classList.add(theme);\n    }\n\n    // Set theme\n    var theme;\n    try { theme = localStorage.getItem(\'mdbook-theme\'); } catch(e) { }\n    if (theme === null || theme === undefined) { theme = \'light\'; }\n\n    set_theme(theme);\n\n    themeToggleButton.addEventListener(\'click\', function () {\n        if (themePopup.style.display === \'block\') {\n            hideThemes();\n        } else {\n            showThemes();\n        }\n    });\n\n    themePopup.addEventListener(\'click\', function (e) {\n        var theme = e.target.id || e.target.parentElement.id;\n        set_theme(theme);\n    });\n\n    themePopup.addEventListener(\'focusout\', function(e) {\n        // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)\n        if (!!e.relatedTarget && !themeToggleButton.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)) {\n            hideThemes();\n        }\n    });\n\n    // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang-nursery/mdBook/issues/628\n    document.addEventListener(\'click\', function(e) {\n        if (themePopup.style.display === \'block\' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {\n            hideThemes();\n        }\n    });\n\n    document.addEventListener(\'keydown\', function (e) {\n        if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }\n        if (!themePopup.contains(e.target)) { return; }\n\n        switch (e.key) {\n            case \'Escape\':\n                e.preventDefault();\n                hideThemes();\n                break;\n            case \'ArrowUp\':\n                e.preventDefault();\n                var li = document.activeElement.parentElement;\n                if (li && li.previousElementSibling) {\n                    li.previousElementSibling.querySelector(\'button\').focus();\n                }\n                break;\n            case \'ArrowDown\':\n                e.preventDefault();\n                var li = document.activeElement.parentElement;\n                if (li && li.nextElementSibling) {\n                    li.nextElementSibling.querySelector(\'button\').focus();\n                }\n                break;\n            case \'Home\':\n                e.preventDefault();\n                themePopup.querySelector(\'li:first-child button\').focus();\n                break;\n            case \'End\':\n                e.preventDefault();\n                themePopup.querySelector(\'li:last-child button\').focus();\n                break;\n        }\n    });\n})();\n\n(function sidebar() {\n    var html = document.querySelector(\"html\");\n    var sidebar = document.getElementById(\"sidebar\");\n    var sidebarLinks = document.querySelectorAll(\'#sidebar a\');\n    var sidebarToggleButton = document.getElementById(\"sidebar-toggle\");\n    var firstContact = null;\n\n    function showSidebar() {\n        html.classList.remove(\'sidebar-hidden\')\n        html.classList.add(\'sidebar-visible\');\n        Array.from(sidebarLinks).forEach(function (link) {\n            link.setAttribute(\'tabIndex\', 0);\n        });\n        sidebarToggleButton.setAttribute(\'aria-expanded\', true);\n        sidebar.setAttribute(\'aria-hidden\', false);\n        try { localStorage.setItem(\'mdbook-sidebar\', \'visible\'); } catch (e) { }\n    }\n\n    function hideSidebar() {\n        html.classList.remove(\'sidebar-visible\')\n        html.classList.add(\'sidebar-hidden\');\n        Array.from(sidebarLinks).forEach(function (link) {\n            link.setAttribute(\'tabIndex\', -1);\n        });\n        sidebarToggleButton.setAttribute(\'aria-expanded\', false);\n        sidebar.setAttribute(\'aria-hidden\', true);\n        try { localStorage.setItem(\'mdbook-sidebar\', \'hidden\'); } catch (e) { }\n    }\n\n    // Toggle sidebar\n    sidebarToggleButton.addEventListener(\'click\', function sidebarToggle() {\n        if (html.classList.contains(\"sidebar-hidden\")) {\n            showSidebar();\n        } else if (html.classList.contains(\"sidebar-visible\")) {\n            hideSidebar();\n        } else {\n            if (getComputedStyle(sidebar)[\'transform\'] === \'none\') {\n                hideSidebar();\n            } else {\n                showSidebar();\n            }\n        }\n    });\n\n    document.addEventListener(\'touchstart\', function (e) {\n        firstContact = {\n            x: e.touches[0].clientX,\n            time: Date.now()\n        };\n    }, { passive: true });\n\n    document.addEventListener(\'touchmove\', function (e) {\n        if (!firstContact)\n            return;\n\n        var curX = e.touches[0].clientX;\n        var xDiff = curX - firstContact.x,\n            tDiff = Date.now() - firstContact.time;\n\n        if (tDiff < 250 && Math.abs(xDiff) >= 150) {\n            if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300))\n                showSidebar();\n            else if (xDiff < 0 && curX < 300)\n                hideSidebar();\n\n            firstContact = null;\n        }\n    }, { passive: true });\n\n    // Scroll sidebar to current active section\n    var activeSection = sidebar.querySelector(\".active\");\n    if (activeSection) {\n        sidebar.scrollTop = activeSection.offsetTop;\n    }\n})();\n\n(function chapterNavigation() {\n    document.addEventListener(\'keydown\', function (e) {\n        if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }\n        if (window.search && window.search.hasFocus()) { return; }\n\n        switch (e.key) {\n            case \'ArrowRight\':\n                e.preventDefault();\n                var nextButton = document.querySelector(\'.nav-chapters.next\');\n                if (nextButton) {\n                    window.location.href = nextButton.href;\n                }\n                break;\n            case \'ArrowLeft\':\n                e.preventDefault();\n                var previousButton = document.querySelector(\'.nav-chapters.previous\');\n                if (previousButton) {\n                    window.location.href = previousButton.href;\n                }\n                break;\n        }\n    });\n})();\n\n(function clipboard() {\n    var clipButtons = document.querySelectorAll(\'.clip-button\');\n\n    function hideTooltip(elem) {\n        elem.firstChild.innerText = \"\";\n        elem.className = \'fa fa-copy clip-button\';\n    }\n\n    function showTooltip(elem, msg) {\n        elem.firstChild.innerText = msg;\n        elem.className = \'fa fa-copy tooltipped\';\n    }\n\n    var clipboardSnippets = new Clipboard(\'.clip-button\', {\n        text: function (trigger) {\n            hideTooltip(trigger);\n            let playpen = trigger.closest(\"pre\");\n            return playpen_text(playpen);\n        }\n    });\n\n    Array.from(clipButtons).forEach(function (clipButton) {\n        clipButton.addEventListener(\'mouseout\', function (e) {\n            hideTooltip(e.currentTarget);\n        });\n    });\n\n    clipboardSnippets.on(\'success\', function (e) {\n        e.clearSelection();\n        showTooltip(e.trigger, \"Copied!\");\n    });\n\n    clipboardSnippets.on(\'error\', function (e) {\n        showTooltip(e.trigger, \"Clipboard error!\");\n    });\n})();\n\n(function scrollToTop () {\n    var menuTitle = document.querySelector(\'.menu-title\');\n\n    menuTitle.addEventListener(\'click\', function () {\n        document.scrollingElement.scrollTo({ top: 0, behavior: \'smooth\' });\n    });\n})();\n\n(function autoHideMenu() {\n    var menu = document.getElementById(\'menu-bar\');\n\n    var previousScrollTop = document.scrollingElement.scrollTop;\n\n    document.addEventListener(\'scroll\', function () {\n        if (menu.classList.contains(\'folded\') && document.scrollingElement.scrollTop < previousScrollTop) {\n            menu.classList.remove(\'folded\');\n        } else if (!menu.classList.contains(\'folded\') && document.scrollingElement.scrollTop > previousScrollTop) {\n            menu.classList.add(\'folded\');\n        }\n\n        if (!menu.classList.contains(\'bordered\') && document.scrollingElement.scrollTop > 0) {\n            menu.classList.add(\'bordered\');\n        }\n\n        if (menu.classList.contains(\'bordered\') && document.scrollingElement.scrollTop === 0) {\n            menu.classList.remove(\'bordered\');\n        }\n\n        previousScrollTop = document.scrollingElement.scrollTop;\n    }, { passive: true });\n})();\n"