UNPKG

collapsible-block

Version:

Lightweight Collapse/Expand component library.

324 lines (263 loc) 17.8 kB
<!DOCTYPE html> <html> <head> <title>Collapsible Block Test</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <script type="text/javascript" src="dist/collapsible-block.min.js"></script> <script type="text/javascript"> var log = function( message ) { var debugContainer = document.querySelector( '.debug-container' ); if ( debugContainer ) { var newMessage = document.createElement( 'p' ); newMessage.innerText = message; debugContainer.appendChild( newMessage ); } } var initCollapsibleBlocks = function() { if ( window.CollapsibleBlock ) { CollapsibleBlock.init(); log( 'Collapsible Blocks initialized.' ); } else { log( 'Collapsible Blocks isn\'t loaded.' ); } } window.addEventListener( "DOMContentLoaded", function () { log( 'DOM Content loaded' ); } ); window.addEventListener( "DOMContentLoaded", function () { initCollapsibleBlocks(); } ); window.addEventListener( "load", function () { log( 'Page loaded' ); } ); </script> <style type="text/css"> * { box-sizing: border-box; } hr { margin-top: 30px; margin-bottom: 30px; } .is-collapsed:not( .is-activated ) [data-collapsible-content] { display: none; } .collapsible-block__handler { display: inline-block; margin-top: 10px; padding: 5px 10px; background-color: #f9f9f9; cursor: pointer; } .disconnected-handler .collapsible-block__handler { background-color: #f7bdbd; } .collapsible-content__inner { padding: 20px; background-color: #f3f3f3; border: solid 2px #ddd; } #collapsible-content-multi-target-1 .collapsible-content__inner { background-color: #a3f3f3; } #collapsible-content-multi-target-2 .collapsible-content__inner { background-color: #f3a3f3; } #collapsible-content-multi-target-3 .collapsible-content__inner { background-color: #f3f3a3; } #collapsible-handler-to-hide .collapsible-content__inner { padding: 0; background-color: #fff; border: none; } .collapsible-content strong { display: block; margin-bottom: 10px; } </style> </head> <body> <hr/> <h2>One collapsible block -- Initially collapsed</h2> <div class="collapsible-blocks__group"> <div class="is-collapsed" data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle State </a> <div class="collapsible-content" data-collapsible-content data-collapsible-initial-state="collapsed"> <strong>Collapsible Content</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum.<br><br> <a href="https://www.google.com/search?q=Pictures+of+cupcakes" target="_blank">Pictures of cupcakes</a><br> More Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <hr/> <h2>One collapsible block -- Initially expanded</h2> <div class="collapsible-blocks__group"> <div data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle State </a> <div class="collapsible-content" data-collapsible-content data-collapsible-initial-state="expanded"> <div class="collapsible-content__inner"> <strong>Collapsible Content</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> </div> <hr/> <h2>Multi collapsible block -- First expanded</h2> <div class="collapsible-blocks__group"> <div data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle State 1 </a> <div class="collapsible-content" data-collapsible-content data-autofocus> <div class="collapsible-content__inner"> <strong>Collapsible Content</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. <div data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle Nested collapsible </a> <div class="collapsible-content" data-collapsible-content> <div class="collapsible-content__inner"> <strong>Nested Collapsible Content with autofocus element</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. <p> <label> First focusable element:<br> <input type="text" placeholder="This is the first focusable element" data-autofocus /> </label> </p> <p> <button type="button">Do nothing</button> </p> Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <p> <label> First focusable element:<br> <input type="text" placeholder="This is the first focusable element" /> </label> </p> <p> <button type="button">Do nothing</button> </p> Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <div data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle State 2 </a> <div class="collapsible-content" data-collapsible-content> <div class="collapsible-content__inner"> <strong>Collapsible Content</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <div data-collapsible> <a href="#" class="collapsible-block__handler" data-collapsible-handler> Toggle State 3 </a> <div class="collapsible-content" data-collapsible-content> <div class="collapsible-content__inner"> <strong>Collapsible Content</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> </div> <hr/> <h2>Targetting a disconnected collapsible block content element</h2> <div>The collapsible block below does not follow the recommended HTML structure but it is still possible to control it's state with a handler element that is not connected to the collapsible content section by the HTML structure. For that it is necessary that the `id` attribute of the content element is set manually (or at least known).</div> <div class="disconnected-handler"> <a href="#" class="collapsible-block__handler" data-collapsible-handler aria-controls="collapsible-content-disconnected"> Toggle State </a> </div> <div class="collapsible-blocks__group"> <div id="collapsible-content-disconnected" class="collapsible-content" data-collapsible data-collapsible-content data-collapsible-initial-state="collapsed"> <div class="collapsible-content__inner"> <strong>#collapsible-content-disconnected</strong><br> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <hr/> <h2>Toggle multiple targets</h2> <div>The toggle button below will toggle the states (expand or collapsed) for each collapsible block set as a target.</div> <a href="#" class="collapsible-block__handler" data-collapsible-handler data-collapsible-targets="collapsible-content-multi-target-1, collapsible-content-multi-target-2, collapsible-content-multi-target-3, non-existent-id"> Expand content and hide toggle button </a> <div class="collapsible-blocks__group"> <div id="collapsible-content-multi-target-1" class="collapsible-content" data-collapsible data-collapsible-content> <div class="collapsible-content__inner"> <strong>#collapsible-content-multi-target-1</strong><br> Sugar plum biscuit fruitcake. Dragée candy canes dragée carrot cake. Cake macaroon lemon drops soufflé carrot cake sesame snaps toffee candy. Cupcake gummi bears jujubes bear claw sweet roll. Sweet roll cheesecake cake cheesecake. Toffee jelly topping biscuit cupcake. Marshmallow lollipop wafer chupa chups. Brownie cookie carrot cake. </div> </div> <div id="collapsible-content-multi-target-2" class="collapsible-content" data-collapsible data-collapsible-content> <div class="collapsible-content__inner"> <strong>#collapsible-content-multi-target-2</strong><br> Tiramisu halvah chocolate bar croissant cotton candy candy canes topping tootsie roll cupcake. Cake dessert jelly. Liquorice liquorice chocolate bar. Candy cotton candy carrot cake. <p> <label> First focusable element:<br> <input type="text" placeholder="This is the first focusable element" /> </label> </p> <p> <label> Second focusable element (autofocus):<br> <input type="text" data-autofocus placeholder="This is the second focusable element" /> </label> </p> <p> <button type="button">Do nothing</button> </p> Apple pie marzipan jujubes dragée. Jelly-o ice cream donut candy chupa chups tiramisu cake. Lemon drops sweet gingerbread sweet danish marzipan. Jelly beans jujubes candy lollipop toffee topping candy. Muffin cake oat cake. </div> </div> <div id="collapsible-content-multi-target-3" class="collapsible-content" data-collapsible data-collapsible-content> <div class="collapsible-content__inner"> <strong>#collapsible-content-multi-target-3</strong><br> Jujubes pastry cotton candy. Biscuit liquorice wafer pastry pudding lemon drops fruitcake pie halvah. Gummies oat cake tiramisu biscuit. Lollipop dessert pie. Pie jelly oat cake chocolate bar. Gummies jelly jujubes topping toffee jelly toffee pudding. Jujubes donut caramels. Muffin topping tiramisu icing powder chocolate cake ice cream cotton candy. </div> </div> </div> <hr/> <h2>Multiple targets (one-way, hides toggle button)</h2> <div>The toggle button below will expand the collapsed block with content and hide the collapsible block which contains the toggle link.</div> <div class="collapsible-blocks__group"> <div id="collapsible-handler-to-hide" class="collapsible-content" data-collapsible data-collapsible-content data-collapsible-initial-state="expanded"> <div class="collapsible-content__inner"> <a href="#" class="collapsible-block__handler" data-collapsible-handler data-collapsible-targets="collapsible-handler-to-hide, collapsible-content-to-show"> Expand content and hide toggle button </a> </div> </div> <div id="collapsible-content-to-show" class="collapsible-content" data-collapsible data-collapsible-content data-collapsible-initial-state="collapsed" data-autofocus> <div class="collapsible-content__inner"> Cupcake ipsum dolor sit amet brownie. Tootsie roll lollipop chocolate cake soufflé sweet roll gingerbread gummi bears dragée. Tootsie roll soufflé lemon drops. Cheesecake dragée jujubes cake jelly cookie caramels marzipan ice cream. Pastry jelly candy pastry halvah. Brownie tiramisu halvah. Pie gummi bears topping marzipan gummi bears jelly-o bonbon jelly-o jujubes. Croissant pudding liquorice lollipop jelly-o sweet chocolate cake caramels marzipan. Chocolate halvah marzipan wafer dessert toffee pastry croissant. Dragée ice cream lemon drops chocolate cake toffee fruitcake caramels sesame snaps carrot cake. <p> <label> First focusable element:<br> <input type="text" placeholder="This is the first focusable element" value="Should auto-select the text" /> </label> </p> <p> <button type="button">Do nothing</button> </p> Powder powder marzipan muffin cake danish pie. Lemon drops sesame snaps chocolate muffin apple pie fruitcake chocolate cake marzipan topping. Jelly beans brownie cake jelly beans tiramisu lemon drops chocolate carrot cake sugar plum. </div> </div> </div> <hr/> <div class="debug-container"> </div> </body> </html>