aLight - sample of inheritance

by lega911

HTML

<script src="http://angularlight.org/bin/alight_0.49b.min.js"></script>
<div al-app>
    al-value: <input type="text" al-value="text" /> <br/>
    al-value-delay: <input type="text" al-value-delay="text" /> {{text}}
</div>

JavaScript

alight.directives.al.valueDelay = function() {
    var dir = alight.directives.al.value.apply(null, arguments);  // make the directive
    var oldUpdate = dir.updateModel;  // an old method for update the model
    var timer = null;
    
    dir.updateModel = function() {  // change th method
        if(timer) clearTimeout(timer);
        timer = setTimeout(function() {
            timer = null;
            oldUpdate();  // call the default method for update the model
        }, 500);
    }
    return dir;
}