@@ -13,6 +13,8 @@ let viewMarkdown = true
13
13
14
14
let iscurrentfilemd = false
15
15
16
+ let mdsource = ""
17
+
16
18
toggleExamples = ( mode ) => {
17
19
if ( mode ) {
18
20
subnav . children [ 1 ] . style . display = 'block'
@@ -58,12 +60,13 @@ loadExamplefromGitHub = (name, dir, editor) => {
58
60
}
59
61
examplecode . style . display = 'flex'
60
62
examplewelcome . style . display = 'none'
63
+ showExample ( viewMarkdown )
61
64
editor . setValue ( data )
62
65
highlightKeyword ( editor )
63
- showExample ( viewMarkdown )
64
66
}
65
67
66
68
function loadmd ( data ) {
69
+ mdsource = data ;
67
70
iscurrentfilemd = true ;
68
71
var byClass = document . getElementsByClassName ( "strip-button" ) ;
69
72
for ( var i = 0 ; i < byClass . length ; i ++ ) {
@@ -331,6 +334,36 @@ fetch('/_static/json/all_examples.json')
331
334
} )
332
335
} )
333
336
337
+ var copybutton = document . createElement ( 'button' )
338
+ copybutton . className = 'copy-button'
339
+ copybutton . style . top = '0rem'
340
+ copybutton . innerHTML = '<span class="clipboard-message">.edp copied to clipboard</span><i class="far fa-clone"></i>'
341
+ copybutton . onclick = function ( e ) {
342
+ const textarea = document . createElement ( 'textarea' )
343
+ if ( iscurrentfilemd && viewMarkdown ) {
344
+ copybutton . innerHTML = '<span class="clipboard-message">.md copied to clipboard</span><i class="far fa-clone"></i>'
345
+ textarea . value = mdsource
346
+ }
347
+ else {
348
+ copybutton . innerHTML = '<span class="clipboard-message">.edp copied to clipboard</span><i class="far fa-clone"></i>'
349
+ textarea . value = editor . getValue ( )
350
+ }
351
+ textarea . setAttribute ( 'readonly' , '' )
352
+ textarea . style . position = 'absolute'
353
+ textarea . style . left = '-9999px'
354
+ document . body . appendChild ( textarea )
355
+ textarea . select ( )
356
+ document . execCommand ( 'copy' )
357
+ document . body . removeChild ( textarea )
358
+
359
+ this . children [ 0 ] . classList . toggle ( 'clipboard-message--active' )
360
+ setTimeout ( ( ) => {
361
+ this . children [ 0 ] . classList . remove ( 'clipboard-message--active' )
362
+ } , 2000 )
363
+ }
364
+ const examplecopybutton = document . getElementById ( 'ExampleCopyButton' )
365
+ examplecopybutton . appendChild ( copybutton )
366
+
334
367
var bs1 = new ButtonStrip ( {
335
368
id : 'buttonStrip1'
336
369
} ) ;
0 commit comments