Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created November 14, 2012 16:47
Show Gist options
  • Select an option

  • Save mikebaldry/4073246 to your computer and use it in GitHub Desktop.

Select an option

Save mikebaldry/4073246 to your computer and use it in GitHub Desktop.
class ClickTracking
constructor: ->
@lastX = -1
@lastY = -1
this._hookEvent()
$(document).on "click", "*", (e) =>
this._trackClick(e)
_trackClick: (e) ->
return if e.pageX == @lastX && e.pageY == @lastY
console.log "clicked at #{e.pageX}, #{e.pageY}"
@lastX = e.pageX
@lastY = e.pageY
_hookEvent: ->
jQuery.Event.prototype._prevPreventDefault = jQuery.Event.prototype.preventDefault
jQuery.Event.prototype.preventDefault = ->
window.GlobalClientStats.ClickTracking._trackClick(this) if this.type == "click"
jQuery.Event.prototype._prevPreventDefault()
jQuery.Event.prototype._prevStopPropagation = jQuery.Event.prototype.stopPropagation
jQuery.Event.prototype.stopPropagation = ->
window.GlobalClientStats.ClickTracking._trackClick(this) if this.type == "click"
jQuery.Event.prototype._prevStopPropagation()
window.GlobalClientStats.ClickTracking = new ClickTracking()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment