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.

41 lines
1.2 KiB

  1. $(function() {
  2. if (/Mac/i.test(navigator.userAgent)) {
  3. // No support for Safari :(
  4. return;
  5. }
  6. var markup = '<button class="btn btn-default hidden-sm">' +
  7. '<span class="ic-clippy"></span>' +
  8. '</button>';
  9. $(".highlight").append(markup);
  10. var reBlankLines = new RegExp("^\\s*[\\r\\n]", "gm");
  11. var reTrailingWhitespace = new RegExp("\\s+$");
  12. var clipboard = new Clipboard(".highlight button", {
  13. text: function (trigger) {
  14. var snippetElement = $(trigger).parent().children().clone();
  15. /* remove pygmentize comment elements */
  16. snippetElement.find(".c, .cm, .cp, .c1, .cs").remove();
  17. /* remove blank lines and trailing whitespace */
  18. return snippetElement.text().replace(reBlankLines, '').replace(reTrailingWhitespace, '');
  19. }
  20. });
  21. clipboard.on("success", function(e) {
  22. $(e.trigger)
  23. .tooltip({title: "Copied!", trigger: "hover"})
  24. .tooltip("show")
  25. .on("hidden.bs.tooltip", function(){
  26. $(this).tooltip("destroy");
  27. })
  28. });
  29. clipboard.on("error", function(e) {
  30. prompt("Press Ctrl+C to select:", e.text)
  31. });
  32. });