@@ -15,15 +15,21 @@ export default class extends Controller {
1515
1616 // Update share icons for native sharing support
1717 if ( navigator . share ) {
18+ const ownershipLinkIcon = document . querySelector ( '#share-ownership-link i' )
19+ if ( ownershipLinkIcon ) {
20+ ownershipLinkIcon . classList . remove ( 'bi-shield-fill-check' )
21+ ownershipLinkIcon . classList . add ( 'bi-share' )
22+ }
23+
1824 const editLinkIcon = document . querySelector ( '#share-edit-link i' )
1925 if ( editLinkIcon ) {
20- editLinkIcon . classList . remove ( 'bi-link-45deg ' )
26+ editLinkIcon . classList . remove ( 'bi-pencil-square ' )
2127 editLinkIcon . classList . add ( 'bi-share' )
2228 }
2329
2430 const viewLinkIcon = document . querySelector ( '#share-view-link i' )
2531 if ( viewLinkIcon ) {
26- viewLinkIcon . classList . remove ( 'bi-link-45deg ' )
32+ viewLinkIcon . classList . remove ( 'bi-eye-fill ' )
2733 viewLinkIcon . classList . add ( 'bi-share' )
2834 }
2935 }
@@ -41,36 +47,39 @@ export default class extends Controller {
4147 copyOwnershipLink ( e ) {
4248 e . preventDefault ( )
4349 const ownershipLink = window . location . origin + document . querySelector ( '#share-ownership-link a' ) . getAttribute ( 'href' )
44- this . copyToClipboard ( ownershipLink , "Ownership link copied" )
50+ this . copyToClipboard ( ownershipLink , "Ownership link copied" , e . currentTarget )
4551 }
4652
4753 copyEditLink ( e ) {
4854 e . preventDefault ( )
4955 const editLink = window . location . origin + document . querySelector ( '#share-edit-link a' ) . getAttribute ( 'href' )
50- this . copyToClipboard ( editLink , "Edit link copied" )
56+ this . copyToClipboard ( editLink , "Edit link copied" , e . currentTarget )
5157 }
5258
5359 copyViewLink ( e ) {
5460 e . preventDefault ( )
5561 const viewLink = window . location . origin + document . querySelector ( '#share-view-link a' ) . getAttribute ( 'href' )
56- this . copyToClipboard ( viewLink , "View link copied" )
62+ this . copyToClipboard ( viewLink , "View link copied" , e . currentTarget )
5763 }
5864
59- copyToClipboard ( text , successMessage ) {
65+ copyToClipboard ( text , successMessage , iconElement = null ) {
6066 // Try modern clipboard API first
6167 if ( navigator . clipboard && navigator . clipboard . writeText ) {
6268 navigator . clipboard . writeText ( text ) . then ( ( ) => {
6369 status ( successMessage )
70+ if ( iconElement ) {
71+ this . showCopySuccess ( iconElement )
72+ }
6473 } ) . catch ( ( ) => {
65- this . fallbackCopyToClipboard ( text , successMessage )
74+ this . fallbackCopyToClipboard ( text , successMessage , iconElement )
6675 } )
6776 } else {
6877 // Fallback for non-secure contexts
69- this . fallbackCopyToClipboard ( text , successMessage )
78+ this . fallbackCopyToClipboard ( text , successMessage , iconElement )
7079 }
7180 }
7281
73- fallbackCopyToClipboard ( text , successMessage ) {
82+ fallbackCopyToClipboard ( text , successMessage , iconElement = null ) {
7483 const textArea = document . createElement ( 'textarea' )
7584 textArea . value = text
7685 textArea . style . position = 'fixed'
@@ -83,6 +92,9 @@ export default class extends Controller {
8392 try {
8493 document . execCommand ( 'copy' )
8594 status ( successMessage )
95+ if ( iconElement ) {
96+ this . showCopySuccess ( iconElement )
97+ }
8698 } catch ( err ) {
8799 status ( "Failed to copy link" )
88100 console . error ( 'Fallback copy failed:' , err )
@@ -91,6 +103,27 @@ export default class extends Controller {
91103 document . body . removeChild ( textArea )
92104 }
93105
106+ showCopySuccess ( iconElement ) {
107+ // Find the actual icon element
108+ const icon = iconElement . querySelector ( 'i' ) || iconElement
109+
110+ // Store original classes
111+ const wasCheck = icon . classList . contains ( 'bi-check2' )
112+
113+ // Don't animate if already showing success
114+ if ( wasCheck ) return
115+
116+ // Change to checkmark with success styling
117+ icon . classList . remove ( 'bi-copy' )
118+ icon . classList . add ( 'bi-check2' , 'copy-success' )
119+
120+ // Revert after 2 seconds
121+ setTimeout ( ( ) => {
122+ icon . classList . remove ( 'bi-check2' , 'copy-success' )
123+ icon . classList . add ( 'bi-copy' )
124+ } , 2000 )
125+ }
126+
94127 nativeShareOwnershipLink ( e ) {
95128 if ( navigator . share ) {
96129 e . preventDefault ( )
@@ -127,6 +160,6 @@ export default class extends Controller {
127160 copyEmbedCode ( e ) {
128161 e . preventDefault ( )
129162 const embedCode = document . querySelector ( '#embed-code' ) . value
130- this . copyToClipboard ( embedCode , "Embed code copied" )
163+ this . copyToClipboard ( embedCode , "Embed code copied" , e . currentTarget )
131164 }
132165}
0 commit comments