git: 4612e81a77 - main - Fix undefined reference in search function and other JS improvements
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 03 May 2022 18:53:05 UTC
The branch main has been updated by carlavilla: URL: https://cgit.FreeBSD.org/doc/commit/?id=4612e81a776915245ac78ee7808f57f4f13332c2 commit 4612e81a776915245ac78ee7808f57f4f13332c2 Author: Sergio Carlavilla Delgado <carlavilla@FreeBSD.org> AuthorDate: 2022-05-03 18:52:03 +0000 Commit: Sergio Carlavilla Delgado <carlavilla@FreeBSD.org> CommitDate: 2022-05-03 18:52:03 +0000 Fix undefined reference in search function and other JS improvements --- .../themes/beastie/assets/js/copy-clipboard.js | 29 +++++++++--------- documentation/themes/beastie/assets/js/search.js | 5 +++- .../themes/beastie/assets/js/theme-chooser.js | 34 +++++++++++----------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/documentation/themes/beastie/assets/js/copy-clipboard.js b/documentation/themes/beastie/assets/js/copy-clipboard.js index 4b11058422..126f2bf8b1 100644 --- a/documentation/themes/beastie/assets/js/copy-clipboard.js +++ b/documentation/themes/beastie/assets/js/copy-clipboard.js @@ -27,7 +27,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -(function () { +;(function () { + 'use strict' + document.querySelectorAll(".rouge, .highlight").forEach(function(codeItem) { var sourceCode = codeItem.textContent; @@ -51,16 +53,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. button.addEventListener('click', copyToClipboard.bind(button, sourceCode)); }); -})(); -function copyToClipboard(text, item) { - const tooltip = item.target.nextElementSibling; - window.navigator.clipboard.writeText(text).then(function() { - if (tooltip) { - tooltip.classList.add("show-tooltip"); - setTimeout(function(){ - tooltip.classList.remove("show-tooltip"); - }, 1200); - } - }); -} + function copyToClipboard(text, item) { + const tooltip = item.target.nextElementSibling; + window.navigator.clipboard.writeText(text).then(function() { + if (tooltip) { + tooltip.classList.add("show-tooltip"); + setTimeout(function(){ + tooltip.classList.remove("show-tooltip"); + }, 1200); + } + }); + } + +})(); diff --git a/documentation/themes/beastie/assets/js/search.js b/documentation/themes/beastie/assets/js/search.js index cab7098d09..0cf9a29bb2 100644 --- a/documentation/themes/beastie/assets/js/search.js +++ b/documentation/themes/beastie/assets/js/search.js @@ -32,7 +32,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var searchBookInput = document.querySelector("#search-book"); var menuContents = document.querySelector("#MenuContents"); - searchBookInput.addEventListener('keyup', search); + + if (searchBookInput) { + searchBookInput.addEventListener('keyup', search); + } function search() { var menuElements = menuContents.children[0]; diff --git a/documentation/themes/beastie/assets/js/theme-chooser.js b/documentation/themes/beastie/assets/js/theme-chooser.js index 9a48432dc5..cc52d7084b 100644 --- a/documentation/themes/beastie/assets/js/theme-chooser.js +++ b/documentation/themes/beastie/assets/js/theme-chooser.js @@ -27,7 +27,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -(function () { +;(function () { + 'use strict' + var theme = localStorage.getItem('theme'); var themeChooser = document.querySelector('#theme-chooser'); var themeContainer = document.querySelector('.theme-container'); @@ -43,23 +45,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. setTheme('theme-light'); themeChooser.value = 'theme-light'; } -})(); -var themeChooser = document.querySelector('#theme-chooser'); + themeChooser.addEventListener('change', function() { + var theme = this.value; -themeChooser.addEventListener('change', function() { - var theme = this.value; + if (theme === "theme-dark") { + setTheme('theme-dark'); + } else if (theme === "theme-high-contrast") { + setTheme('theme-high-contrast'); + } else { + setTheme('theme-light'); + } + }); - if (theme === "theme-dark") { - setTheme('theme-dark'); - } else if (theme === "theme-high-contrast") { - setTheme('theme-high-contrast'); - } else { - setTheme('theme-light'); + function setTheme(themeName) { + localStorage.setItem('theme', themeName); + document.documentElement.className = themeName; } -}); - -function setTheme(themeName) { - localStorage.setItem('theme', themeName); - document.documentElement.className = themeName; -} +})();