Add $.fn.events, which returns a list of all handled events

This commit is contained in:
Nathan Sobo
2012-10-01 12:08:10 -10:00
parent 23e7139ed1
commit 96c9f0bc36
2 changed files with 26 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
$ = require 'jquery'
{$$} = require 'space-pen'
describe 'jQuery extensions', ->
describe '$.fn.preempt(eventName, handler)', ->
@@ -39,3 +40,20 @@ describe 'jQuery extensions', ->
element.off('.bar')
element.trigger 'foo'
expect(events).toEqual [2,1,3]
describe "$.fn.events()", ->
fit "returns a list of all events being listened for on the target node or its ancestors", ->
view = $$ ->
@div id: 'a', =>
@div id: 'b', =>
@div id: 'c'
@div id: 'd'
view.on 'a1', ->
view.on 'a2', ->
view.find('#b').on 'b1', ->
view.find('#b').on 'b2', ->
view.find('#c').on 'c', ->
view.find('#d').on 'd', ->
expect(view.find('#c').events()).toEqual ['c', 'b1', 'b2', 'a1', 'a2']

View File

@@ -1,4 +1,5 @@
$ = require 'jquery'
_ = require 'underscore'
$.fn.scrollBottom = (newValue) ->
if newValue?
@@ -36,3 +37,10 @@ $.fn.trueHeight = ->
$.fn.trueWidth = ->
this[0].getBoundingClientRect().width
$.fn.events = ->
events = _.keys(@data('events') ? {})
if @hasParent()
events.concat(@parent().events())
else
events