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.

            
              <h1>Basic BehaviourController Demo</h1>

<h2>Clock</h2>
<div class="component">
    <div data-behaviour="Clock">Clock is inactive</div>
</div>

<h2>ClearField</h2>
<div class="component">
    <input type="text" data-behaviour="ClearField">
</div>
            
          
!
            
              html {
  background:#fff;
  line-height:1.5;
  padding:2em;
  color:#999;
  overflow:scroll;
}

html,input,textarea,button {
  font-family:Helvetica,Verdana,sans-serif;
  font-size:1em;
}

h1 {
  font-size:1.5em;
  color:#333;
}

h2 {
  margin-top:1.5em;
  font-size:1.25em;
  color:#333;
}

h2+p {
  margin-top:-.75em;
}

p {
  max-width:30em;
}

.component {
  padding:1em;
  border:1px dotted #ccc;
}

            
          
!
            
              /*
 * Clock Class
 */
var Clock = function(element) {

    // set element reference
    this._element = element;

    // start ticking
    this.tick();
};

// Update time
Clock.prototype.tick = function() {
    this._element.textContent = new Date().toString();
    var self = this;
    this._timer = setTimeout(function(){
        self.tick();
    },1000);
};


/*
 * ClearField Class
 */
var ClearField = function(element) {

    // set element reference
    this._element = element;

    // Add clear button
    var clearButton = document.createElement('button');
    clearButton.textContent = 'clear';
    clearButton.addEventListener('click',this);
    this._element.parentNode.insertBefore(clearButton,this._element);
};

// Handle events
ClearField.prototype.handleEvent = function(e) {
    // if event type is click clear the field
    if (e.type === 'click') {
        this._element.value = '';
    }
};


/*
 * BehaviourController Static Class
 */
var BehaviourController = {

    applyDefault:function() {

        document.addEventListener('DOMContentLoaded',function(){
            BehaviourController.applyBehaviour(document);
        });

    },

    // Applies behaviour to given context
    applyBehaviour:function(context) {

        var behaviourConstructor,nodes,i,l;

        nodes = context.querySelectorAll('[data-behaviour]');
        l = nodes.length;

        for (i=0;i<l;i++) {
            behaviourConstructor = nodes[i].getAttribute('data-behaviour');
            new window[behaviourConstructor](nodes[i]);
        }
    }

};



// Run
BehaviourController.applyDefault();
            
          
!
999px
Loading ..................

Console