forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
giraffe.d.ts
187 lines (146 loc) · 5.38 KB
/
giraffe.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Type definitions for Giraffe
// Project: https://github.com/barc/backbone.giraffe
// Definitions by: Matt McCray <https://github.com/darthapo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../backbone/backbone.d.ts" />
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<TModel extends Model> {
[ cid:string ]: View<TModel>;
}
interface StringMap {
[ def:string ]: string;
}
var app: App;
var apps: AppMap;
var defaultOptions: DefaultOptions;
var version: string;
var views: ViewMap<Model>;
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<TModel extends Model> extends Backbone.Collection<TModel> implements GiraffeObject {
app: App;
//model: typeof TModel;
model: { new (): TModel; }; // workaround
}
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<TModel extends Model> extends Backbone.View<TModel> implements GiraffeObject {
app: App;
appEvents: StringMap;
children: View<TModel>[];
dataEvents: StringMap;
defaultOptions: DefaultOptions;
documentTitle: string;
parent: View<TModel>;
template: any;
ui: StringMap;
attachTo( el:any, options?:AttachmentOptions ): View<TModel>;
attach( view:View<TModel>, options?:AttachmentOptions ): View<TModel>;
isAttached( el:any ): boolean;
render( options?:any ): View<TModel>;
beforeRender();
afterRender();
templateStrategy(): string;
serialize(): any;
setParent( parent:View<TModel> ): View<TModel>;
addChild( child:View<TModel> ): View<TModel>;
addChildren( children:View<TModel>[] ): View<TModel>;
removeChild( child:View<TModel>, preserve?:boolean ): View<TModel>;
removeChildren( preserve?:boolean ): View<TModel>;
detach( preserve?:boolean ): View<TModel>;
detachChildren( preserve?:boolean ): View<TModel>;
invoke( method:string, ...args:any[] );
dispose(): View<TModel>;
beforeDispose(): View<TModel>;
afterDispose(): View<TModel>;
static detachByElement( el:any, preserve?:boolean ): View<Model>;
static getClosestView<TModel>( el:any ): View<Model>;
static getByCid( cid:string ): View<Model>;
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<Model> {
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<TModel extends Model> extends View<TModel> {
collection: Collection<TModel>;
modelView: View<TModel>;
modelViewArgs: any[];
modelViewEl: any;
renderOnChange: boolean;
findByModel( model:Model ): View<TModel>;
addOne( model:Model ): View<TModel>;
removeOne( model:Model ): View<TModel>;
static getDefaults( ctx:any ): any;
}
class FastCollectionView<TModel extends Model> extends View<TModel> {
collection: Collection<TModel>;
modelTemplate: any;
modelTemplateStrategy: string;
modelEl: any;
renderOnChange: boolean;
modelSerialize(): any;
addAll(): View<TModel>;
addOne( model:Model ): View<TModel>;
removeOne( model:Model ): View<TModel>;
removeByIndex( index:number ): View<TModel>;
findElByModel( model:Model ): JQuery;
findElByIndex( index:number ): JQuery;
findModelByEl( el:any ): Model;
static getDefaults( ctx:any ): any;
}
}
}