😎 Give your xaringan slides some style
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.2KB

  1. /* http://gregfranko.com/blog/jquery-best-practices/ */
  2. (function($) {
  3. $(function() {
  4. $('.navbar-fixed-top').headroom();
  5. $('body').css('padding-top', $('.navbar').height() + 10);
  6. $(window).resize(function(){
  7. $('body').css('padding-top', $('.navbar').height() + 10);
  8. });
  9. $('body').scrollspy({
  10. target: '#sidebar',
  11. offset: 60
  12. });
  13. $('[data-toggle="tooltip"]').tooltip();
  14. var cur_path = paths(location.pathname);
  15. var links = $("#navbar ul li a");
  16. var max_length = -1;
  17. var pos = -1;
  18. for (var i = 0; i < links.length; i++) {
  19. if (links[i].getAttribute("href") === "#")
  20. continue;
  21. // Ignore external links
  22. if (links[i].host !== location.host)
  23. continue;
  24. var nav_path = paths(links[i].pathname);
  25. var length = prefix_length(nav_path, cur_path);
  26. if (length > max_length) {
  27. max_length = length;
  28. pos = i;
  29. }
  30. }
  31. // Add class to parent <li>, and enclosing <li> if in dropdown
  32. if (pos >= 0) {
  33. var menu_anchor = $(links[pos]);
  34. menu_anchor.parent().addClass("active");
  35. menu_anchor.closest("li.dropdown").addClass("active");
  36. }
  37. });
  38. function paths(pathname) {
  39. var pieces = pathname.split("/");
  40. pieces.shift(); // always starts with /
  41. var end = pieces[pieces.length - 1];
  42. if (end === "index.html" || end === "")
  43. pieces.pop();
  44. return(pieces);
  45. }
  46. // Returns -1 if not found
  47. function prefix_length(needle, haystack) {
  48. if (needle.length > haystack.length)
  49. return(-1);
  50. // Special case for length-0 haystack, since for loop won't run
  51. if (haystack.length === 0) {
  52. return(needle.length === 0 ? 0 : -1);
  53. }
  54. for (var i = 0; i < haystack.length; i++) {
  55. if (needle[i] != haystack[i])
  56. return(i);
  57. }
  58. return(haystack.length);
  59. }
  60. /* Clipboard --------------------------*/
  61. function changeTooltipMessage(element, msg) {
  62. var tooltipOriginalTitle=element.getAttribute('data-original-title');
  63. element.setAttribute('data-original-title', msg);
  64. $(element).tooltip('show');
  65. element.setAttribute('data-original-title', tooltipOriginalTitle);
  66. }
  67. if(ClipboardJS.isSupported()) {
  68. $(document).ready(function() {
  69. var copyButton = "<button type='button' class='btn btn-primary btn-copy-ex' type = 'submit' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='tooltip' data-placement='left auto' data-trigger='hover' data-clipboard-copy><i class='fa fa-copy'></i></button>";
  70. $(".examples, div.sourceCode").addClass("hasCopyButton");
  71. // Insert copy buttons:
  72. $(copyButton).prependTo(".hasCopyButton");
  73. // Initialize tooltips:
  74. $('.btn-copy-ex').tooltip({container: 'body'});
  75. // Initialize clipboard:
  76. var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', {
  77. text: function(trigger) {
  78. return trigger.parentNode.textContent;
  79. }
  80. });
  81. clipboardBtnCopies.on('success', function(e) {
  82. changeTooltipMessage(e.trigger, 'Copied!');
  83. e.clearSelection();
  84. });
  85. clipboardBtnCopies.on('error', function() {
  86. changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
  87. });
  88. });
  89. }
  90. })(window.jQuery || window.$)