PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.5.4
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.5.4
5.5.4 5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 All 79 releases
← All changes | assets/js/clipboard.js +96 -42 3.4.2 → 5.5.4 View file →
@@ -1,50 +1,104 @@
1 -window.CTC = (function (window, document, navigator) {
2 - var textArea,
3 - copy;
1 +window.CTCWP = (function (window, document, navigator) {
2 + var textArea,
3 + copy;
4 4
5 - function isOS() {
6 - return navigator.userAgent.match(/ipad|iphone/i);
7 - }
5 + function isOS() {
6 + return navigator.userAgent.match( /ipad|iphone/i );
7 + }
8 8
9 - function createTextArea(text) {
10 - textArea = document.createElement('textArea');
11 - textArea.value = text;
12 - document.body.appendChild(textArea);
13 - }
9 + function createTextArea(text) {
10 + textArea = document.createElement( 'textArea' );
11 + textArea.value = text;
12 + document.body.appendChild( textArea );
13 + }
14 14
15 - function selectText() {
16 - var range,
17 - selection;
15 + function selectText() {
16 + var range,
17 + selection;
18 18
19 - if (isOS()) {
20 - range = document.createRange();
21 - range.selectNodeContents(textArea);
22 - selection = window.getSelection();
23 - selection.removeAllRanges();
24 - selection.addRange(range);
25 - textArea.setSelectionRange(0, 999999);
26 - } else {
27 - textArea.select();
28 - }
29 - }
19 + if (isOS()) {
20 + range = document.createRange();
21 + range.selectNodeContents( textArea );
22 + selection = window.getSelection();
23 + selection.removeAllRanges();
24 + selection.addRange( range );
25 + textArea.setSelectionRange( 0, 999999 );
26 + } else {
27 + textArea.select();
28 + }
29 + }
30 30
31 - function copyToClipboard() {
32 - document.execCommand('copy');
33 - document.body.removeChild(textArea);
31 + function copyToClipboard() {
32 + // Use modern Clipboard API (iOS 26+ compatible)
33 + if ( navigator.clipboard && navigator.clipboard.writeText ) {
34 + navigator.clipboard.writeText( textArea.value ).then(
35 + function() {
36 + document.body.removeChild( textArea );
37 + // Redirect to page.
38 + if ( typeof copyTheCode !== 'undefined' && copyTheCode.redirect_url ) {
39 + window.location.href = copyTheCode.redirect_url;
40 + }
41 + }
42 + ).catch(
43 + function() {
44 + // Fallback to legacy method if Clipboard API fails
45 + document.execCommand( 'copy' );
46 + document.body.removeChild( textArea );
47 + // Redirect to page.
48 + if ( typeof copyTheCode !== 'undefined' && copyTheCode.redirect_url ) {
49 + window.location.href = copyTheCode.redirect_url;
50 + }
51 + }
52 + );
53 + } else {
54 + // Fallback for older browsers
55 + document.execCommand( 'copy' );
56 + document.body.removeChild( textArea );
57 + // Redirect to page.
58 + if ( typeof copyTheCode !== 'undefined' && copyTheCode.redirect_url ) {
59 + window.location.href = copyTheCode.redirect_url;
60 + }
61 + }
62 + }
34 63
35 - // Redirect to page.
36 - if( copyTheCode.redirect_url ) {
37 - window.location.href = copyTheCode.redirect_url;
38 - }
39 - }
64 + copy = function (text) {
65 + createTextArea( text );
66 + selectText();
67 + copyToClipboard();
68 + }
40 69
41 - copy = function (text) {
42 - createTextArea(text);
43 - selectText();
44 - copyToClipboard();
45 - };
70 + copySelection = function ( source ) {
71 + const selection = window.getSelection()
72 + const range = document.createRange()
73 + range.selectNodeContents( source[0] )
74 + selection.removeAllRanges()
75 + selection.addRange( range )
76 +
77 + // Get selected text
78 + const selectedText = selection.toString();
79 +
80 + // Use modern Clipboard API (iOS 26+ compatible)
81 + if ( navigator.clipboard && navigator.clipboard.writeText ) {
82 + navigator.clipboard.writeText( selectedText ).then(
83 + function() {
84 + selection.removeAllRanges();
85 + }
86 + ).catch(
87 + function() {
88 + // Fallback to legacy method if Clipboard API fails
89 + document.execCommand( 'copy' );
90 + selection.removeAllRanges();
91 + }
92 + );
93 + } else {
94 + // Fallback for older browsers
95 + document.execCommand( 'copy' );
96 + selection.removeAllRanges();
97 + }
98 + }
46 99
47 - return {
48 - copy: copy
49 - };
50 -})(window, document, navigator);
100 + return {
101 + copy: copy,
102 + copySelection: copySelection,
103 + };
104 +})( window, document, navigator );