Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created March 27, 2013 09:02
Show Gist options
  • Save stansidel/5252845 to your computer and use it in GitHub Desktop.
Save stansidel/5252845 to your computer and use it in GitHub Desktop.
A JS class for firing counters events (added to cart, sold) on any site (esp, Bitrix).
<html>
<head>
<script type="text/javascript">
var asproEvents = new function(){
var myWatchers = new Array();
this.addEventListener = function(watcher) {
console.log(typeof watcher);
}
this.raiseEvent = function(eventId) {
for (var thisEventIndex in myWatchers) {
myWatchers[thisEventIndex](eventId);
}
}
};
</script>
</head>
<body>
<button onclick="asproEvents.raiseEvent('pow');">My button</button>
<script type="text/javascript">
asproEvents.addEventListener(function(text){
console.log('event: ' + text);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment