11/* global hljs */
22'use strict'
33
4- $ ( document ) . ready ( function ( ) {
4+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
55 hljs . highlightAll ( )
66
77 const snippets = document . getElementsByTagName ( 'pre' )
@@ -10,44 +10,50 @@ $(document).ready(function () {
1010 snippets [ i ] . innerHTML = '<button id="button' + ( i + 1 ) + '" class="hljs-copy btn btn-secondary btn-copy-to-clipboard mt-2 me-2 float-end"><i class="fa fa-copy"></i> Copy</button>' + snippets [ i ] . innerHTML
1111 }
1212
13- $ ( '.btn-copy-to-clipboard' ) . on ( 'click' , function ( event ) {
14- let codeBlockId
15- if ( this . id === 'button1' ) {
16- codeBlockId = 'code-block1'
17- } else {
18- codeBlockId = 'code-block2'
19- }
20-
21- const codeContent = document . getElementById ( codeBlockId ) . textContent
22- const textArea = document . createElement ( 'textarea' )
23- textArea . textContent = codeContent
24- document . body . append ( textArea )
25-
26- textArea . select ( )
27- document . execCommand ( 'copy' )
28-
29- textArea . remove ( )
13+ const copyButtons = document . querySelectorAll ( '.btn-copy-to-clipboard' )
14+ copyButtons . forEach ( button => {
15+ button . addEventListener ( 'click' , function ( ) {
16+ let codeBlockId
17+ if ( this . id === 'button1' ) {
18+ codeBlockId = 'code-block1'
19+ } else {
20+ codeBlockId = 'code-block2'
21+ }
22+
23+ const codeContent = document . getElementById ( codeBlockId ) . textContent
24+ const textArea = document . createElement ( 'textarea' )
25+ textArea . textContent = codeContent
26+ document . body . append ( textArea )
27+
28+ textArea . select ( )
29+ document . execCommand ( 'copy' )
30+
31+ textArea . remove ( )
32+ } )
3033 } )
3134
32- $ ( '.btn-download-file' ) . on ( 'click' , function ( event ) {
33- let codeBlockId
34- let filename
35- if ( this . id === 'download-button1' ) {
36- codeBlockId = 'code-block1'
37- filename = 'irods_environment.json'
38- } else {
39- codeBlockId = 'code-block2'
40- filename = 'config.yml'
41- }
42-
43- const codeContent = document . getElementById ( codeBlockId ) . textContent
44- const link = document . createElement ( 'a' )
45- const file = new Blob ( [ codeContent ] , { type : 'text/plain' } )
46-
47- link . href = URL . createObjectURL ( file )
48- link . download = filename
49- link . click ( )
50-
51- URL . revokeObjectURL ( link . href )
35+ const downloadButtons = document . querySelectorAll ( '.btn-download-file' )
36+ downloadButtons . forEach ( button => {
37+ button . addEventListener ( 'click' , function ( ) {
38+ let codeBlockId
39+ let filename
40+ if ( this . id === 'download-button1' ) {
41+ codeBlockId = 'code-block1'
42+ filename = 'irods_environment.json'
43+ } else {
44+ codeBlockId = 'code-block2'
45+ filename = 'config.yml'
46+ }
47+
48+ const codeContent = document . getElementById ( codeBlockId ) . textContent
49+ const link = document . createElement ( 'a' )
50+ const file = new Blob ( [ codeContent ] , { type : 'text/plain' } )
51+
52+ link . href = URL . createObjectURL ( file )
53+ link . download = filename
54+ link . click ( )
55+
56+ URL . revokeObjectURL ( link . href )
57+ } )
5258 } )
5359} )
0 commit comments