Skip to content

Commit c1f9b26

Browse files
committed
Make copy-to-clipboard functionality more generic
See #2061.
1 parent bc77e7a commit c1f9b26

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

textpattern/include/txp_diag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ function doDiagnostics()
647647
inputLabel(
648648
'diag_clear_private',
649649
checkbox('diag_clear_private', 1, false, 0, 'diag_clear_private').'<span class="txp-textarea-options">
650-
<button class="action-copy txp-reduced-ui-button"><span class="ui-icon ui-icon-clipboard"></span> ' . gTxt('copy_to_clipboard') . '</button>
650+
<button class="action-copy-clip txp-reduced-ui-button" data-source="#diagnostics-detail"><span class="ui-icon ui-icon-clipboard"></span> ' . gTxt('copy_to_clipboard') . '</button>
651651
</span>',
652652
'diag_clear_private', 'diag_clear_private', array('class' => 'txp-form-field'),
653653
''

textpattern/textpattern.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,11 +2595,6 @@ textpattern.Route.add('diag', function () {
25952595
$('#diagnostics-detail').val(diag_data);
25962596
});
25972597
$('#diag_clear_private').change();
2598-
$('.action-copy').click(function(ev) {
2599-
ev.preventDefault();
2600-
let diagData = $('#diagnostics-detail').val();
2601-
navigator.clipboard.writeText(diagData);
2602-
});
26032598
});
26042599

26052600
// Languages panel.
@@ -2848,6 +2843,17 @@ textpattern.Route.add('', function () {
28482843
}
28492844
});
28502845

2846+
// Copy to clipboard.
2847+
$('.action-copy-clip').click(function(ev) {
2848+
ev.preventDefault();
2849+
let source = $(this).data('source');
2850+
let $source = $(source);
2851+
2852+
if ($source.length) {
2853+
navigator.clipboard.writeText($source.val());
2854+
}
2855+
});
2856+
28512857
// Pane states
28522858
var hasTabs = $('.txp-layout:has(.switcher-list li a[data-txp-pane])');
28532859

0 commit comments

Comments
 (0)