cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="demo A">

    <span class="clickme">Hello, world!</span>

</div>


<div class="demo B">

    <span class="clickme">Hello, world!</span>

</div>


<script type="text/template" id="tplTag">
  
<div class="bigtag">
  <div class="outer">
    <div class="boilerplate">Hi! My name is</div>
    <div class="name">{%= content %}</div>
  </div>
</div>
  
</script>


<div class="demo C">

  <div class="nametag">DarkDOM</div>

</div>


<div class="demo D">

  <div class="nametag">
    <x-name>DarkDOM</x-name>
    <p>Blablabla...</p>
    <p>Blablabla...</p>
    <x-site url="http://douban.com"></x-site>
  </div>

</div>


<div class="demo E">

  <div class="nametag" data-style="night">
    <x-name>DarkDOM</x-name>
    <x-city>Beijing</x-city>
    <x-gender>Male</x-gender>
    <x-site href="http://douban.com"></x-site>
    <x-site href="https://github.com"></x-site>
    <x-site href="https://twitter.com"></x-site>
    <p>Blablabla...</p>
    <p>Blablabla...</p>
  </div>

</div>


<div class="demo F">

  <div class="nametag"
       source-selector=".raw-tag">
    <x-site url="http://douban.com">0</x-site>
  </div>
  
  <div class="nametag">
    <x-name source-selector=".raw-name">DarkDOM</x-name>
    <x-site source="raw-site site1"></x-site>
    <x-site url="http://douban.com">0</x-site>
    <x-site source="raw-site site2"></x-site>
    <p>Blablabla...</p>
  </div>
  
  <div class="raw">
    <div class="raw-tag" data-theme="night">
      <div><div>
        <div class="raw-name">yy</div>
      </div></div>
      <a class="raw-site site1" href="http://ozjs.org">1</a>
      <div>
        <a class="raw-site site2" href="http://alphatown.com">2</a>
      </div>
      <div><p>source content</p></div>
    </div>
  </div>

</div>


<div class="demo G">
  
  <div class="nametag">
    <x-name>DarkDOM</x-name>
    test
  </div>
  
</div>


<div class="demo H">
  
  <div class="nametag">
    <x-name>DarkDOM</x-name>
    <p class="my-change-name">
        <input type="text">
        <input type="button" value="Change name">
    </p>
    <p class="my-new-name">
        <input type="text">
        <input type="button" value="New name">
    </p>
  </div>
  
</div>

            
          
!
            
              
.demo {
  text-align:center;
  padding:40px 0;
  border-bottom:1px dashed #999;
  cursor:pointer;
  
  &:hover {
    background:#eee;
  }
  
}

.raw {
  display:none;
}


input.clickme {
  background: #333;
  color:#fff;
  padding:10px 14px;
  border:none;
  border-radius:10px;
}

.bigtag {

  .outer {
    border: 2px solid brown;
    border-radius: 1em;
    background: red;
    font-size: 20pt;
    width: 12em;
    min-height:7em;
    text-align: center;
    margin:20px auto;
  }

  .boilerplate {
    color: white;
    font-family: sans-serif;
    padding: 0.5em;
  }

  .name {
    color: black;
    background: white;
    font-size: 35pt;
    border-bottom:1px solid red;
  }

  .desc,
  .meta {
    padding:10px 20px;
    border-top:1px solid #999;
    font-size:14px;
    line-height:1.6;
    color:#fff;
    text-align:left;
  }
  
  a {
    color:#eee;
  }

  p,
  ul {
    margin:0;
  }
  
  input[type="text"] {
    border:none;
    width:100px;
  }
  
  &[theme="night"] .outer {
    background:blue;
    border-color:blue;
  }

}

            
          
!
            
              require.config({
  baseUrl: 'http://www.dexmage.com/js/codepen-20140212/'
});

// Demo A

require(['darkdom'], function(darkdom){

  darkdom({
    render: function(data){
      return '<input type="button" value="' 
        + data.content 
      + ' 闇の世界"/>';
    }
  }).createGuard().watch('.demo.A .clickme').mount();

});

// Demo B

