123

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.

            
              <aside id="archives" class="widget widget_archive">
  <h3 class="widget-title">Archivos</h3>
  <ul>
    <li><a href="#">2015</a>
      <i class="fa fa-angle-down"></i>
      <ul>
        <li><a href="#">febrero 2015</a></li>
        <li><a href="#">enero 2015</a></li>
      </ul>
    </li>
    <li><a href="#">2014</a>
      <i class="fa fa-angle-down"></i>
      <ul class="hide">
        <li><a href="#">diciembre 2014</a></li>
        <li><a href="#">noviembre 2014</a></li>
        <li><a href="#">marzo 2014</a></li>
        <li><a href="#">febrero 2014</a></li>
        <li><a href="#">enero 2014</a></li>
      </ul>
    </li>
    <li><a href="#">2013</a>
      <i class="fa fa-angle-down"></i>
      <ul class="hide">
        <li><a href="#">diciembre 2013</a></li>
        <li><a href="#">septiembre 2013</a></li>
      </ul>
    </li>
  </ul>
</aside>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lato);

body {
  font-family: 'Lato', sans-serif;
}

.fa-angle-down {
  transition: all .3s ease-in-out;
}

.widget {
  width:60%;
  margin:50px auto 0 auto;
  border:4px solid rgba(10,10,10,0.05);
  padding:10px;
  border-radius:10px;
  -webkit-box-shadow: 10px 10px 45px -20px rgba(0,0,0,0.75);
  -moz-box-shadow: 10px 10px 45px -20px rgba(0,0,0,0.75);
  box-shadow: 10px 10px 45px -20px rgba(0,0,0,0.75);
}

.widget-title {
  font-weight:bold;
  text-transform:uppercase;
  color:#636363;
  padding-bottom:10px
}

.widget a {
  color:#9b9b9b;
  text-decoration:none;
  padding:10px 0 10px 10px;
  display:inline-block;
}

.widget i {
  color: #9b9b9b;
  padding:10px 16px;
  float:right;
  line-height:1.5;
}

.widget i:hover {
  cursor: pointer;
  color:#444;   
}

.widget a:hover {
  color:#444
}

.widget ul {
  list-style-type:none;
  margin:0;
  padding:0;
  background-color:#eee;
}

.widget ul li:first-child .fa-angle-down {
  -moz-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  -webkit-transform: rotate(180deg); 
  transform: rotate(180deg);
}

.widget ul {
  line-height:1.5;
}

.widget li {
  border-top:1px solid #ccc;
}

.widget li li {
  line-height:1.5;
  border-top:1px solid #eaeaea;
  background-color:#fff;
}

.widget > ul li:first-child 
li a:first-child {
  display:inline-block;
}

.hide {
  display:none;
}
            
          
!
            
              /* 

Reviewed on http://codereview.stackexchange.com/questions/83940/minimalist-accordion-implementation-using-vanilla-javascript 

http://sonnyt.com/javascript-check-if-element-has-class/

*/

var el = document.getElementById("archives");
var hook = el.getElementsByClassName("fa");
var rotated;

for (var i = 0; i < hook.length; i++) {
	hook[i].addEventListener("click",Toogle);
}

function Toogle() {
    'use strict';
  if (this.nextElementSibling.nodeType === 1 && hasClass(this.nextElementSibling,"hide")) { 
    if (this.nextElementSibling.classList) {
      this.nextElementSibling.classList.remove('hide');
    } else {
      this.nextElementSibling.className = this.nextElementSibling.className.replace(new RegExp('(^|\\b)' + "hide" + '(\\b|$)', 'gi'), ' ');
    }
    rotated = false;
  }
  else {    
    this.nextElementSibling.className += " " + "hide";
    rotated = true;
  }
  
  var deg = rotated ? 0 : 180;
    
  this.style.transform = 'rotate('+deg+'deg)';     
}

function hasClass (el, className){
  return el.className && new RegExp("(^|\\s)" + className + "(\\s|$)").test(el.className);
}
            
          
!
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