PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / 2.0.3
Admin Help Docs v2.0.3
2.0.3 2.0.2 2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / js / click-to-copy.js
admin-help-docs / inc / js Last commit date
click-to-copy.js 19 hours ago post-type-help-doc-imports.js 19 hours ago post-type-help-docs.js 19 hours ago qs-add.js 19 hours ago qs-remove.js 19 hours ago
click-to-copy.js
43 lines
1 jQuery( document ).ready( function( $ ) {
2
3 $( '.helpdocs-click-to-copy' ).on( 'click', function() {
4 var $this = $( this );
5 var textToCopy = $this.text().trim();
6
7 // Modern Clipboard API
8 if ( navigator.clipboard && window.isSecureContext ) {
9 navigator.clipboard.writeText( textToCopy ).then( function() {
10 showCopiedFeedback( $this );
11 } ).catch( function( err ) {
12 console.error( 'Unable to copy', err );
13 } );
14 } else {
15 // Fallback for non-HTTPS or older browsers
16 var $temp = $( '<textarea>' );
17 $( 'body' ).append( $temp );
18 $temp.val( textToCopy ).select();
19 try {
20 document.execCommand( 'copy' );
21 showCopiedFeedback( $this );
22 } catch ( err ) {
23 console.error( 'Fallback copy failed', err );
24 }
25 $temp.remove();
26 }
27 });
28
29 /**
30 * Helper to show the "Copied!" feedback
31 */
32 function showCopiedFeedback( $el ) {
33 if ( $el.find( '.helpdocs-copied-tip' ).length > 0 ) return;
34
35 var $tip = $( '<span class="helpdocs-copied-tip">' + helpdocs_click_to_copy.copied_text + '</span>' );
36 $el.append( $tip );
37
38 $tip.fadeIn( 200 ).delay( 1500 ).fadeOut( 400, function() {
39 $( this ).remove();
40 } );
41 }
42
43 });