requiredEvent = function(name, callback, context){
var that = this
, stateUpdate = function(nameIn, stateEventsIn){
var name = nameIn
, stateEvents = stateEventsIn;
return function(){
var truthy = true
, key;
if(typeof stateEvents[name] !== 'undefined'){
stateEvents[name] = true;
for(key in stateEvents){
truthy = truthy && stateEvents[key];
}
if(truthy && !that.triggeredStateReady){
//feels like a little bit of a hack.
// lets the data finish propogating before triggering the call
setTimeout(that.stateReady.apply(that), 100);
that.triggeredStateReady = true;
}
}
};
};
that.triggeredStateReady = false;
that.stateEvents[name] = false;
that.listen(name, callback, context);
that.listen(name, stateUpdate(name, that.stateEvents), that);
};
var loadedHandler = function(){
alert('loaded');
//be a good neighbor... remove unneeded listeners
document.removeListener('DOMContentLoaded', loadedHandler);
};
document.addEventListener('DOMContentLoaded', loadedHandler);
// the more familiar jQuery
$(document).ready(loadedHandler);
//A button
document.querySelect('.button').addEventListener('click', function(){
//do stuff on click
});
$('.button').on('click', function(){
//do stuff on click
});