diff --git a/README.md b/README.md index ef760fe8ae..1158e73389 100755 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ List of Definitions * [FPSMeter](http://darsa.in/fpsmeter/) (by [Aaron Lampros](https://github.com/alampros)) * [FullCalendar](http://arshaw.com/fullcalendar/) (by [Neil Stalker](https://github.com/nestalk)) * [Gamepad](http://www.w3.org/TR/gamepad/) (by [Kon](http://phyzkit.net/)) +* [Giraffe](https://github.com/barc/backbone.giraffe) (by [Matt McCray](https://github.com/darthapo)) * [glDatePicker](http://glad.github.com/glDatePicker/) (by [Dániel Tar](https://github.com/qcz)) * [GoJS](http://gojs.net/) (by [Barbara Duckworth](https://github.com/barbara42)) * [GreenSock Animation Platform (GSAP)](http://www.greensock.com/get-started-js/) (by [Robert S.](https://github.com/codeBelt)) diff --git a/giraffe/giraffe-tests.ts b/giraffe/giraffe-tests.ts new file mode 100644 index 0000000000..70365bb59b --- /dev/null +++ b/giraffe/giraffe-tests.ts @@ -0,0 +1,37 @@ +/// + +class User extends Giraffe.Model { +} + +class MainView extends Giraffe.View { + + constructor(options?) { + this.appEvents = { + 'startup': 'app_onStartup' + } + super(options) + } + + app_onStartup() { + + } + +} + +class MyApp extends Giraffe.App { + constructor() { + this.routes= { + '': 'home' + } + super() + } + + home() { + this.attach( new MainView ) + } + +} + +var app= new MyApp(); + +app.start(); \ No newline at end of file diff --git a/giraffe/giraffe.d.ts b/giraffe/giraffe.d.ts new file mode 100644 index 0000000000..24c41aa243 --- /dev/null +++ b/giraffe/giraffe.d.ts @@ -0,0 +1,186 @@ +// Type definitions for Giraffe +// Project: https://github.com/barc/backbone.giraffe +// Definitions by: Matt McCray +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Giraffe { + + interface GiraffeObject { + app: App; + appEvents?: StringMap; + dataEvents?: StringMap; + defaultOptions?: DefaultOptions; + + initialize?(); + beforeInitialize?(); + afterInitialize?(); + + dispose?(); + beforeDispose?(); + afterDispose?(); + } + + interface AttachmentOptions { + method?: string; + forceRender?: boolean; + suppressRender?: boolean; + } + + interface DefaultOptions { + disposeOnDetach?: boolean; + alwaysRender?: boolean; + saveScrollPosition?: boolean; + documentTitle?: string; + } + + interface AppMap { + [ cid:string ]: App; + } + interface ViewMap { + [ cid:string ]: View; + } + interface StringMap { + [ def:string ]: string; + } + + var app: App; + var apps: AppMap; + var defaultOptions: DefaultOptions; + var version: string; + var views: ViewMap; + + function bindAppEvents( instance:GiraffeObject ): GiraffeObject; + function bindDataEvents( instance:GiraffeObject ): GiraffeObject; + function bindEvent( context:Backbone.Events, target:Backbone.Events, event:any, callback:Function ); + function unbindEvent( context:Backbone.Events, target:Backbone.Events, event:any, callback:Function ); + function bindEventMap( context:Backbone.Events, target:Backbone.Events, eventMap:any ); + function unbindEventMap( context:Backbone.Events, target:Backbone.Events, eventMap:any ); + + function configure( instance:any, options?:any ); + function dispose( instance:GiraffeObject, ...args:any[] ): GiraffeObject; + function disposeThis( ...args:any[] ): GiraffeObject; + + function wrapFn( obj:any, name:string, before:Function, after:Function); + + class Collection extends Backbone.Collection implements GiraffeObject { + app: App; + model: Model; + } + + class Model extends Backbone.Model implements GiraffeObject { + app: App; + } + + class Router extends Backbone.Router implements GiraffeObject { + app: App; + namespace: string; + triggers: StringMap; + + cause( appEvent:string, ...args:any[] ); + isCaused( appEvent:string, ...args:any[] ): boolean; + getRoute( appEvent:string, ...args:any[] ): string; + + reload( url:string ); + } + + class View extends Backbone.View implements GiraffeObject { + app: App; + appEvents: StringMap; + children: View[]; + dataEvents: StringMap; + defaultOptions: DefaultOptions; + documentTitle: string; + parent: View; + template: any; + ui: StringMap; + + attachTo( el:any, options?:AttachmentOptions ): View; + attach( view:View, options?:AttachmentOptions ): View; + isAttached( el:any ): boolean; + + render( options?:any ): View; + beforeRender(); + afterRender(); + templateStrategy(): string; + serialize(): any; + + setParent( parent:View ): View; + + addChild( child:View ): View; + addChildren( children:View[] ): View; + removeChild( child:View, preserve?:boolean ): View; + removeChildren( preserve?:boolean ): View; + + detach( preserve?:boolean ): View; + detachChildren( preserve?:boolean ): View; + + invoke( method:string, ...args:any[] ); + + dispose(): View; + beforeDispose(): View; + afterDispose(): View; + + static detachByElement( el:any, preserve?:boolean ): View; + static getClosestView( el:any ): View; + static getByCid( cid:string ): View; + static to$El( el:any, parent?:any, allowParentMatch?:boolean ): JQuery; + static setDocumentEvents( events:string[], prefix?:string ): string[]; + static removeDocumentEvents( prefix?:string ); + static setDocumentEventPrefix( prefix?:string ); + static setTemplateStrategy( strategy:any, instance?:any ); + } + + class App extends View { + routes: StringMap; + + addInitializer( initializer:( options?:any, callback?:()=>void )=>void ): App; + + start( options?:any ): App; + } + + module Contrib { + + class Controller extends Backbone.Events implements GiraffeObject { + app: App; + } + + class CollectionView extends View { + + collection: Collection; + modelView: View; + modelViewArgs: any[]; + modelViewEl: any; + renderOnChange: boolean; + + findByModel( model:Model ): View; + addOne( model:Model ): View; + removeOne( model:Model ): View; + + static getDefaults( ctx:any ): any; + } + + class FastCollectionView extends View { + collection: Collection; + modelTemplate: any; + modelTemplateStrategy: string; + modelEl: any; + renderOnChange: boolean; + + modelSerialize(): any; + + addAll(): View; + addOne( model:Model ): View; + removeOne( model:Model ): View; + + removeByIndex( index:number ): View; + findElByModel( model:Model ): JQuery; + findElByIndex( index:number ): JQuery; + findModelByEl( el:any ): Model; + + static getDefaults( ctx:any ): any; + } + + } +}