presentazione-papero/dist/plugin/search.js

8 lines
4.2 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).RevealSearch=t()}(this,(function(){"use strict";
/*!
* Handles finding a text string anywhere in the slides and showing the next occurrence to the user
* by navigatating to that slide and highlighting it.
*
* By Jon Snyder <snyder.jon@gmail.com>, February 2013
*/return function(){var e,t,n,i;function r(e,t){var n=document.getElementById(e)||document.body,i=t||"EM",r=new RegExp("^(?:"+i+"|SCRIPT|FORM)$"),o=["#ff6","#a0ffff","#9f9","#f99","#f6f"],d=[],l=0,a="",s=[];this.setRegex=function(e){e=e.replace(/^[^\w]+|[^\w]+$/g,"").replace(/[^\w'-]+/g,"|"),a=new RegExp("("+e+")","i")},this.getRegex=function(){return a.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(e){if(null!=e&&e&&a&&!r.test(e.nodeName)){if(e.hasChildNodes())for(var t=0;t<e.childNodes.length;t++)this.hiliteWords(e.childNodes[t]);if(3==e.nodeType&&(nv=e.nodeValue)&&(regs=a.exec(nv))){for(var n=e;null!=n&&"SECTION"!=n.nodeName;)n=n.parentNode;var c=Reveal.getIndices(n),u=s.length,h=!1;for(t=0;t<u;t++)s[t].h===c.h&&s[t].v===c.v&&(h=!0);h||s.push(c),d[regs[0].toLowerCase()]||(d[regs[0].toLowerCase()]=o[l++%o.length]);var p=document.createElement(i);p.appendChild(document.createTextNode(regs[0])),p.style.backgroundColor=d[regs[0].toLowerCase()],p.style.fontStyle="inherit",p.style.color="#000";var f=e.splitText(regs.index);f.nodeValue=f.nodeValue.substring(regs[0].length),e.parentNode.insertBefore(p,f)}}},this.remove=function(){for(var e=document.getElementsByTagName(i);e.length&&(el=e[0]);)el.parentNode.replaceChild(el.firstChild,el)},this.apply=function(e){if(null!=e&&e)return this.remove(),this.setRegex(e),this.hiliteWords(n),s}}function o(){var e=document.getElementById("searchinputdiv"),t=document.getElementById("searchinput");e.style.display="inline",t.focus(),t.select()}function d(){document.getElementById("searchinputdiv").style.display="none",i&&i.remove()}function l(){if(n){var o=document.getElementById("searchinput").value;""===o?(i&&i.remove(),e=null):(i=new r("slidecontent"),e=i.apply(o),t=0)}e&&(e.length&&e.length<=t&&(t=0),e.length>t&&(Reveal.slide(e[t].h,e[t].v),t++))}var a={};if(a.wrapper=document.querySelector(".reveal"),!a.wrapper.querySelector(".searchbox")){var s=document.createElement("div");s.id="searchinputdiv",s.classList.add("searchdiv"),s.style.position="absolute",s.style.top="10px",s.style.right="10px",s.style.zIndex=10,s.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>',a.wrapper.appendChild(s)}return document.getElementById("searchbutton").addEventListener("click",(function(e){l()}),!1),document.getElementById("searchinput").addEventListener("keyup",(function(e){switch(e.keyCode){case 13:e.preventDefault(),l(),n=!1;break;default:n=!0}}),!1),document.addEventListener("keydown",(function(e){"F"==e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),"inline"!==document.getElementById("searchinputdiv").style.display?o():d())}),!1),d(),{id:"search",init:function(e){e.registerKeyboardShortcut("CTRL + Shift + F","Search")},open:o}}()}));