Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created June 28, 2014 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crobinson42/2040d123b96c8bf75b19 to your computer and use it in GitHub Desktop.
Save crobinson42/2040d123b96c8bf75b19 to your computer and use it in GitHub Desktop.
Custom Event Counter
//
// Custom event - counter
// Emits data: startTime, startCount & count
//
var emitCounter= function(){
var currentCount = 0,
date = new Date(),
startTime = date.getTime();
setInterval(function(){
currentCount++;
$.event.trigger({
type : 'counter',
startTime : startTime,
startCount : 0,
count : currentCount
});
},1000);
};
emitCounter();
// listener 1
$(document).on('counter',function(eventData){
console.log(eventData);
});
// listener 2
$(document).on('counter',function(eventData){
// do something with event data
});
// listener 3
$(document).on('counter',function(eventData){
// do something else with event data
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment