Making WordPress.org

Changeset 12386


Ignore:
Timestamp:
02/03/2023 07:46:05 AM (21 months ago)
Author:
coffee2code
Message:

Photo Directory: Fix Rich Text copy-to-clipboard.

See #6097.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-photos/js/attribution.js

    r12385 r12386  
    66
    77function copyAttribution(event){
     8    document.addEventListener('copy', copyAttributionListener);
     9    document.execCommand('copy');
     10    document.removeEventListener('copy', copyAttributionListener);
     11}
     12
     13function copyAttributionListener(event) {
    814    event.preventDefault();
    915    const attribution = document.querySelector('.attribution-text .tab.active');
    1016    const copyButton  = document.querySelector('.attribution-copy');
    1117
    12     let txt = attribution.innerHTML;
     18    let txt = attribution.innerHTML.trim();
    1319
    1420    if ( attribution.classList.contains('tab-html') ) {
     
    1622    }
    1723   
    18     navigator.clipboard.writeText(txt.trim()).then(res=>{
    19         copyButton.textContent = PhotoDir.copied_text;
    20         setTimeout(function() { restoreCopyButtonText(); }, 4000);
    21           function restoreCopyButtonText(){ copyButton.textContent = PhotoDir.copy_to_clipboard_text; }
    22     })
     24    let html = attribution.classList.contains('tab-rich-text') ? txt : '';
     25
     26    event.clipboardData.setData('text/html', html);
     27    event.clipboardData.setData('text/plain', txt);
     28
     29    copyButton.textContent = PhotoDir.copied_text;
     30    setTimeout(function() { restoreCopyButtonText(); }, 4000);
     31    function restoreCopyButtonText(){ copyButton.textContent = PhotoDir.copy_to_clipboard_text; }
    2332}
    2433
Note: See TracChangeset for help on using the changeset viewer.