😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

175 lines
4.4KB

  1. $(function() {
  2. $("#sidebar")
  3. .stick_in_parent({offset_top: 40})
  4. .on('sticky_kit:bottom', function(e) {
  5. $(this).parent().css('position', 'static');
  6. })
  7. .on('sticky_kit:unbottom', function(e) {
  8. $(this).parent().css('position', 'relative');
  9. });
  10. $('body').scrollspy({
  11. target: '#sidebar',
  12. offset: 60
  13. });
  14. $('[data-toggle="tooltip"]').tooltip();
  15. var cur_path = paths(location.pathname);
  16. $("#navbar ul li a").each(function(index, value) {
  17. if (value.text == "Home")
  18. return;
  19. if (value.getAttribute("href") === "#")
  20. return;
  21. var path = paths(value.pathname);
  22. if (is_prefix(cur_path, path)) {
  23. // Add class to parent <li>, and enclosing <li> if in dropdown
  24. var menu_anchor = $(value);
  25. menu_anchor.parent().addClass("active");
  26. menu_anchor.closest("li.dropdown").addClass("active");
  27. }
  28. });
  29. });
  30. $(document).ready(function() {
  31. // do keyword highlighting
  32. /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */
  33. var mark = function() {
  34. var referrer = document.URL ;
  35. var paramKey = "q" ;
  36. if (referrer.indexOf("?") !== -1) {
  37. var qs = referrer.substr(referrer.indexOf('?') + 1);
  38. var qs_noanchor = qs.split('#')[0];
  39. var qsa = qs_noanchor.split('&');
  40. var keyword = "";
  41. for (var i = 0; i < qsa.length; i++) {
  42. var currentParam = qsa[i].split('=');
  43. if (currentParam.length !== 2) {
  44. continue;
  45. }
  46. if (currentParam[0] == paramKey) {
  47. keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20"));
  48. }
  49. }
  50. if (keyword !== "") {
  51. $(".contents").unmark({
  52. done: function() {
  53. $(".contents").mark(keyword);
  54. }
  55. });
  56. }
  57. }
  58. };
  59. mark();
  60. });
  61. function paths(pathname) {
  62. var pieces = pathname.split("/");
  63. pieces.shift(); // always starts with /
  64. var end = pieces[pieces.length - 1];
  65. if (end === "index.html" || end === "")
  66. pieces.pop();
  67. return(pieces);
  68. }
  69. function is_prefix(needle, haystack) {
  70. if (needle.length > haystack.lengh)
  71. return(false);
  72. // Special case for length-0 haystack, since for loop won't run
  73. if (haystack.length === 0) {
  74. return(needle.length === 0);
  75. }
  76. for (var i = 0; i < haystack.length; i++) {
  77. if (needle[i] != haystack[i])
  78. return(false);
  79. }
  80. return(true);
  81. }
  82. /* Clipboard --------------------------*/
  83. function changeTooltipMessage(element, msg) {
  84. var tooltipOriginalTitle=element.getAttribute('data-original-title');
  85. element.setAttribute('data-original-title', msg);
  86. $(element).tooltip('show');
  87. element.setAttribute('data-original-title', tooltipOriginalTitle);
  88. }
  89. if(Clipboard.isSupported()) {
  90. $(document).ready(function() {
  91. var copyButton = "<button type='button' class='btn btn-primary btn-copy-ex' type = 'submit' title='Copy to clipboard' aria-hidden='true' data-toggle='tooltip' data-placement='left auto' data-trigger='hover' data-clipboard-copy><i class='fa fa-copy' aria-hidden='true'></i></button>";
  92. $(".examples").addClass("hasCopyButton");
  93. // Insert copy buttons:
  94. $(copyButton).prependTo(".hasCopyButton");
  95. // Initialize tooltips:
  96. $('.btn-copy-ex').tooltip({container: 'body'});
  97. // Initialize clipboard:
  98. var clipboardBtnCopies = new Clipboard('[data-clipboard-copy]', {
  99. text: function(trigger) {
  100. return trigger.parentNode.textContent;
  101. }
  102. });
  103. clipboardBtnCopies.on('success', function(e) {
  104. changeTooltipMessage(e.trigger, 'Copied!');
  105. e.clearSelection();
  106. });
  107. clipboardBtnCopies.on('error', function() {
  108. changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
  109. });
  110. });
  111. }
  112. /* Search term highlighting ------------------------------*/
  113. function matchedWords(hit) {
  114. var words = [];
  115. var hierarchy = hit._highlightResult.hierarchy;
  116. // loop to fetch from lvl0, lvl1, etc.
  117. for (var idx in hierarchy) {
  118. words = words.concat(hierarchy[idx].matchedWords);
  119. }
  120. var content = hit._highlightResult.content;
  121. if (content) {
  122. words = words.concat(content.matchedWords);
  123. }
  124. // return unique words
  125. var words_uniq = [...new Set(words)];
  126. return words_uniq;
  127. }
  128. function updateHitURL(hit) {
  129. var words = matchedWords(hit);
  130. var url = "";
  131. if (hit.anchor) {
  132. url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor;
  133. } else {
  134. url = hit.url + '?q=' + escape(words.join(" "));
  135. }
  136. return url;
  137. }