From 385f229aa9e7cb7dd63eca9fd2f4b224801328ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Hedr=C3=A9n?= Date: Mon, 28 Oct 2013 12:47:58 +0100 Subject: [PATCH] Added som tests. Updated definitions. --- flight/flight-tests.ts | 49 +++++++++++++++++++++++++++++++++++++++++- flight/flight.d.ts | 5 +++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/flight/flight-tests.ts b/flight/flight-tests.ts index 66f33c7aba..7b48eb93f8 100644 --- a/flight/flight-tests.ts +++ b/flight/flight-tests.ts @@ -1 +1,48 @@ -/// \ No newline at end of file +/// +declare var el: Element; +declare var els: Element[]; +declare var mixinFn: Function; + +function TestComponent() { + var self: FlightBase = this; + + self.defaultAttrs({ + fooSelector: '.bar' + }); + + this.onClick = function (ev: JQueryEventObject, data) { + self.select('fooSelector').addClass('bar'); + }; + + self.around('initialize', function () { }); + self.before('initialize', function () { }); + self.after("initialize", function () { + + var $node: JQuery = self.$node; + var node: Element = self.node; + + self.on(el, 'click', {}); + self.on(els, 'click', function () { }); + self.on(document, 'click', this.onClick); + self.on('click', function () { }); + self.on('click', { + fooSelector: this.onClick + }); + + self.off('click', function () { }); + self.off(document, 'click'); + self.off(el, 'click') + self.off(els, 'click'); + + self.teardown(); + }); +} + +flight.component(TestComponent, mixinFn).attachTo(el); +flight.component(TestComponent, mixinFn).attachTo($(els)); +flight.component(TestComponent, mixinFn).attachTo('.test'); +flight.component(TestComponent, mixinFn).attachTo('.test', { + some: 'data' +}); + +flight.component.teardownAll(); diff --git a/flight/flight.d.ts b/flight/flight.d.ts index eca08f46ae..1fa49113f0 100644 --- a/flight/flight.d.ts +++ b/flight/flight.d.ts @@ -36,7 +36,7 @@ interface FlightBase extends FlightAdvice, FlightComponent { * * @param attr */ - select(attr: string) + select(attr: string): JQuery; /** * This method is attached to the prototype of every Component; it accepts @@ -50,7 +50,7 @@ interface FlightBase extends FlightAdvice, FlightComponent { * API for more information). This is a good place to set up event * listeners that bind to callbacks. */ - initialize(); + initialize(node, options: Object); /** * This allows a component instance to listen to an event and register a @@ -66,6 +66,7 @@ interface FlightBase extends FlightAdvice, FlightComponent { * targets and callbacks. */ on(eventType: string, handler: Function); + on(eventType: string, handler: Object); on(selector: string, eventType: string, handler: Function); on(selector: Document, eventType: string, handler: Function); on(selector: Element, eventType: string, handler: Function);