Make WordPress Core

Ticket #48463: 48463.patch

File 48463.patch, 3.8 KB (added by sajjad67, 5 years ago)

Feature to auto copy Media Link to clipboard when clicked 'Copy Link' label

  • src/js/media/views/attachment/details.js

     
    2323                'click .trash-attachment':        'trashAttachment',
    2424                'click .untrash-attachment':      'untrashAttachment',
    2525                'click .edit-attachment':         'editAttachment',
     26                'click .copy-attachment-url':     'copyAttachmentLink',
    2627                'keydown':                        'toggleSelectionHandler'
    2728        },
    2829
    2930        /**
     31         * Copies the attachment link to the clipboard.
     32         *
     33         * Browser support for Chrome 43+, Firefox 42+, Safari 10+, Edge and Internet Explorer 10+
     34         *
     35         * @since 5.2.0
     36         *
     37         * @param {MouseEvent} event A click event.
     38         *
     39         * @returns {void}
     40         */
     41        copyAttachmentLink: function( event ) {
     42
     43                var successful = false;
     44               
     45                // Copy Link Label
     46                var AttachmentLinkLabel = document.querySelector( 'label.name.copy-attachment-url' );
     47               
     48                // Attachment Input
     49                var AttachmentLink = document.querySelector( '#attachment-details-two-column-copy-link' );
     50
     51                // Set the focus to the input
     52                AttachmentLink.focus();
     53           
     54            // Select the input text
     55            AttachmentLink.select();
     56
     57            // especially for IE
     58            if (window.clipboardData && window.clipboardData.setData) {
     59
     60                successful = clipboardData.setData( "Text", AttachmentLink.value );
     61
     62            }
     63            // checking for browser support
     64            else if ( document.queryCommandSupported && document.queryCommandSupported( "copy" ) ) {
     65
     66                        try {
     67                       
     68                        // process the 'copy' cmd
     69                        var successful = document.execCommand( 'copy' );
     70                   
     71                    // let user know copy didn't happen
     72                    } catch ( err ) {
     73                       
     74                        alert( 'Sorry, unable to copy', err );
     75                }
     76                }
     77
     78                // copy did successfully completed
     79                if ( successful ) {
     80
     81                // show 'Link Copied' text 1s animation
     82                AttachmentLinkLabel.classList.add("copied");
     83
     84                // remove 'Link Copied' text after 2s
     85                setTimeout(function(){
     86
     87                        AttachmentLinkLabel.classList.remove("copied");
     88
     89                }, 2000 );
     90        }
     91        },
     92
     93        /**
    3094         * Shows the details of an attachment.
    3195         *
    3296         * @since 3.5.0
  • src/wp-admin/css/media.css

     
    12811281                max-width: 100%;
    12821282        }
    12831283}
     1284
     1285@keyframes showCopiedText {
     1286  0% {
     1287    opacity: 0;
     1288  }
     1289  100% {
     1290    opacity: 1;
     1291  }
     1292}
     1293
     1294label.name.copy-attachment-url.copied:before {
     1295    position: absolute;
     1296    content: 'Link Copied!';
     1297    bottom: 30px;
     1298    left: 5px;
     1299    color: white;
     1300    background: green;
     1301    padding: 2px 8px;
     1302    border-radius: 3px;
     1303    -webkit-animation: showCopiedText 1s normal forwards;
     1304    -moz-animation: showCopiedText 1s normal forwards;
     1305    -o-animation: showCopiedText 1s normal forwards;
     1306    animation: showCopiedText 1s normal forwards;
     1307}
     1308 No newline at end of file
  • src/wp-includes/media-template.php

     
    501501                                        </span>
    502502                                <# } #>
    503503                                <span class="setting" data-setting="url">
    504                                         <label for="attachment-details-two-column-copy-link" class="name"><?php _e( 'Copy Link' ); ?></label>
     504                                        <label for="attachment-details-two-column-copy-link" class="name copy-attachment-url"><?php _e( 'Copy Link' ); ?></label>
    505505                                        <input type="text" id="attachment-details-two-column-copy-link" value="{{ data.url }}" readonly />
    506506                                </span>
    507507                                <div class="attachment-compat"></div>