nakome
9/23/2013 - 9:31 PM

A Pen by Moncho Varela.

A Pen by Moncho Varela.

/*  = Demo only
---------------------------*/
@import url(http://fonts.googleapis.com/css?family=Lato|Lobster);
body{background: #26ABB1;width: 80%;margin: 1% auto;}
.main{background: #F5F5F5;padding: 0.5em;color: #616161;border-radius:0.2em;}
.head{color: #FFFFFF;font-family:'Lobster', cursive;text-shadow: 0 3px 3px #26ABB1,0 6px 5px #2C3E50;position:relative;}
.subhead{color: #FFFFFF;font-family:'Lobster', cursive;text-shadow: 0 3px 2px #26ABB1,0 5px 2px #000;position:relative;}
.main pre{font-family:monospace, serif;font-size:1em}pre{white-space:pre-wrap;background: #26ABB1;padding: 0.5em;color: #FFF;border-radius: 0.2em;}
.main a img {width:350px;height:150px;padding: 0.5em;background: #26ABB1;box-shadow: 0 0.5em 0.5em -0.5em #000;transition:background 0.8s ease;border-radius: 0.2em;}
.main a:hover img{background: #fff;transition:background 0.8s ease;}
.main img {display:block;width:350px;height:150px;}
.footer{position: fixed;bottom: 0;left: 0;display: block;width: 100%;background: #585858;text-align: center;color: #F0F0F0;padding: 0.2em;text-shadow: 0 2px 3px black;font-family:verdana;}

if (typeof lorem == 'undefined')
  lorem = {};
lorem.display = {
  // init function
  init: function() {
    this.getLorem();
  },
  // short query selector 
  js: function(el){
    return document.querySelectorAll('[data-js="'+el+'"]');
  },
  // short query selector 
  lorem: function(el){
    return document.querySelectorAll('[data-lorem="'+el+'"]');
  },
  // html templates change this if you like.
  tag:{
    'h1': '<h1>This is h1 tag</h1>',
    'h2': '<h2>This is h2 tag</h2>',
    'h3': '<h3>This is h3 tag</h3>',
    'h4': '<h4>This is h4 tag</h4>',
    'h5': '<h5>This is h5 tag</h5>',
    'h6': '<h6>This is h6 tag</h6>',
    'img_link':'<a href="#" title="sample link"><img src="http://placehold.it/350x150" alt="Sample photo"/></a>',
    'img': '<img src="http://placehold.it/350x150" alt="Sample photo"/>',
    'long_lorem':'<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>',
    'medium_lorem':'<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>',
    'small_lorem':'<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>',
    'short_ul':'<ul><li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li><li>Aliquam tincidunt mauris eu risus.</li><li>Vestibulum auctor dapibus neque.</li></ul>',
    'long_ul':'<ul><li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.</li>li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li><li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li><li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li></ul>',
    'nav_ul':'<nav><ul><li><a href="#nowhere" title="Morbi in sem quis dui placerat ornare">Morbi</a></li><li><a href="#nowhere" title="Praesent dapibus, neque id cursus faucibus">Praesent</a></li><li><a href="#nowhere" title="Pellentesque fermentum dolor">Pellentesque</a></li></ul></nav>',
    'table':'<table><thead><tr><th>Example table</th><th>Example table</th><th>Example table</th><th>Example table</th></tr></thead><tbody><tr><td>Example table</td><td>Example table</td><td>Example table</td><td>Example table</td></tr><tr><td>Example table</td><td>Example table</td><td>Example table</td><td>Example table</td></tr><tr><td>Example table</td><td>Example table</td><td>Example table</td><td>Example table</td></tr></tbody></table>'
  },
  // get samples
  getLorem:function(){
    
    var count = this.js('lorem'),elem = '';
    // count all elements 
    for(var i = 0; i < count.length; i++){
      elem = count[i].getAttribute('data-lorem');
      // switch elements 
      switch(elem){
         // if elem = h1
        case 'h1':
          count[i].innerHTML = this.tag.h1;
          break;
        case 'h2':
          count[i].innerHTML = this.tag.h2;
          break;
        case 'h3':
          count[i].innerHTML = this.tag.h3;
          break;
        case 'h4':
          count[i].innerHTML = this.tag.h3;
          break;
        case 'h5':
          count[i].innerHTML = this.tag.h5;
          break;
        case 'h6':
          count[i].innerHTML = this.tag.h6;
          break;
        case 'img_link':
          count[i].innerHTML = this.tag.img_link;
          break;					
        case 'img':
          count[i].innerHTML = this.tag.img;
          break;
        case 'long_lorem':
          count[i].innerHTML = this.tag.long_lorem;
          break;
        case 'medium_lorem':
          count[i].innerHTML = this.tag.medium_lorem;
          break;
        case 'small_lorem':
          count[i].innerHTML = this.tag.small_lorem;
          break;
        case 'short_ul':
          count[i].innerHTML = this.tag.short_ul;
          break;
        case 'long_ul':
          count[i].innerHTML = this.tag.long_ul;
          break;
        case 'nav_ul':
          count[i].innerHTML = this.tag.nav_ul;
          break;
        case 'table':
          count[i].innerHTML = this.tag.table;
          break;
        default:
          count[i].innerHTML = 'What is this ?';
          break;
      };
    }
    return elem;
  }
};
// init script
lorem.display.init();

<h1 class="head">Data-lorem.</h1>
<h2 class="subhead">Simple experiment with data attributes to generate sample data.</h2>



<div class="main">
  <span data-js="lorem" data-lorem="h1" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="h1" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="h2" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="h2" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="h3" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="h3" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="h4"></span>
  <pre>&lt;span data-js="lorem" data-lorem="h4" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="h5" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="h5" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="h6" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="h6" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="long_lorem" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="long_lorem" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="medium_lorem" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="medium_lorem" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="small_lorem" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="small_lorem" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="img" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="img" &gt;&lt;/span&gt;</pre>
  
  <br>
  <span data-js="lorem" data-lorem="img_link" ></span>
  <pre>&lt;span data-js="lorem" data-lorem="img_link" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="short_ul" ></span>	
  <pre>&lt;span data-js="lorem" data-lorem="short_ul" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="long_ul" ></span>	
  <pre>&lt;span data-js="lorem" data-lorem="long_ul" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="nav_ul" ></span>			
  <pre>&lt;span data-js="lorem" data-lorem="nav_ul" &gt;&lt;/span&gt;</pre>
  
  <span data-js="lorem" data-lorem="table" ></span>	
  <pre>&lt;span data-js="lorem" data-lorem="table" &gt;&lt;/span&gt;</pre>

</div>

<div class="footer">Nakome &copy; 2013</div>

Data-lorem

Simple experiment with data attributes to generate sample data.

A Pen by Moncho Varela on CodePen.

License.