😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

86 lines
2.0KB

  1. $(function() {
  2. // register a handler to move the focus to the search bar
  3. // upon pressing shift + "/" (i.e. "?")
  4. $(document).on('keydown', function(e) {
  5. if (e.shiftKey && e.keyCode == 191) {
  6. e.preventDefault();
  7. $("#search-input").focus();
  8. }
  9. });
  10. $(document).ready(function() {
  11. // do keyword highlighting
  12. /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */
  13. var mark = function() {
  14. var referrer = document.URL ;
  15. var paramKey = "q" ;
  16. if (referrer.indexOf("?") !== -1) {
  17. var qs = referrer.substr(referrer.indexOf('?') + 1);
  18. var qs_noanchor = qs.split('#')[0];
  19. var qsa = qs_noanchor.split('&');
  20. var keyword = "";
  21. for (var i = 0; i < qsa.length; i++) {
  22. var currentParam = qsa[i].split('=');
  23. if (currentParam.length !== 2) {
  24. continue;
  25. }
  26. if (currentParam[0] == paramKey) {
  27. keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20"));
  28. }
  29. }
  30. if (keyword !== "") {
  31. $(".contents").unmark({
  32. done: function() {
  33. $(".contents").mark(keyword);
  34. }
  35. });
  36. }
  37. }
  38. };
  39. mark();
  40. });
  41. });
  42. /* Search term highlighting ------------------------------*/
  43. function matchedWords(hit) {
  44. var words = [];
  45. var hierarchy = hit._highlightResult.hierarchy;
  46. // loop to fetch from lvl0, lvl1, etc.
  47. for (var idx in hierarchy) {
  48. words = words.concat(hierarchy[idx].matchedWords);
  49. }
  50. var content = hit._highlightResult.content;
  51. if (content) {
  52. words = words.concat(content.matchedWords);
  53. }
  54. // return unique words
  55. var words_uniq = [...new Set(words)];
  56. return words_uniq;
  57. }
  58. function updateHitURL(hit) {
  59. var words = matchedWords(hit);
  60. var url = "";
  61. if (hit.anchor) {
  62. url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor;
  63. } else {
  64. url = hit.url + '?q=' + escape(words.join(" "));
  65. }
  66. return url;
  67. }