require([
  'dollar',
  'mo/template/string',
  'darkdom'
], function($, tpl, darkdom){

  var button = darkdom({
    render: function(data){
      return tpl.format('<input type="button" class="{{myname}}" ' 
          + 'value="{{content}} 闇の世界"/>', {
        myname: data.state.myname,
        content: data.content
      });
    }
  });

  var guard = button.createGuard();
  guard.state('myname', 'class');

  guard.watch($('.clickme')[1]);
  $('.clickme').eq(1).mountDarkDOM();

});

// Demo C

require([
  'mo/template/micro',
  'darkdom'
], function(tpl, darkdom){

  var tag = darkdom({
    render: tpl.convertTpl('tplTag')
  });

  var guard = tag.createGuard();
  guard.watch('.C .nametag');

  guard.mount();

});

// Demo D & E

define('tpl/big_tag', [], function(){

  return '<div class="bigtag" theme="{%= state.theme %}">\
    <div class="outer">\
      <div class="boilerplate">Hi! My name is</div>\
      <div class="name">{%= component.name %}</div>\
      {% if (component.city || component.gender) { %}\
      <div class="meta">\
        <div class="city">City: {%= component.city %}</div>\
        <div class="gender">Gender: {%= component.gender %}</div>\
        <ul>\
        {% componentData.site.forEach(function(site){ %}\
          <li>{%= site.state.link %}</li>\
        {% }); %}\
        </ul>\
      </div>\
      <div class="desc">{%= content %}</div>\
      {% } else { %}\
      <div class="desc">{%= content %}</div>\
      <div class="meta">\
        <ul>\
        {% component.site.forEach(function(site){ %}\
          <li>{%= site %}</li>\
        {% }); %}\
        </ul>\
      </div>\
      {% } %}\
    </div>\
  </div>';

});

define('tag', [
  'mo/template/micro',
  'darkdom',
  'tpl/big_tag'
], function(tpl, darkdom, tpl_big_tag){

  var site = darkdom({
    render: function(data){
      return '<a href="' + data.state.link + '">' 
        + data.state.link + '</a>';
    }
  });
  site.state('link', 'url');

  var tag = darkdom({
    render: tpl.convertTpl(tpl_big_tag)
  });
  tag.state('theme', 'data-style');
  tag.contain('name', darkdom({ unique: true }));
  tag.contain('city', darkdom({ unique: true }));
  tag.contain('gender', darkdom({ unique: true}));
  tag.contain('site', site);

  return tag;

});

require([
  'dollar', 
  'tag'
], function($, tag){

  var guard1 = tag.createGuard();
  guard1.component('name', function(guard){
    guard.watch('x-name');
  });
  guard1.component('site', function(guard){
    guard.watch('x-site');
  });
  guard1.watch($('.D .nametag')).mount();

});

require([
  'dollar', 
  'tag'
], function($, tag){

  var guard2 = tag.createGuard();
  guard2.component('name', 'x-name');
  guard2.component('city', 'x-city');
  guard2.component('gender', 'x-gender');
  guard2.component('site', 'x-site');
  guard2.component('site', function(guard){
    guard.watch('x-site');
    guard.state('link', 'href');
  });
  guard2.watch($('.E .nametag')).mount();

});

// Demo F

require([
  'mo/template/micro',
  'dollar',
  'darkdom',
  'tpl/big_tag'
], function(tpl, $, darkdom, tpl_big_tag){

  var tag = darkdom({
    enableSource: true,
    render: tpl.convertTpl(tpl_big_tag)
  });
  tag.contain('name', darkdom({ 
    enableSource: true,
    unique: true 
  }));
  tag.contain('site', darkdom({
    render: function(data){
      return '<i>' + data.content + ': ' + data.state.link + '</i>';
    },
    enableSource: true
  }));

  var guard = tag.createGuard();
  guard.component('name', function(guard){
    guard.watch('x-name');
  });
  guard.component('site', function(guard){
    guard.watch('x-site');
    guard.state('link', 'url');
    guard.state('source', function(node){
      var str = $(node).attr('source');
      if (!str) {
        return;
      }
      return '.' + str.split(/\s+/).join('.');
    });
    var source = guard.source();
    source.state('link', 'href');
  });
  var source = guard.source();
  source.state('theme', 'data-theme');
  source.component('name', function(guard){
    guard.watch('.raw-name');
  });
  source.component('site', function(guard){
    guard.watch('.raw-site');
    guard.state('link', 'href');
  });
  guard.watch($('.F .nametag')).mount();
 
});

// Demo G

