forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackbone.layoutmanager-tests.ts
59 lines (49 loc) · 1.49 KB
/
backbone.layoutmanager-tests.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
/// <reference path="backbone.layoutmanager.d.ts"/>
/// <reference path="../backbone/backbone.d.ts"/>
/// <reference path="../jquery/jquery.d.ts"/>
// Example code.
class DisplayView extends Backbone.View<Backbone.Model> {
constructor(options?: Backbone.ViewOptions<Backbone.Model>) {
super(options);
this.manage = true;
this.template = "#display";
}
manage: boolean;
template: string;
}
// Create a View to be used with the Layout below.
class View extends Backbone.Layout<Backbone.Model> {
constructor(options?: Backbone.LayoutOptions<Backbone.Model>) {
super(options);
this.template = "#view";
// When you click the View contents, it will wrap them in a bold tag.
this.events = <any>{
"click": "wrapElement",
"mouseenter": "insertElement",
"mouseleave": "removeElement"
}
}
wrapElement(): void {
this.$el.wrap("<b>");
}
insertElement(): void {
this.insertView(new DisplayView()).render();
}
removeElement(): void {
// Removes the inserted DisplayView.
this.removeView("");
}
}
// Create a new Layout.
var layout = new Backbone.Layout<Backbone.Model>({
// Attach the Layout to the main container.
el: ".main",
// Use the previous defined template.
template: "#layout",
// Declaratively bind a nested View to the Layout.
views: {
"p": new View()
}
});
// Render the Layout.
layout.render();