|
3 | 3 | * |
4 | 4 | * @author Jim Chen |
5 | 5 | * @license MIT License |
6 | | - * @description Factory to allow creation of different kinds of comments with |
7 | | - * different underlying abstractions. |
| 6 | + * @description Factory to allow creation of different kinds of comments with |
| 7 | + * different underlying abstractions. |
8 | 8 | */ |
9 | 9 | /// <reference path="Core.d.ts" /> |
10 | 10 | /// <reference path="Comment.ts" /> |
11 | 11 | /// <reference path="css-renderer/CssComment.ts" /> |
12 | 12 | class CommentFactory implements ICommentFactory { |
13 | | - private _bindings:{[key:number]:Function;} = {}; |
| 13 | + private _bindings:{[key:number]:Function;} = {}; |
14 | 14 |
|
15 | | - private static _simpleCssScrollingInitializer (manager:ICommentManager, data:Object):IComment { |
16 | | - var cmt = new CssScrollComment(manager, data); |
17 | | - switch (cmt.mode) { |
18 | | - case 1: { |
19 | | - cmt.align = 0; |
20 | | - cmt.axis = 0; |
21 | | - break; |
22 | | - } |
23 | | - case 2: { |
24 | | - cmt.align = 2; |
25 | | - cmt.axis = 2; |
26 | | - break; |
27 | | - } |
28 | | - case 6: { |
29 | | - cmt.align = 1; |
30 | | - cmt.axis = 1; |
31 | | - break; |
32 | | - } |
33 | | - } |
34 | | - cmt.init(); |
35 | | - manager.stage.appendChild(cmt.dom); |
36 | | - return cmt; |
| 15 | + private static _simpleCssScrollingInitializer (manager:ICommentManager, data:Object):IComment { |
| 16 | + var cmt = new CssScrollComment(manager, data); |
| 17 | + switch (cmt.mode) { |
| 18 | + case 1: { |
| 19 | + cmt.align = 0; |
| 20 | + cmt.axis = 0; |
| 21 | + break; |
| 22 | + } |
| 23 | + case 2: { |
| 24 | + cmt.align = 2; |
| 25 | + cmt.axis = 2; |
| 26 | + break; |
| 27 | + } |
| 28 | + case 6: { |
| 29 | + cmt.align = 1; |
| 30 | + cmt.axis = 1; |
| 31 | + break; |
| 32 | + } |
37 | 33 | } |
| 34 | + cmt.init(); |
| 35 | + manager.stage.appendChild(cmt.dom); |
| 36 | + return cmt; |
| 37 | + } |
38 | 38 |
|
39 | | - private static _simpleScrollingInitializer (manager:ICommentManager, data:Object):IComment { |
40 | | - var cmt = new ScrollComment(manager, data); |
41 | | - switch (cmt.mode) { |
42 | | - case 1: { |
43 | | - cmt.align = 0; |
44 | | - cmt.axis = 0; |
45 | | - break; |
46 | | - } |
47 | | - case 2: { |
48 | | - cmt.align = 2; |
49 | | - cmt.axis = 2; |
50 | | - break; |
51 | | - } |
52 | | - case 6: { |
53 | | - cmt.align = 1; |
54 | | - cmt.axis = 1; |
55 | | - break; |
56 | | - } |
57 | | - } |
58 | | - cmt.init(); |
59 | | - manager.stage.appendChild(cmt.dom); |
60 | | - return cmt; |
| 39 | + private static _simpleScrollingInitializer (manager:ICommentManager, data:Object):IComment { |
| 40 | + var cmt = new ScrollComment(manager, data); |
| 41 | + switch (cmt.mode) { |
| 42 | + case 1: { |
| 43 | + cmt.align = 0; |
| 44 | + cmt.axis = 0; |
| 45 | + break; |
| 46 | + } |
| 47 | + case 2: { |
| 48 | + cmt.align = 2; |
| 49 | + cmt.axis = 2; |
| 50 | + break; |
| 51 | + } |
| 52 | + case 6: { |
| 53 | + cmt.align = 1; |
| 54 | + cmt.axis = 1; |
| 55 | + break; |
| 56 | + } |
61 | 57 | } |
| 58 | + cmt.init(); |
| 59 | + manager.stage.appendChild(cmt.dom); |
| 60 | + return cmt; |
| 61 | + } |
62 | 62 |
|
63 | | - private static _simpleAnchoredInitializer (manager:ICommentManager, data:Object):IComment { |
64 | | - var cmt = new CoreComment(manager, data); |
65 | | - switch (cmt.mode) { |
66 | | - case 4: { |
67 | | - cmt.align = 2; |
68 | | - cmt.axis = 2; |
69 | | - break; |
70 | | - } |
71 | | - case 5: { |
72 | | - cmt.align = 0; |
73 | | - cmt.axis = 0; |
74 | | - break; |
75 | | - } |
76 | | - } |
77 | | - cmt.init(); |
78 | | - manager.stage.appendChild(cmt.dom); |
79 | | - return cmt; |
80 | | - }; |
81 | | - |
82 | | - private static _advancedCoreInitializer (manager:ICommentManager, data:Object):IComment { |
83 | | - var cmt = new CoreComment(manager, data); |
84 | | - cmt.init(); |
85 | | - cmt.transform = CommentUtils.Matrix3D.createRotationMatrix(0, data['rY'], data['rZ']).flatArray; |
86 | | - manager.stage.appendChild(cmt.dom); |
87 | | - return cmt; |
| 63 | + private static _simpleAnchoredInitializer (manager:ICommentManager, data:Object):IComment { |
| 64 | + var cmt = new CoreComment(manager, data); |
| 65 | + switch (cmt.mode) { |
| 66 | + case 4: { |
| 67 | + cmt.align = 2; |
| 68 | + cmt.axis = 2; |
| 69 | + break; |
| 70 | + } |
| 71 | + case 5: { |
| 72 | + cmt.align = 0; |
| 73 | + cmt.axis = 0; |
| 74 | + break; |
| 75 | + } |
88 | 76 | } |
| 77 | + cmt.init(); |
| 78 | + manager.stage.appendChild(cmt.dom); |
| 79 | + return cmt; |
| 80 | + }; |
89 | 81 |
|
90 | | - public static defaultFactory ():ICommentFactory { |
91 | | - var factory = new CommentFactory(); |
92 | | - factory.bind(1, CommentFactory._simpleScrollingInitializer); |
93 | | - factory.bind(2, CommentFactory._simpleScrollingInitializer); |
94 | | - factory.bind(6, CommentFactory._simpleScrollingInitializer); |
95 | | - factory.bind(4, CommentFactory._simpleAnchoredInitializer); |
96 | | - factory.bind(5, CommentFactory._simpleAnchoredInitializer); |
97 | | - factory.bind(7, CommentFactory._advancedCoreInitializer); |
98 | | - factory.bind(17, CommentFactory._advancedCoreInitializer); |
99 | | - return factory; |
100 | | - } |
| 82 | + private static _advancedCoreInitializer (manager:ICommentManager, data:Object):IComment { |
| 83 | + var cmt = new CoreComment(manager, data); |
| 84 | + cmt.init(); |
| 85 | + cmt.transform = CommentUtils.Matrix3D.createRotationMatrix(0, data['rY'], data['rZ']).flatArray; |
| 86 | + manager.stage.appendChild(cmt.dom); |
| 87 | + return cmt; |
| 88 | + } |
101 | 89 |
|
102 | | - public static defaultCssRenderFactory ():ICommentFactory { |
103 | | - var factory = new CommentFactory(); |
104 | | - factory.bind(1, CommentFactory._simpleCssScrollingInitializer); |
105 | | - factory.bind(2, CommentFactory._simpleCssScrollingInitializer); |
106 | | - factory.bind(6, CommentFactory._simpleCssScrollingInitializer); |
107 | | - factory.bind(4, CommentFactory._simpleAnchoredInitializer); |
108 | | - factory.bind(5, CommentFactory._simpleAnchoredInitializer); |
109 | | - factory.bind(7, CommentFactory._advancedCoreInitializer); |
110 | | - factory.bind(17, CommentFactory._advancedCoreInitializer); |
111 | | - return factory; |
112 | | - } |
| 90 | + public static defaultFactory ():ICommentFactory { |
| 91 | + var factory = new CommentFactory(); |
| 92 | + factory.bind(1, CommentFactory._simpleScrollingInitializer); |
| 93 | + factory.bind(2, CommentFactory._simpleScrollingInitializer); |
| 94 | + factory.bind(6, CommentFactory._simpleScrollingInitializer); |
| 95 | + factory.bind(4, CommentFactory._simpleAnchoredInitializer); |
| 96 | + factory.bind(5, CommentFactory._simpleAnchoredInitializer); |
| 97 | + factory.bind(7, CommentFactory._advancedCoreInitializer); |
| 98 | + factory.bind(17, CommentFactory._advancedCoreInitializer); |
| 99 | + return factory; |
| 100 | + } |
113 | 101 |
|
114 | | - public bind (mode:number, factory:Function):void { |
115 | | - this._bindings[mode] = factory; |
116 | | - } |
| 102 | + public static defaultCssRenderFactory ():ICommentFactory { |
| 103 | + var factory = new CommentFactory(); |
| 104 | + factory.bind(1, CommentFactory._simpleCssScrollingInitializer); |
| 105 | + factory.bind(2, CommentFactory._simpleCssScrollingInitializer); |
| 106 | + factory.bind(6, CommentFactory._simpleCssScrollingInitializer); |
| 107 | + factory.bind(4, CommentFactory._simpleAnchoredInitializer); |
| 108 | + factory.bind(5, CommentFactory._simpleAnchoredInitializer); |
| 109 | + factory.bind(7, CommentFactory._advancedCoreInitializer); |
| 110 | + factory.bind(17, CommentFactory._advancedCoreInitializer); |
| 111 | + return factory; |
| 112 | + } |
| 113 | + |
| 114 | + public bind (mode:number, factory:Function):void { |
| 115 | + this._bindings[mode] = factory; |
| 116 | + } |
117 | 117 |
|
118 | | - public create (manager:ICommentManager, comment:Object):IComment { |
119 | | - if (comment === null || !comment.hasOwnProperty('mode')) { |
120 | | - throw new Error('Comment format incorrect'); |
121 | | - } |
122 | | - if (!this._bindings.hasOwnProperty(comment['mode'])) { |
123 | | - throw new Error('No binding for comment type ' + comment['mode']); |
124 | | - } |
125 | | - return this._bindings[comment['mode']](manager, comment); |
| 118 | + public create (manager:ICommentManager, comment:Object):IComment { |
| 119 | + if (comment === null || !comment.hasOwnProperty('mode')) { |
| 120 | + throw new Error('Comment format incorrect'); |
| 121 | + } |
| 122 | + if (!this._bindings.hasOwnProperty(comment['mode'])) { |
| 123 | + throw new Error('No binding for comment type ' + comment['mode']); |
126 | 124 | } |
| 125 | + return this._bindings[comment['mode']](manager, comment); |
| 126 | + } |
127 | 127 | } |
0 commit comments