08-27-周三_17-09-29
This commit is contained in:
75
node_modules/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.js
generated
vendored
Normal file
75
node_modules/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
(function(){
|
||||
if (typeof self === 'undefined' || !self.Prism || !self.document) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Prism.plugins.toolbar) {
|
||||
console.warn('Copy to Clipboard plugin loaded before Toolbar plugin.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var ClipboardJS = window.ClipboardJS || undefined;
|
||||
|
||||
if (!ClipboardJS && typeof require === 'function') {
|
||||
ClipboardJS = require('clipboard');
|
||||
}
|
||||
|
||||
var callbacks = [];
|
||||
|
||||
if (!ClipboardJS) {
|
||||
var script = document.createElement('script');
|
||||
var head = document.querySelector('head');
|
||||
|
||||
script.onload = function() {
|
||||
ClipboardJS = window.ClipboardJS;
|
||||
|
||||
if (ClipboardJS) {
|
||||
while (callbacks.length) {
|
||||
callbacks.pop()();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js';
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
Prism.plugins.toolbar.registerButton('copy-to-clipboard', function (env) {
|
||||
var linkCopy = document.createElement('button');
|
||||
linkCopy.textContent = 'Copy';
|
||||
|
||||
if (!ClipboardJS) {
|
||||
callbacks.push(registerClipboard);
|
||||
} else {
|
||||
registerClipboard();
|
||||
}
|
||||
|
||||
return linkCopy;
|
||||
|
||||
function registerClipboard() {
|
||||
var clip = new ClipboardJS(linkCopy, {
|
||||
'text': function () {
|
||||
return env.code;
|
||||
}
|
||||
});
|
||||
|
||||
clip.on('success', function() {
|
||||
linkCopy.textContent = 'Copied!';
|
||||
|
||||
resetText();
|
||||
});
|
||||
clip.on('error', function () {
|
||||
linkCopy.textContent = 'Press Ctrl+C to copy';
|
||||
|
||||
resetText();
|
||||
});
|
||||
}
|
||||
|
||||
function resetText() {
|
||||
setTimeout(function () {
|
||||
linkCopy.textContent = 'Copy';
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
})();
|
1
node_modules/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js
generated
vendored
Normal file
1
node_modules/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(){if("undefined"!=typeof self&&self.Prism&&self.document)if(Prism.plugins.toolbar){var r=window.ClipboardJS||void 0;r||"function"!=typeof require||(r=require("clipboard"));var i=[];if(!r){var o=document.createElement("script"),e=document.querySelector("head");o.onload=function(){if(r=window.ClipboardJS)for(;i.length;)i.pop()()},o.src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js",e.appendChild(o)}Prism.plugins.toolbar.registerButton("copy-to-clipboard",function(e){var t=document.createElement("button");return t.textContent="Copy",r?o():i.push(o),t;function o(){var o=new r(t,{text:function(){return e.code}});o.on("success",function(){t.textContent="Copied!",n()}),o.on("error",function(){t.textContent="Press Ctrl+C to copy",n()})}function n(){setTimeout(function(){t.textContent="Copy"},5e3)}})}else console.warn("Copy to Clipboard plugin loaded before Toolbar plugin.")}();
|
Reference in New Issue
Block a user