require([
  'mo/template/micro',
  'dollar',
  'darkdom',
  'tpl/big_tag'
], function(tpl, $, darkdom, tpl_big_tag){

  var tag = darkdom({
    enableSource: true,
    render: tpl.convertTpl(tpl_big_tag)
  });
  tag.contain('name', darkdom({ 
    enableSource: true,
    unique: true 
  }));
  tag.contain('city', darkdom({ 
    enableSource: true,
    unique: true 
  }));
  tag.contain('gender', darkdom({ 
    enableSource: true,
    unique: true 
  }));
  tag.contain('site', darkdom());
  
  var guard = tag.createGuard();
  guard.watch($('.G .nametag'));
  guard.component({
    name: 'x-name',
    city: 'x-city',
    gender: 'x-gender'
  });
  $('.G .nametag')[0].feedDarkDOM({
    state: {
      theme: 'night'
    },
    componentData: {
      city: {
        contentData: {
          text: 'Beijing'
        },
      }
    }
  });
  guard.mount();

  $('.G .nametag').feedDarkDOM(function(data){
    data.componentData.gender = {
      contentData: {
        text: 'Male'
      }
    };
    return data;
  });
  $('.G .nametag')[0].updateDarkDOM();
  
});

// Demo H

define('tpl/input_tag', [], function(){

  return '<div class="bigtag">\
    <div class="outer">\
      <div class="boilerplate">Hi! My name is</div>\
      {% component.name.forEach(function(name){ %}\
        {%= name %}\
      {% }); %}\
      <div class="meta">\
        <p>Form in component:</p>\
        <div class="change-name">\
          <input type="text">\
          <input type="button" value="Change name">\
        </div>\
        <div class="new-name">\
          <input type="text">\
          <input type="button" value="New name">\
        </div>\
      </div>\
      <div class="meta">\
        <p>Form in custom content:</p>\
        {%= content %}\
      </div>\
      <div class="desc"></div>\
    </div>\
  </div>';

});

define('inputTag', [
  'mo/template/micro',
  'darkdom',
  'tpl/input_tag'
], function(tpl, darkdom, tpl_input_tag){

  var name = darkdom({
    render: function(data){
      return '<div class="name">' + data.content + '</div>';
    }
  });

  var tag = darkdom({
    render: tpl.convertTpl(tpl_input_tag)
  });
  tag.contain('name', name);
  tag.response('component:name', function(changes){
    changes.root.find('.name')
      .replaceWith(changes.data.component.name.join(''));
  });
  tag.forward({
    'change .change-name input[type="text"]': 'inputName',
    'click .change-name input[type="button"]': 'changeName',
    'change .new-name input[type="text"]': 'inputName',
    'click .new-name input[type="button"]': 'newName'
  });

  return tag;

});

require([
  'dollar',
  'inputTag'
], function($, tag){

  var dark_root = $('.H .nametag');

  var guard = tag.createGuard();
  guard.watch(dark_root);
  guard.component('name', function(guard){
    guard.watch('x-name');
  });
  guard.forward({
    'inputName': function(e, node){
      node.attr('input-buffer', e.target.value);
    },
    'changeName': 'change x-name:last-of-type',
    'newName': 'change'
  });
  guard.mount();

});

require(['dollar'], function($){

  var dark_root = $('.H .nametag');

  dark_root.on('darkdom:rendered', function(e){
    if (e.target === this) {
      listen_custom_content();
    }
  });

  if (dark_root[0].isMountedDarkDOM) {
    listen_custom_content();
  }

  function listen_custom_content(){
    $('.H .my-change-name input[type="button"]').on('click', function(){
      var text = $('.H .my-change-name input[type="text"]');
      var name = text.val();
      dark_root.find('x-name').eq(-1).html(name).updateDarkDOM();
    });
    $('.H .my-new-name input[type="button"]').on('click', function(){
      var text = $('.H .my-new-name input[type="text"]');
      var name = text.val();
      dark_root.append('<x-name>' + name + '</x-name>').updateDarkDOM();
    });
  }

  dark_root.on('change', function(e){
    var me = $(this);
    var input = me.attr('input-buffer');
    if (e.target.nodeName === 'X-NAME') {
      $(e.target).html(input).updateDarkDOM();
    } else {
      me.append('<x-name>' + input + '</x-name>').updateDarkDOM();
    }
  });

});

            
          
!
999px
Loading ..................

Console