/
ContainerController.ts
168 lines (128 loc) · 3.48 KB
/
ContainerController.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
/**
* 追加コンテナの表示制御
*
* @class ContainerController
*/
class ContainerController
{
protected _visibility: boolean;
protected _position: ContainerController.ContainerPosition;
protected _container?: HTMLElement;
protected _viewer_container: HTMLElement;
protected _is_compact: boolean;
/**
* @param container ルートコンテナ(Viewerクラスのcontainer_element)
* @param options 表示オプション
*/
constructor( container: HTMLElement | string, options: ContainerController.Option )
{
this._visibility = options.visibility !== undefined ? options.visibility : true;
this._position = options.position || ContainerController.ContainerPosition.TOP_LEFT;
var container_element;
if ( typeof container === "string" ) {
// コンテナを ID 指定したとき
container_element = document.getElementById( container ) as HTMLElement;
}
else {
// コンテナを直接要素で指定のとき
container_element = container;
}
this._viewer_container = container_element;
this._is_compact = false;
var self = this;
window.addEventListener("resize", function() { self._sizeChanged(); }, false);
}
/**
* 表示・非表示の設定
*
* @param visibility
*/
setVisibility( visibility: boolean ): void
{
this._visibility = visibility;
// 表示状態の更新
this._setContainerVisibility();
}
/**
* 表示位置
*
* @param position
*/
setPosition( position: ContainerController.ContainerPosition ): void
{
this._position = position;
// コンテナの再作成
this._deleteContainer();
this.createContainer();
}
/**
* コンテナの表示設定
*/
private _setContainerVisibility(): void
{
if (this._container)
{
( this._visibility ) ? this._container.style.visibility = "visible" : this._container.style.visibility = "collapse"
}
}
/**
* インスタンスの破棄
*/
private _destroy(): void
{
var self = this;
window.removeEventListener( "resize", function () { self._sizeChanged(); }, false );
this._deleteContainer();
}
/**
* 追加コンテナの削除
*/
protected _deleteContainer(): void
{
if ( this._container ) {
var parent_container = this._container.parentElement;
if ( parent_container ) {
parent_container.removeChild( this._container );
}
this._container = undefined;
}
}
/**
* リサイズイベント
*/
protected _sizeChanged(): void
{
}
/**
* 追加コンテナの作成
*/
createContainer(): void
{
}
}
namespace ContainerController {
/**
* オプション
*/
export interface Option {
/** 表示・非表示 */
visibility?: boolean;
/** 表示位置 */
position?: ContainerPosition;
}
/**
* ロゴ・著作権表示位置の列挙型
*/
export enum ContainerPosition {
/** 左上 */
TOP_LEFT = "top-left",
/** 右上 */
TOP_RIGHT = "top-right",
/** 左下 */
BOTTOM_LEFT = "bottom-left",
/** 右下 */
BOTTOM_RIGHT = "bottom-right",
};
export const _compact_size = 500;
} // namespace ContainerController
export default ContainerController;