😎 Give your xaringan slides some style
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

111 linhas
3.2KB

  1. /* http://gregfranko.com/blog/jquery-best-practices/ */
  2. (function($) {
  3. $(function() {
  4. $("#sidebar")
  5. .stick_in_parent({offset_top: 40})
  6. .on('sticky_kit:bottom', function(e) {
  7. $(this).parent().css('position', 'static');
  8. })
  9. .on('sticky_kit:unbottom', function(e) {
  10. $(this).parent().css('position', 'relative');
  11. });
  12. $('body').scrollspy({
  13. target: '#sidebar',
  14. offset: 60
  15. });
  16. $('[data-toggle="tooltip"]').tooltip();
  17. var cur_path = paths(location.pathname);
  18. var links = $("#navbar ul li a");
  19. var max_length = -1;
  20. var pos = -1;
  21. for (var i = 0; i < links.length; i++) {
  22. if (links[i].getAttribute("href") === "#")
  23. continue;
  24. var path = paths(links[i].pathname);
  25. var length = prefix_length(cur_path, 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. function prefix_length(needle, haystack) {
  47. if (needle.length > haystack.length)
  48. return(0);
  49. // Special case for length-0 haystack, since for loop won't run
  50. if (haystack.length === 0) {
  51. return(needle.length === 0 ? 1 : 0);
  52. }
  53. for (var i = 0; i < haystack.length; i++) {
  54. if (needle[i] != haystack[i])
  55. return(i);
  56. }
  57. return(haystack.length);
  58. }
  59. /* Clipboard --------------------------*/
  60. function changeTooltipMessage(element, msg) {
  61. var tooltipOriginalTitle=element.getAttribute('data-original-title');
  62. element.setAttribute('data-original-title', msg);
  63. $(element).tooltip('show');
  64. element.setAttribute('data-original-title', tooltipOriginalTitle);
  65. }
  66. if(Clipboard.isSupported()) {
  67. $(document).ready(function() {
  68. 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>";
  69. $(".examples, div.sourceCode").addClass("hasCopyButton");
  70. // Insert copy buttons:
  71. $(copyButton).prependTo(".hasCopyButton");
  72. // Initialize tooltips:
  73. $('.btn-copy-ex').tooltip({container: 'body'});
  74. // Initialize clipboard:
  75. var clipboardBtnCopies = new Clipboard('[data-clipboard-copy]', {
  76. text: function(trigger) {
  77. return trigger.parentNode.textContent;
  78. }
  79. });
  80. clipboardBtnCopies.on('success', function(e) {
  81. changeTooltipMessage(e.trigger, 'Copied!');
  82. e.clearSelection();
  83. });
  84. clipboardBtnCopies.on('error', function() {
  85. changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
  86. });
  87. });
  88. }
  89. })(window.jQuery || window.$)