Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Project: KOB1
Views: 16973/*1* Handles finding a text string anywhere in the slides and showing the next occurrence to the user2* by navigatating to that slide and highlighting it.3*4* By Jon Snyder <[email protected]>, February 20135*/67var RevealSearch = (function() {89var matchedSlides;10var currentMatchedIndex;11var searchboxDirty;12var myHilitor;1314// Original JavaScript code by Chirp Internet: www.chirp.com.au15// Please acknowledge use of this code by including this header.16// 2/2013 jon: modified regex to display any match, not restricted to word boundaries.1718function Hilitor(id, tag)19{2021var targetNode = document.getElementById(id) || document.body;22var hiliteTag = tag || "EM";23var skipTags = new RegExp("^(?:" + hiliteTag + "|SCRIPT|FORM)$");24var colors = ["#ff6", "#a0ffff", "#9f9", "#f99", "#f6f"];25var wordColor = [];26var colorIdx = 0;27var matchRegex = "";28var matchingSlides = [];2930this.setRegex = function(input)31{32input = input.replace(/^[^\w]+|[^\w]+$/g, "").replace(/[^\w'-]+/g, "|");33matchRegex = new RegExp("(" + input + ")","i");34}3536this.getRegex = function()37{38return matchRegex.toString().replace(/^\/\\b\(|\)\\b\/i$/g, "").replace(/\|/g, " ");39}4041// recursively apply word highlighting42this.hiliteWords = function(node)43{44if(node == undefined || !node) return;45if(!matchRegex) return;46if(skipTags.test(node.nodeName)) return;4748if(node.hasChildNodes()) {49for(var i=0; i < node.childNodes.length; i++)50this.hiliteWords(node.childNodes[i]);51}52if(node.nodeType == 3) { // NODE_TEXT53if((nv = node.nodeValue) && (regs = matchRegex.exec(nv))) {54//find the slide's section element and save it in our list of matching slides55var secnode = node;56while (secnode != null && secnode.nodeName != 'SECTION') {57secnode = secnode.parentNode;58}5960var slideIndex = Reveal.getIndices(secnode);61var slidelen = matchingSlides.length;62var alreadyAdded = false;63for (var i=0; i < slidelen; i++) {64if ( (matchingSlides[i].h === slideIndex.h) && (matchingSlides[i].v === slideIndex.v) ) {65alreadyAdded = true;66}67}68if (! alreadyAdded) {69matchingSlides.push(slideIndex);70}7172if(!wordColor[regs[0].toLowerCase()]) {73wordColor[regs[0].toLowerCase()] = colors[colorIdx++ % colors.length];74}7576var match = document.createElement(hiliteTag);77match.appendChild(document.createTextNode(regs[0]));78match.style.backgroundColor = wordColor[regs[0].toLowerCase()];79match.style.fontStyle = "inherit";80match.style.color = "#000";8182var after = node.splitText(regs.index);83after.nodeValue = after.nodeValue.substring(regs[0].length);84node.parentNode.insertBefore(match, after);85}86}87};8889// remove highlighting90this.remove = function()91{92var arr = document.getElementsByTagName(hiliteTag);93while(arr.length && (el = arr[0])) {94el.parentNode.replaceChild(el.firstChild, el);95}96};9798// start highlighting at target node99this.apply = function(input)100{101if(input == undefined || !input) return;102this.remove();103this.setRegex(input);104this.hiliteWords(targetNode);105return matchingSlides;106};107108}109110function openSearch() {111//ensure the search term input dialog is visible and has focus:112var inputboxdiv = document.getElementById("searchinputdiv");113var inputbox = document.getElementById("searchinput");114inputboxdiv.style.display = "inline";115inputbox.focus();116inputbox.select();117}118119function closeSearch() {120var inputboxdiv = document.getElementById("searchinputdiv");121inputboxdiv.style.display = "none";122if(myHilitor) myHilitor.remove();123}124125function toggleSearch() {126var inputboxdiv = document.getElementById("searchinputdiv");127if (inputboxdiv.style.display !== "inline") {128openSearch();129}130else {131closeSearch();132}133}134135function doSearch() {136//if there's been a change in the search term, perform a new search:137if (searchboxDirty) {138var searchstring = document.getElementById("searchinput").value;139140if (searchstring === '') {141if(myHilitor) myHilitor.remove();142matchedSlides = null;143}144else {145//find the keyword amongst the slides146myHilitor = new Hilitor("slidecontent");147matchedSlides = myHilitor.apply(searchstring);148currentMatchedIndex = 0;149}150}151152if (matchedSlides) {153//navigate to the next slide that has the keyword, wrapping to the first if necessary154if (matchedSlides.length && (matchedSlides.length <= currentMatchedIndex)) {155currentMatchedIndex = 0;156}157if (matchedSlides.length > currentMatchedIndex) {158Reveal.slide(matchedSlides[currentMatchedIndex].h, matchedSlides[currentMatchedIndex].v);159currentMatchedIndex++;160}161}162}163164var dom = {};165dom.wrapper = document.querySelector( '.reveal' );166167if( !dom.wrapper.querySelector( '.searchbox' ) ) {168var searchElement = document.createElement( 'div' );169searchElement.id = "searchinputdiv";170searchElement.classList.add( 'searchdiv' );171searchElement.style.position = 'absolute';172searchElement.style.top = '10px';173searchElement.style.right = '10px';174searchElement.style.zIndex = 10;175//embedded base64 search icon Designed by Sketchdock - http://www.sketchdock.com/:176searchElement.innerHTML = '<span><input type="search" id="searchinput" class="searchinput" style="vertical-align: top;"/><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJiSURBVHjatFZNaxNBGH5md+Mmu92NVdKDRipSAyqCghgQD4L4cRe86UUtAQ+eFCxoa4/25EXBFi8eBE+eRPoDhB6KgiiixdAPCEkx2pjvTXadd9yNsflwuyUDD/O+u8PzzDPvzOwyx3EwyCZhwG3gAkp7MnpjgbopjsltcD4gjuXZZKeAR348MYLYTm3LzOs/y3j3JTfZxgXWXmTuwPHIc4VmoOmv5IrI53+AO2DdHLjkDWQ3GoEEVFXtXQOvkSnPWcyUceviLhwbDYv8/XIVj97kse7TodLvZXxYxrPUHkQ1ufXs3FEdybEIxucySOesoNvUgWU1cP3MkCBfTFdw9fGaAMVmRELq7LBw2Q3/FaAxxWIRpw+ZIr/7IouPqzUBiqmdHAv7EuhRAwf1er2Vy4x1jW3b2d5Jfvu5IPp7l2LYbcgCFFNb+FoJ7oBqEAqFMPNqFcmEgVMJDfMT+1tvN0pNjERlMS6QA5pFOKxiKVPFhakPeL3It+WGJUDxt2wFR+JhzI7v5ctkd8DXOZAkCYYxhO+lKm4+Xfqz/rIixBuNBl7eOYzkQQNzqX249mRl6zUgEcYkaJrGhUwBinVdh6IouPzwE6/DL5w4oLkH8y981aDf+uq6hlKpJESiUdNfDZi7/ehG9K6KfiA3pml0PLcsq+cSMTj2NL9ukc4UOmz7AZ3+crkC4mHujFvXNaMFB3bEr8xPS6p5O+jXxq4VZtaen7/PwzrntjcLUE0iHPS1Ud1cdiEJl/8WivZk0wXd7zWOMkeF8s0CcAmkNrC2nvXZDbbbN73ccYnZoH9bfgswAFzAe9/h3dbKAAAAAElFTkSuQmCC" id="searchbutton" class="searchicon" style="vertical-align: top; margin-top: -1px;"/></span>';177dom.wrapper.appendChild( searchElement );178}179180document.getElementById("searchbutton").addEventListener( 'click', function(event) {181doSearch();182}, false );183184document.getElementById("searchinput").addEventListener( 'keyup', function( event ) {185switch (event.keyCode) {186case 13:187event.preventDefault();188doSearch();189searchboxDirty = false;190break;191default:192searchboxDirty = true;193}194}, false );195196document.addEventListener( 'keydown', function( event ) {197if( event.key == "F" && (event.ctrlKey || event.metaKey) ) {//Control+Shift+f198event.preventDefault();199toggleSearch();200}201}, false );202if( window.Reveal ) Reveal.registerKeyboardShortcut( 'Ctrl-Shift-F', 'Search' );203closeSearch();204return { open: openSearch };205})();206207208