😎 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.

116 lines
3.3KB

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