From 634117ed66edd0be5ab4001c58732b17cd36dc34 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 14 Mar 2013 11:34:28 -0600 Subject: [PATCH] Make `$.fn.document` always take event name / doc string args It's simpler and we don't use the other syntax right now. --- spec/stdlib/jquery-extensions-spec.coffee | 14 ++++++-------- src/stdlib/jquery-extensions.coffee | 9 +++------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/spec/stdlib/jquery-extensions-spec.coffee b/spec/stdlib/jquery-extensions-spec.coffee index f0962a200..3b7ce522c 100644 --- a/spec/stdlib/jquery-extensions-spec.coffee +++ b/spec/stdlib/jquery-extensions-spec.coffee @@ -42,7 +42,7 @@ describe 'jQuery extensions', -> element.trigger 'foo' expect(events).toEqual [2,1,3] - describe "$.fn.events() and $.fn.document", -> + describe "$.fn.events() and $.fn.document(...)", -> it "returns a list of all events being listened for on the target node or its ancestors, along with their documentation string", -> view = $$ -> @div id: 'a', => @@ -50,20 +50,18 @@ describe 'jQuery extensions', -> @div id: 'c' @div id: 'd' - view.document - 'a1': "This is event A2" - 'b2': "This is event b2" + view.document 'a1', "This is event A2" + view.document 'b2', "This is event b2" - view.document 'a1': "A1: Waste perfectly-good steak" + view.document 'a1', "A1: Waste perfectly-good steak" view.on 'a1', -> view.on 'a2', -> view.on 'b1', -> # should not appear as a duplicate divB = view.find('#b') - divB.document - 'b1': "B1: Super-sonic bomber" - 'b2': "B2: Looks evil. Kinda is." + divB.document 'b1', "B1: Super-sonic bomber" + divB.document 'b2', "B2: Looks evil. Kinda is." divB.on 'b1', -> divB.on 'b2', -> diff --git a/src/stdlib/jquery-extensions.coffee b/src/stdlib/jquery-extensions.coffee index 80397f975..70d24fc3a 100644 --- a/src/stdlib/jquery-extensions.coffee +++ b/src/stdlib/jquery-extensions.coffee @@ -59,12 +59,9 @@ $.fn.trueHeight = -> $.fn.trueWidth = -> this[0].getBoundingClientRect().width -$.fn.document = (eventDescriptions, optionalDoc) -> - if optionalDoc - eventName = eventDescriptions - eventDescriptions = {} - eventDescriptions[eventName] = optionalDoc - +$.fn.document = (eventName, docString) -> + eventDescriptions = {} + eventDescriptions[eventName] = docString @data('documentation', {}) unless @data('documentation') _.extend(@data('documentation'), eventDescriptions)