mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
clipboard: remove trailing line break from copied text #175
This commit is contained in:
parent
e4f0ed138c
commit
d850ea528d
1 changed files with 7 additions and 2 deletions
|
@ -341,18 +341,23 @@ jQuery(function() {
|
||||||
var clip = new ClipboardJS('.copy-to-clipboard-button', {
|
var clip = new ClipboardJS('.copy-to-clipboard-button', {
|
||||||
text: function(trigger) {
|
text: function(trigger) {
|
||||||
var text = $(trigger).prev('code').text();
|
var text = $(trigger).prev('code').text();
|
||||||
|
// remove a trailing line break, this may most likely
|
||||||
|
// come from the browser / Hugo transformation
|
||||||
|
text = text.replace(/\n$/, '');
|
||||||
|
// removes leading $ signs from text in an assumption
|
||||||
|
// that this has to be the unix prompt marker - weird
|
||||||
return text.replace(/^\$\s/gm, '');
|
return text.replace(/^\$\s/gm, '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
clip.on('success', function(e) {
|
clip.on('success', function(e) {
|
||||||
e.clearSelection();
|
e.clearSelection();
|
||||||
var inPre = $(e.trigger).parent().parent().prop('tagName') == 'PRE';
|
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
||||||
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
});
|
});
|
||||||
|
|
||||||
clip.on('error', function(e) {
|
clip.on('error', function(e) {
|
||||||
var inPre = $(e.trigger).parent().parent().prop('tagName') == 'PRE';
|
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
||||||
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
$(document).one('copy', function(){
|
$(document).one('copy', function(){
|
||||||
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
|
|
Loading…
Reference in a new issue