-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: Fix events.
- Loading branch information
Showing
6 changed files
with
817 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* jshint browser:true */ | ||
/* global Clipboard:true */ | ||
|
||
(function() { | ||
'use strict'; | ||
|
||
var selectors = document.querySelectorAll('pre code[class^="lang-"]'); | ||
|
||
Array.prototype.forEach.call(selectors, function(selector){ | ||
|
||
var btnHtml = '<div class="clipboard">' + | ||
'<span class="btn btn-clipboard" title="Copy to clipboard">Copy</span>' + | ||
'</div>'; | ||
selector.insertAdjacentHTML('beforebegin', btnHtml); | ||
|
||
var clipboard = new Clipboard('.btn-clipboard', { | ||
target: function (trigger) { | ||
return trigger.parentNode.nextElementSibling; | ||
} | ||
}); | ||
|
||
clipboard.on('success', function (e) { | ||
e.clearSelection(); | ||
selector.setAttribute('title', 'Copied!'); | ||
//e.trigger; | ||
}); | ||
|
||
clipboard.on('error', function (/*e*/) { | ||
var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318 to copy' : 'Press Ctrl-C to copy'; | ||
selector.setAttribute('title', fallbackMsg); | ||
//e.trigger; | ||
}); | ||
|
||
}); | ||
|
||
})(); |
Oops, something went wrong.