HTML5, CSS3 & JS Experiments

By Martin Ivanov

Details Enabler YUI Class

Demo

  • Details Summary
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Details Summary
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Details Summary
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Register the Class

<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script src="html-5-details-element-enabler/html-5-details-element-enabler.js"></script>
<script src="html-5-details-element-enabler/Example.js"></script>

Usage and Code Insight

YUI().use("html5-details", function (Y) {
    var details = new Y.HTML5.Details();
    details.enable();
});
/*
 * Details
 * JavaScript enabler for HTML5 Details Element
 * developer's website: http://wemakesites.net/#!/web-dev
 * developer's twitter: https://twitter.com/#!/wemakesitesnet
 * developer's blog http://acidmartin.wordpress.com/
 **/

YUI.add("html5-details", function(Y) {
    function Details() {
        Details.superclass.constructor.apply(this, arguments);
    }
    
    var OPEN = "open";
    
	Y.extend(Details, Y.Base, {
        enable: function() {
            if (!(OPEN in document.createElement("details"))) {
                this._bind();
            }
        },
        
        _bind: function() {
            Y.one("body").delegate("click", function() {
                var details = this.get('parentNode');
                
                details.getAttribute(OPEN) ? details.removeAttribute(OPEN) : details.setAttribute(OPEN, OPEN);
            }, "summary");
        }
    });
    Y.namespace("HTML5").Details = Details;
}, "0.0.1", {
    requires: ["base", "node", "event"]
});
.details-list, 
.details-list > li 
{
    list-style: none outside none;
    margin: 0;
    padding: 0;
}

.details-list > li 
{
    margin: 4px 0;
}

details, 
summary 
{
    display: block;
}

details, 
summary::before 
{
    border-radius: 5px 5px 5px 5px;
}

details:not([open]) > div 
{
    display: none;
}

details[open] > div 
{
    display: block;
}

details > div 
{
    border-top: 1px dotted #333333;
    font-size: 12px;
    margin: 0 12px 12px;
    padding: 8px 0 0;
}

details 
{
    border: 1px solid #e1e1e1;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    color: #363636;
    font-family: Arial,Sans-serif;
}

summary 
{
    background: -moz-linear-gradient(#fafafa, #e1e1e1);
    background: -webkit-linear-gradient(#fafafa, #e1e1e1);
    background: -o-linear-gradient(#fafafa, #e1e1e1);
    background: -ms-linear-gradient(#fafafa, #e1e1e1);
    background: -linear-gradient(#fafafa, #e1e1e1);
    border-radius: 5px 5px 0 0;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    line-height: 32px;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
}

details[open], 
details[open] summary, 
summary:hover 
{
    background: #e1e1e1;
}

summary::before 
{
    color: #363636;
    content: "+";
    display: inline-block;
    font-size: 14px;
    height: 32px;
    padding: 0;
    text-align: center;
    width: 32px;
}

details[open] summary::before 
{
    content: "-";
    margin-top: -4px;
}

details summary::-webkit-details-marker
{
    display: none;
}