😎 Give your xaringan slides some style
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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