forked from OneJane/OneJane.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.js
1 lines (1 loc) · 1.2 KB
/
copy.js
1
$(function(){$("figure.highlight").wrap('<div class="code-area-wrap"></div>');var e=$('<i class="fa fa-clipboard" aria-hidden="true"></i>'),a=$('<div class="copy-notice"></div>'),o=$('<span class="codeblock-language"></span>');$(".code-area-wrap").prepend(e),$(".code-area-wrap").prepend(a),$(".code-area-wrap").prepend(o),$(".code-area-wrap").each(function(e,a){var o=$(a).find("figure.highlight").attr("class").replace("highlight","").trim();$(a).find(".codeblock-language").text(o)}),$(".code-area-wrap .fa-clipboard").on("click",function(){var e=window.getSelection(),a=document.createRange();a.selectNodeContents($(this).siblings("figure").find(".code pre")[0]),e.removeAllRanges(),e.addRange(a);e.toString();!function(e,a){if(document.queryCommandSupported&&document.queryCommandSupported("copy"))try{document.execCommand("copy"),$(a).prev(".copy-notice").text(GLOBAL_CONFIG.copy.success).velocity({translateX:-30,opacity:1},{loop:1,duration:750,easing:"easeOutQuint"})}catch(e){return $(a).prev(".copy-notice").text(GLOBAL_CONFIG.copy.error).velocity({translateX:-30,opacity:1},{loop:1,duration:750,easing:"easeOutQuint"})}else $(a).prev(".copy-notice").text(GLOBAL_CONFIG.copy.noSupport)}(0,this),e.removeAllRanges()})});