1+ var WorkflowContainer = {
2+ createCodeHeader : function ( text ) {
3+ const div = document . createElement ( "div" ) ;
4+ div . className = "codeHeader" ;
5+ div . innerHTML =
6+ '<span class="language">' + text + '</span>' +
7+ '<a class="btn border-0 code-action" href="#" title="Copy">' +
8+ ' <i class="bi bi-clipboard"></i>' +
9+ '</a>' ;
10+ return div ;
11+ } ,
12+ setCopyAlert : function ( element ) {
13+ const copyIcon = element . querySelector ( "i" ) ;
14+ element . classList . add ( "link-success" ) ;
15+ copyIcon . classList . add ( "bi-check-lg" ) ;
16+ copyIcon . classList . remove ( "bi-clipboard" ) ;
17+ setTimeout ( function ( ) {
18+ copyIcon . classList . remove ( "bi-check-lg" ) ;
19+ copyIcon . classList . add ( "bi-clipboard" ) ;
20+ element . classList . remove ( "link-success" ) ;
21+ } , 1000 ) ;
22+ } ,
23+ renderElement : function ( element ) {
24+ const img = element . querySelector ( "img" ) ;
25+ const workflowPath = img . src ;
26+ img . src = workflowPath . replace ( / \. [ ^ . ] + $ / , ".svg" ) ;
27+
28+ const codeHeader = WorkflowContainer . createCodeHeader ( "Workflow" ) ;
29+ const button = codeHeader . querySelector ( "a" ) ;
30+ button . addEventListener ( "click" , ( e ) => {
31+ e . preventDefault ( ) ;
32+ fetch ( workflowPath ) . then ( req => req . text ( ) ) . then ( contents => {
33+ navigator . clipboard . writeText ( contents ) ;
34+ WorkflowContainer . setCopyAlert ( button ) ;
35+ } ) ;
36+ } ) ;
37+
38+ const wrap = document . createElement ( "p" ) ;
39+ const parent = element . parentElement
40+ parent . insertBefore ( wrap , element ) ;
41+ wrap . appendChild ( codeHeader ) ;
42+ wrap . appendChild ( element ) ;
43+ } ,
44+ init : async function ( ) {
45+ for ( const element of document . getElementsByClassName ( "workflow" ) ) {
46+ WorkflowContainer . renderElement ( element )
47+ }
48+ }
49+ }
50+
51+ export default { }
52+ WorkflowContainer . init ( ) ;
0 commit comments