Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="Widget-Base Widget-MiniFAQ" style="width:95%;">

  <h3>Mini FAQ - Wide view</h3>

  <dl>
    <dt>What is this?</dt>
    <dd> It is an attempt to make a mobile-first, responsive and accessible Mini FAQ.
    </dd> 

    <dt>How does it work?</dt>
    <dd><p>Poke around and see for yourself ... but mainly the following: </p>
      <ul>
        <li>Wide FAQs are split left and right</li>
        <li>Narrow ones up and down</li>
        <li>mobile (by window width) do not collapse any questions and show them all. </li>
      </ul>
      <p>   
        Try resizing the output window.</p>
    </dd> 

    <dt>Can I help?</dt>
    <dd><p>Sure, if you want to. I'm have pinged stack overflow at <a href="http://stackoverflow.com/questions/22764718/">http://stackoverflow.com/questions/22764718/</a> to see if anyone there has any ideas, but please fork away ... this is a work-in progress and probably has some issues still ;)</p>
      <p>
        Someone else may already have created something like this ... if you know about it then please say.
      </p>
    </dd> 

    <dt>What does the FAQ look like when there is a very very very very very very very very very very very very very very very very very very very very long question?</dt>
    <dd>
      You're looking at it :D
    </dd> 

    <dt>What issues are there currently?</dt>
    <dd>
      <p>There are a few issues I am working on at the mo ... and others I am aware of but may have to be left due to time constraints:</p>
      <ul>
        <li>js could be done better ... first attempt at namespacing</li>
        <li>mobile safari  $(window).width() 320px ?</li>
        <li>on transition from mobile to desktop modes, selected answers not restored.</li>
        <li>there may be a memory leak ... but not sure on that</li>
        <li>aria roles ... or is using dd and dt enough?</li>
        <li>cross browser testing (IE8+, modern ff, gc, op etc.)</li>
        <li>I have thought of making DD visible due to class on its DT, but the logic may me unclear when mixed between CSS and JS</li>
      </ul>
    </dd> 
  </dl>
</div>

<!-- ######################################### -->

<div class="Widget-Base Widget-MiniFAQ" style="width:300px;">


  <h3>Mini FAQ<br>Narrow view (greeked text)</h3>

  <p>The only difference between this FAQ and the one above is the size of the container.</p>
  
  <dl>
    <dt>Question 1</dt>
    <dd> 1 Etiam euismod diam vel ultricies consectetur. Nullam sodales mattis mauris at tempus. Proin feugiat mi vitae lacus aliquam sollicitudin. Morbi ullamcorper congue lorem, sit amet consequat nibh iaculis et. 
    </dd> 

    <dt>Question 2</dt>
    <dd> 2 Dat nibh iaculis et. Integer sollicitudin neque eget purus eleifend, quis pretium lectus adipiscing. Etiam sit amet mattis lorem. Curabitur molestie malesuada vestibulum. Nullam porttitor in ipsum id fringilla. 
    </dd> 

    <dt>Question 3 - long -  lectus adipiscing. Etiam sit amet mattis lorem. Curabitur molestie malesuada vestibulum. Nullam porttitor in ipsum id fringilla.</dt>
    <dd>
      <p>3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et iaculis nunc. Mauris blandit semper purus ac tempus.</p>
      <p>Curabitur porttitor metus sit amet sem hendrerit sagittis. Vestibulum bibendum lectus erat, vel auctor eros condimentum a. </p> 
    </dd> 
  </dl>

</div>
            
          
!
            
              
.Widget-Base {
  padding: 0.8em;
  padding-top: 1em;
  margin: 0;
  margin-bottom: 2em;

  border-top: #7DC243 9px solid;
  border-bottom: #7DC243 1px solid;
}

.Widget-MiniFAQ * {
  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;    /* Firefox, other Gecko */
  box-sizing: border-box;         /* Opera/IE 8+ */

  font-family: sans-serif;
}

.Widget-MiniFAQ dt.active:before {
  content: "> ";
}

/* Widget css below this line ----------- */

