Created
June 28, 2014 16:24
-
-
Save crobinson42/2040d123b96c8bf75b19 to your computer and use it in GitHub Desktop.
Custom Event Counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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