I FINALLY figured this out, and it was as simple as missing the fact that handlers using bind
to listen are all lower case.
So here is a sample of the code I use in an internal component base class to allow components to bind
and unbind
against the top level jQuery UI Widget, allowing me to use an event oriented architecture that uses the same events inside and outside the widget:
class Base
constructor: (@widget) ->
_fullyQualifiedEventName: (type) ->
fullyQualifiedName = "#{@widget.widgetEventPrefix}#{type}".toLowerCase()
fullyQualifiedName
bind: (type, fn) ->
### bind a callback through the widget's element ###
fullyQualifiedName = @_fullyQualifiedEventName(type)
@widget.element.bind(fullyQualifiedName, fn)
console.log "bind(#{fullyQualifiedName}, #{fn.name})"
unbind: (type, fn) ->
### unbind a callback from the widget's element ###
fullyQualifiedName = @_fullyQualifiedEventName(type)
@widget.element.unbind(fullyQualifiedName, fn)
console.log "unbind(#{fullyQualifiedName}, #{fn.name})"
Whether a handler on the inside is bound to the foo
event with @bind('foo', fn)
, or externally with $('#bar').myWidget().bind('mywidgetfoo', fn)
, or they passed in a handler via options in instantiation {foo: () -> console.log 'options foo listener fired'}
, all listeners will now be triggered with @widget._trigger('foo')