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.

plugin-clipboard.js 907B

пре 5 година
1234567891011121314151617181920212223242526272829
  1. gitbook.require(["gitbook", "jQuery"], function(gitbook, $) {
  2. var copyButton = '<button type="button" class="copy-to-clipboard-button" title="Copy to clipboard" aria-label="Copy to clipboard"><i class="fa fa-copy"></i></button>';
  3. var clipboard;
  4. gitbook.events.bind("page.change", function() {
  5. if (!ClipboardJS.isSupported()) return;
  6. // the page.change event is thrown twice: before and after the page changes
  7. if (clipboard) {
  8. // clipboard is already defined
  9. // we can deduct that we are before page changes
  10. clipboard.destroy(); // destroy the previous events listeners
  11. clipboard = undefined; // reset the clipboard object
  12. return;
  13. }
  14. $(copyButton).prependTo("div.sourceCode");
  15. clipboard = new ClipboardJS(".copy-to-clipboard-button", {
  16. text: function(trigger) {
  17. return trigger.parentNode.textContent;
  18. }
  19. });
  20. });
  21. });