@@ -247,7 +247,9 @@ <h4 class="modal-title" id="step-collection-modal-label">Response</h4>
247
247
{% endhighlight %}
248
248
</ p > </ div >
249
249
< div class ="modal-footer ">
250
+ < button type ="button " class ="btn btn-secondary btn-copy-code " onclick ="copyCode() "> Copy</ button >
250
251
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
252
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
251
253
</ div >
252
254
</ p > </ div >
253
255
</ p > </ div >
@@ -296,7 +298,9 @@ <h4 class="modal-title" id="step-individual-modal-label">Response</h4>
296
298
{% endhighlight %}
297
299
</ p > </ div >
298
300
< div class ="modal-footer ">
301
+ < button type ="button " class ="btn btn-secondary btn-copy-code " aria-live ="assertive " onclick ="copyCode() "> Copy</ button >
299
302
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
303
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
300
304
</ div >
301
305
</ p > </ div >
302
306
</ p > </ div >
@@ -336,7 +340,9 @@ <h4 class="modal-title" id="step-query-modal-label">Response</h4>
336
340
{% endhighlight %}
337
341
</ p > </ div >
338
342
< div class ="modal-footer ">
343
+ < button type ="button " class ="btn btn-secondary btn-copy-code " aria-live ="assertive " onclick ="copyCode() "> Copy</ button >
339
344
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
345
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
340
346
</ div >
341
347
</ p > </ div >
342
348
</ p > </ div >
@@ -359,7 +365,9 @@ <h4 class="modal-title" id="step-post-modal-label">Response</h4>
359
365
{% endhighlight %}
360
366
</ p > </ div >
361
367
< div class ="modal-footer ">
368
+ < button type ="button " class ="btn btn-secondary btn-copy-code " aria-live ="assertive " onclick ="copyCode() "> Copy</ button >
362
369
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
370
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
363
371
</ div >
364
372
</ p > </ div >
365
373
</ p > </ div >
@@ -378,7 +386,9 @@ <h4 class="modal-title" id="step-relationship-modal-label">Response</h4>
378
386
{% endhighlight %}
379
387
</ p > </ div >
380
388
< div class ="modal-footer ">
389
+ < button type ="button " class ="btn btn-secondary btn-copy-code " aria-live ="assertive " onclick ="copyCode() "> Copy</ button >
381
390
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
391
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
382
392
</ div >
383
393
</ p > </ div >
384
394
</ p > </ div >
@@ -453,7 +463,9 @@ <h4 class="modal-title" id="step-function-modal-label">Response</h4>
453
463
{% endhighlight %}
454
464
</ p > </ div >
455
465
< div class ="modal-footer ">
466
+ < button type ="button " class ="btn btn-secondary btn-copy-code " aria-live ="assertive " onclick ="copyCode() "> Copy</ button >
456
467
< button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
468
+ < div id ="feedback " aria-live ="assertive " role ="alert "> </ div >
457
469
</ div >
458
470
</ p > </ div >
459
471
</ p > </ div >
@@ -1360,7 +1372,7 @@ <h4>Contribute to "Understanding OData in 6 steps"</h4>
1360
1372
</ p > </ div >
1361
1373
< script >
1362
1374
$ ( document ) . ready ( function ( ) {
1363
- $ ( '.modal' ) . on ( 'shown.bs.modal' , function ( ) {
1375
+ $ ( '.modal' ) . on ( 'shown.bs.modal' , function ( ) {
1364
1376
$ ( '.close' ) . focus ( ) ;
1365
1377
trapFocus ( this )
1366
1378
$ ( this ) . find ( ".modal-body" ) . attr ( "tabindex" , - 1 ) ;
@@ -1421,4 +1433,60 @@ <h4>Contribute to "Understanding OData in 6 steps"</h4>
1421
1433
1422
1434
} ) ;
1423
1435
}
1436
+
1437
+ // Select all text in a modal when Ctrl+A is pressed
1438
+ $ ( document ) . keydown ( function ( e ) {
1439
+ // If the 'Ctrl + a' or 'Ctrl + Shift + a' for Narrator key are pressed simultaneously.
1440
+ // If the condition is met, it prevents the default action and selects the contents of any visible modal's body.
1441
+ // Check if the modal is open
1442
+ if ( $ ( '.modal:visible .modal-body' ) . length && e . ctrlKey && ( e . key === 'a' || e . key === 'A' ) ) {
1443
+ e . preventDefault ( ) ;
1444
+ var modalBody = $ ( '.modal:visible .modal-body' ) ;
1445
+ modalBody . focus ( ) ;
1446
+
1447
+ // Create a range to select the content within the modal body
1448
+ var range = document . createRange ( ) ;
1449
+ range . selectNodeContents ( modalBody [ 0 ] ) ;
1450
+
1451
+ // Get the current selection and remove any existing ranges
1452
+ var selection = window . getSelection ( ) ;
1453
+ selection . removeAllRanges ( ) ;
1454
+
1455
+ // Add the new range to the selection
1456
+ selection . addRange ( range ) ;
1457
+ }
1458
+ } ) ;
1459
+
1460
+ // Copy code to clipboard
1461
+ function copyCode ( ) {
1462
+ // Loop through each modal
1463
+ document . querySelectorAll ( '.modal' ) . forEach ( function ( modal ) {
1464
+ // Check if the modal is currently open
1465
+ if ( modal . style . display === 'block' ) {
1466
+ var body = modal . querySelector ( '.modal-body' ) ;
1467
+
1468
+ var range = document . createRange ( ) ;
1469
+ range . selectNodeContents ( body ) ;
1470
+ // Get the current selection and remove any existing ranges
1471
+ var selection = window . getSelection ( ) ;
1472
+ selection . removeAllRanges ( ) ;
1473
+ // Add the new range to the selection
1474
+ selection . addRange ( range ) ;
1475
+
1476
+ document . execCommand ( "copy" ) ;
1477
+
1478
+ // Provide feedback to the user
1479
+
1480
+ $ ( '#feedback' ) . text ( 'Payload copied to the clipboard.' ) . show ( ) ;
1481
+
1482
+ // Hide the feedback after 3 seconds
1483
+ setTimeout ( function ( ) {
1484
+ $ ( '#feedback' ) . fadeOut ( 'slow' ) ;
1485
+ } , 3000 ) ;
1486
+
1487
+ // focus on the modal body to show the user that the content has been copied
1488
+ body . focus ( ) ;
1489
+ }
1490
+ } ) ;
1491
+ }
1424
1492
</ script >
0 commit comments