GDB Events With Classes Example

Click the buttons above!

HTML

JavaScript

var Button=function(text){
    var Button=this;
    Button.text=text;
    Button.$element=null;
    setTimeout(function(){ //wait 100 milliseconds until gdb is defined.
        Button.$element=gdb.getBoundElementsForModelPart(Button);
    },100);
    Button.active=false;
    Button.activate=function(){
        if(Button.active){
            Button.$element.removeClass('active');
            Button.active=false;
        }
        else{
            Button.$element.addClass('active');
            Button.active=true;
        }
    };
    Button.clickFunction=function(){
        Button.text="I've been changed!";
        Button.activate();
    };
};
var model={buttons:{
    button1: new Button("Click me, please!"),
    button2: new Button("Click me too, please!")
}};
var gdb=new GDB(model); //We instantiate GDB here because GDB.getBoundElementsForModelPart is an instance method.