.Widget-MiniFAQ dl a {color: #339;}
.Widget-MiniFAQ dl a:hover {color: #993;}
.Widget-MiniFAQ dt {font-weight: bold; margin: 0.4em 0;}

.Widget-MiniFAQ dt.active,
.Widget-MiniFAQ dt.active a {color: #7DC243;}

.Widget-MiniFAQ dt.active + dd {display: block !important;}

.Widget-MiniFAQ.TwoCol {
  position: relative;
  min-height:400px;
}

.Widget-MiniFAQ.TwoCol dl,
.Widget-MiniFAQ.TwoCol dd {
  width: 48%;
}

.Widget-MiniFAQ.TwoCol dd
{
  position: absolute;
  top: 0;
  right: 0;
  background: #7DC243;
  color:#FFF;
  padding: 0 0.8em 0.4em;
  overflow: auto;
  border: 0px solid #FFF;
  border-width: 15px 0 0
}

.Widget-MiniFAQ.TwoCol dd h3 {
  color: #004687;
  padding-bottom: 1em;
  border-bottom: 1px solid #FFF;
  border-color: rgba(255,255,255,0.5);
}

.Widget-MiniFAQ .AnswerIntro {
  margin: auto;
  text-align: center;
}

            
          
!
            
              
var MiniFAQ = MiniFAQ || {
  settings: {
    mobileRendermodeBreakpoint: 599, // px (make fair size bigger than one col b/p due to bug)
    oneColumnBreakpoint: 400,  //px
    widgetClass: ".Widget-MiniFAQ",
    twoColumnClass: "TwoCol",
    renderMode: "unknown",
    mobile: "m",
    desktop: "d"
  },

  init: function () {

    console.log("init fired");

    // Check if need to trigger mobile view based on viewport width
    this.settings.renderMode = this.getRenderMode();

    if (this.settings.renderMode == this.settings.mobile) {
      console.log("Viewport was too small, mobile view");
      return;
    }

    // Init each instance of MiniFAQ
    var faqs = $(this.settings.widgetClass);
    faqs.each(function (i, faq) { MiniFAQ.initFaq($(faq)); });

  },

  getRenderMode: function () {
    if ($(window).width() <= this.settings.mobileRendermodeBreakpoint) {
      return this.settings.mobile;
    }
    return this.settings.desktop;
  },

  initFaq: function (faq) {
    // hide all answers
    $(this.settings.widgetClass + " dd").hide();
    
    if (faq.width() > this.settings.oneColumnBreakpoint) {
      this.initTwoCol(faq);
    }
    else {
      this.initOneCol(faq);
    }
  },

  initOneCol: function (faq) {
    
    //faq.find(".status").remove();
    //faq.prepend("<p class=status>One Column</p>");
    
    // add links
    faq.find("dt").wrapInner("<a href='#void1'></a>");
    // add handlers
    faq.find('dl').on("click", "dt a", function (e) {
      $(this).parent().next("dd").toggle("fast");
      e.preventDefault();
    });
  },

  initTwoCol: function (faq) {
    
    //faq.find(".status").remove();
    //faq.prepend("<p class=status>Two Columns</p>");
    
    // apply styling
    faq.addClass(this.settings.twoColumnClass);
    
    var qs = faq.find("dt");
    // add question to top of each answer
    qs.each(function (i, e) {
      var q = $(e);
      q.next("dd").prepend("<h3 class='MiniFAQ-QuestionClone'>" + q.text() + "</h3>");
    });
    // add links after setting titles on answers
    qs.wrapInner("<a href='#void2'></a>");
    
    // apply delegated handlers to entire faq
    faq.find('dl').on("click", "dt a", function (e) {
      // hide all answers
      faq.find('dd').hide();
      faq.find('dt').removeClass("active");
      // show current answer
      var dt = $(this).parent();
      dt.addClass("active");
      dt.next("dd").show();
      e.preventDefault();
    });
    // set height of all absolutely positioned answers to match container
    faq.find('dd').height(faq.height()-5); 
    
    // if none are active, make first active
    if (faq.find('.active').length == 0) {
      faq.find("dt").first().addClass("active");
    } 
  },

  resize: function () {
    console.log("resize fired, width " + $(window).width());
    var newRenderMode = this.getRenderMode();
    if (this.settings.renderMode != newRenderMode) {
      console.warn("renderMode was '" + this.settings.renderMode + "' changed to '" + newRenderMode + "'");
      if (newRenderMode == this.settings.mobile) {
        this.reset();
      }
      this.init();
    }
  },

  // Reset funtion for when going from desktop to mobile render mode
  reset: function () {
    console.log("reset fired");
    var w = $(this.settings.widgetClass);
    w.removeClass(this.settings.twoColumnClass);
    // remove clones of question in answer for two column items
    w.find(".MiniFAQ-QuestionClone").remove();
    // reset height and show
    w.find("dd").height('auto').show();
    // remove links
    w.find("dt").each(function (i, e) {
      var dt = $(e);
      var text = dt.text();
      dt.empty();
      dt.append(text);
    });
    // remove handlers
    w.find("dl").off();
  }
};

$(window).ready(function () {
  MiniFAQ.init();
});

$(window).resize(function () {
  clearTimeout($(this).data('timer'));
  $(this).data('timer', setTimeout(function() {MiniFAQ.resize();}, 300));
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console