File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -87,5 +87,24 @@ layout: source
8787 }
8888 } )
8989 }
90+
91+ if ( navigator && navigator . clipboard ) {
92+ const copyCodeButtons = document . querySelectorAll ( '[class^="language-"] button' ) ;
93+
94+ copyCodeButtons . forEach ( function ( button ) {
95+ const codeElement = button . parentElement . querySelector ( 'code' ) ;
96+ const originalText = button . innerText ;
97+
98+ button . addEventListener ( 'mousedown' , async function ( ) {
99+ await navigator . clipboard . writeText ( codeElement . innerText ) ;
100+
101+ button . innerText = 'Copied!' ;
102+
103+ setTimeout ( ( ) => {
104+ button . innerText = originalText ;
105+ } , 1000 ) ;
106+ } ) ;
107+ } ) ;
108+ }
90109 } ) ;
91110} ) ( ) ;
Original file line number Diff line number Diff line change 99 background-color : var (--color-fill-secondary );
1010 border : 1px solid var (--color-fill-tertiary );
1111 border-radius : var (--border-radius );
12-
12+
1313 padding : 1rem ;
1414 display : flex ;
1515 flex-direction : column ;
7777}
7878
7979// Button typically embedded in a grid-level-1
80- a .cta-secondary {
80+ a .cta-secondary , [ class ^= " language- " ] button {
8181 background-color : var (--color-fill-tertiary );
8282 border : 1px solid var (--color-fill-quaternary );
8383 border-radius : var (--border-radius );
@@ -99,7 +99,7 @@ a.cta-secondary {
9999 & :hover {
100100 color : var (--color-link );
101101 background-color : var (--color-fill-quaternary );
102-
102+
103103 text-decoration : none ;
104104
105105 @media (prefers-contrast : more) {
@@ -112,3 +112,10 @@ a.cta-secondary {
112112 content : " ↗" ;
113113 }
114114}
115+
116+ [class ^= " language-" ] button {
117+ cursor : pointer ;
118+ padding : 0.1rem 0.4rem ;
119+ margin-left : auto ;
120+ font-size : 0.8rem ;
121+ }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ title: Install Swift
1313 To download toolchains from Swift.org, use the Swiftly toolchain installer. Swift.org toolchains include experimental features like Embedded Swift and support for WebAssembly.
1414 </p >
1515 <h4 >Run this in a terminal:</h4 >
16- <div class =" language-plaintext highlighter-rouge " ><div class =" highlight " ><pre class =" highlight " ><code >curl -O https://download.swift.org/swiftly/darwin/swiftly-{{ site.data.builds.swiftly_release.version }}.pkg & ;& ; \
16+ <div class =" language-plaintext highlighter-rouge " ><button >Copy code</ button >< div class =" highlight " ><pre class =" highlight " ><code >curl -O https://download.swift.org/swiftly/darwin/swiftly-{{ site.data.builds.swiftly_release.version }}.pkg & ;& ; \
1717installer -pkg swiftly-{{ site.data.builds.swiftly_release.version }}.pkg -target CurrentUserHomeDirectory & ;& ; \
1818~ /usr/local/bin/swiftly init --quiet-shell-followup & ;& ; \
1919. ~ /Library/Application\ Support/swiftly/env.sh & ;& ; \
You can’t perform that action at this time.
0 commit comments