Skip to content

Commit

Permalink
Bump ClipboardJS to 2.0.0 and remove hack
Browse files Browse the repository at this point in the history
This is no longer needed, since it no longer conflicts w/ the
built-in global.
  • Loading branch information
mAAdhaTTah committed Mar 1, 2018
1 parent 11f5517 commit e9f410e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "MIT",
"readmeFilename": "README.md",
"optionalDependencies": {
"clipboard": "^1.7.1"
"clipboard": "^2.0.0"
},
"devDependencies": {
"chai": "^2.3.0",
Expand Down
22 changes: 9 additions & 13 deletions plugins/copy-to-clipboard/prism-copy-to-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,37 @@
return;
}

var Clipboard = window.Clipboard || undefined;
var ClipboardJS = window.ClipboardJS || undefined;

if (Clipboard && /(native code)/.test(Clipboard.toString())) {
Clipboard = undefined;
}

if (!Clipboard && typeof require === 'function') {
Clipboard = require('clipboard');
if (!ClipboardJS && typeof require === 'function') {
ClipboardJS = require('clipboard');
}

var callbacks = [];

if (!Clipboard) {
if (!ClipboardJS) {
var script = document.createElement('script');
var head = document.querySelector('head');

script.onload = function() {
Clipboard = window.Clipboard;
ClipboardJS = window.ClipboardJS;

if (Clipboard) {
if (ClipboardJS) {
while (callbacks.length) {
callbacks.pop()();
}
}
};

script.src = 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js';
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('a');
linkCopy.textContent = 'Copy';

if (!Clipboard) {
if (!ClipboardJS) {
callbacks.push(registerClipboard);
} else {
registerClipboard();
Expand All @@ -52,7 +48,7 @@
return linkCopy;

function registerClipboard() {
var clip = new Clipboard(linkCopy, {
var clip = new ClipboardJS(linkCopy, {
'text': function () {
return env.code;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9f410e

Please sign in to comment.