@@ -329,6 +329,7 @@ const bricss = {
329329 const exampleData = bricss . messages . examples . list [ examplesListIndex ] ;
330330 if ( typeof exampleData == 'object' ) {
331331 // Example warning
332+ bricss . _currentExampleIndex = examplesListIndex ;
332333 const markup = bricss . templates . docWarningAdvancedContent ( {
333334 tag : bricss . messages . example ,
334335 title : exampleData . title ,
@@ -343,7 +344,42 @@ const bricss = {
343344 }
344345 } ,
345346 _insertExampleDoc : function ( ) {
346- if ( typeof bricss . _markupExampleWarningItem == 'string' ) bricss . elDocStandard . insertAdjacentHTML ( 'afterbegin' , bricss . _markupExampleWarningItem ) ;
347+ // Insert warning
348+ if ( typeof bricss . _markupExampleWarningItem == 'string' ) {
349+ bricss . elDocStandard . insertAdjacentHTML ( 'afterbegin' , bricss . _markupExampleWarningItem ) ;
350+ }
351+ // Optional sandbox
352+ if ( typeof bricss . messages . examples . list [ bricss . _currentExampleIndex ] . sandbox == 'string' ) {
353+ const iframeContent = `
354+ <!DOCTYPE html>
355+ <html lang="en">
356+ <head>
357+ <meta charset="UTF-8">
358+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
359+ <title>Sandbox</title>
360+ <link rel="stylesheet" href="${ window . dsgCssFile . url } ">
361+ </head>
362+ <body>
363+ ${ bricss . messages . examples . list [ bricss . _currentExampleIndex ] . sandbox }
364+ </body>
365+ </html>
366+ ` ;
367+ const elIframe = document . createElement ( 'iframe' ) ,
368+ elIframeCtn = document . createElement ( 'li' ) ;
369+ elIframe . setAttribute ( 'srcdoc' , iframeContent ) ;
370+ elIframe . setAttribute ( 'class' , 'b-0 w-100' ) ;
371+ elIframe . setAttribute ( 'height' , '500' ) ;
372+ elIframeCtn . setAttribute ( 'class' , 'w-100' ) ;
373+ elIframeCtn . appendChild ( elIframe ) ;
374+ bricss . elDocStandard . appendChild ( elIframeCtn ) ;
375+ }
376+ // Insert example heading
377+ const elHeadingExamples = document . createElement ( 'li' ) ;
378+ elHeadingExamples . setAttribute ( 'class' , 'w-100' ) ;
379+ elHeadingExamples . innerHTML = bricss . messages . listOfAllAvailableJsonExamples ;
380+ bricss . elDocStandard . appendChild ( elHeadingExamples ) ;
381+
382+ // Insert all examples
347383 let examplesChoicesMarkup = '' ;
348384 bricss . messages . examples . list . forEach ( function ( example , index ) {
349385 examplesChoicesMarkup += bricss . templates . docExampleItem ( {
@@ -352,10 +388,8 @@ const bricss = {
352388 examplesListIndex : index
353389 } )
354390 } ) ;
355- bricss . elDocStandard . innerHTML += `
356- <li class="w-100">${ bricss . messages . listOfAllAvailableJsonExamples } </li>
357- ${ examplesChoicesMarkup }
358- ` ;
391+ bricss . elDocStandard . innerHTML += examplesChoicesMarkup ;
392+
359393 } ,
360394 templates : {
361395 docWarningAdvancedContent : function ( { tag, title, description, footer} ) {
0 commit comments