10
10
11
11
'use strict' ;
12
12
13
- /*
14
- TODO
15
-
16
- */
17
-
18
13
var Interface = ( function ( ) {
19
14
self = { } ;
20
15
16
+ /* Events */
17
+ var events = ( function ( ) {
18
+ var list = { } ;
19
+
20
+ return {
21
+ fire : function ( ) {
22
+
23
+ }
24
+ } ;
25
+ } ) ( ) ;
26
+
21
27
/* Utilities */
22
28
var utils = {
23
-
29
+ dom : {
30
+ css : function ( el , prop , value ) {
31
+ el . style [ prop ] = value ;
32
+ } ,
33
+ show : function ( el ) {
34
+ this . css ( el , 'display' , 'block' ) ;
35
+ } ,
36
+ hide : function ( el ) {
37
+ this . css ( el , 'display' , 'none' ) ;
38
+ } ,
39
+ id : function ( id ) {
40
+ return document . getElementById ( id ) ;
41
+ } ,
42
+ klass : function ( klass ) {
43
+ return document . getElementsByClassName ( klass ) ;
44
+ } ,
45
+ stopEvent : function ( e ) {
46
+ e . stopPropagation ( ) ;
47
+ e . preventDefault ( ) ;
48
+
49
+ return this ;
50
+ } ,
51
+ } ,
52
+ extend : function ( obj , options ) {
53
+ var target = { } ;
54
+
55
+ for ( name in obj ) {
56
+ if ( obj . hasOwnProperty ( name ) ) {
57
+ target [ name ] = options [ name ] ? options [ name ] : obj [ name ] ;
58
+ } ;
59
+ } ;
60
+
61
+ return target ;
62
+ } ,
63
+ mixin : function ( target , mixin ) {
64
+ for ( var prop in mixin ) {
65
+ if ( mixin . hasOwnProperty ( prop ) ) {
66
+ target [ prop ] = mixin [ prop ] ;
67
+ }
68
+ }
69
+ } ,
70
+ foreach : function ( arr , func ) {
71
+ for ( var i = 0 , count = arr . length ; i < count ; i ++ ) {
72
+ func ( arr [ i ] , i ) ;
73
+ } ;
74
+ } ,
75
+ foreachReverse : function ( arr , func ) {
76
+ for ( var i = arr . length - 1 ; i >= 0 ; i -- ) {
77
+ func ( arr [ i ] , i ) ;
78
+ } ;
79
+ } ,
80
+ debug : ( function ( ) {
81
+ var output = document . getElementById ( 'debug' ) ;
82
+
83
+ return function ( ) {
84
+ output . innerHTML = [ ] . join . call ( arguments , ' ' ) ;
85
+ } ;
86
+ } ) ( ) ,
24
87
} ;
25
88
26
89
var Menu = function ( items , settings ) {
@@ -85,12 +148,11 @@ var Interface = (function() {
85
148
current = 0 ;
86
149
87
150
return {
88
- push : function ( win ) {
151
+ push : function ( layer ) {
89
152
current ++ ;
90
- arr . push ( new Layer ( win ) ) ;
153
+ arr . push ( layer ) ;
91
154
} ,
92
155
pop : function ( ) {
93
- arr [ current -- ] . destroy ( ) ;
94
156
arr . pop ( ) ;
95
157
} ,
96
158
clear : function ( ) {
@@ -101,87 +163,95 @@ var Interface = (function() {
101
163
} ;
102
164
} ) ( ) ;
103
165
104
- function Layer ( win , with_overlay , z_index ) {
105
- var overlay = null ,
106
- iwindow = win ;
107
-
108
- if ( ! with_overlay ) {
109
- overlay = document . createElement ( 'div' ) ;
110
- document . documentElement . appendChild ( overlay ) ;
111
- overlay . className = 'overlay' ;
112
- overlay . style . display = 'block' ;
113
- overlay . style . zIndex = z_index ;
114
- }
166
+ function create_overlay ( ) {
167
+ var overlay = document . createElement ( 'div' ) ;
168
+ overlay . className = 'overlay' ;
169
+ utils . dom . hide ( overlay ) ;
170
+ document . body . appendChild ( overlay ) ;
115
171
116
- iwindow . show ( ) ;
117
-
118
- this . destroy = function ( ) {
119
- iwindow . hide ( ) ;
120
- } ;
172
+ return overlay ;
121
173
}
122
174
175
+ /**
176
+ *
177
+ *
178
+ *
179
+ */
123
180
function Window ( config ) {
124
- var el = document . querySelector ( '.window' ) ,
125
- close_button = el . querySelector ( '.window__close-button' ) ,
126
- content_wrapper = el . querySelector ( '.window__content' ) ,
127
- header = el . querySelector ( '.window__header' ) ,
128
- content = document . querySelector ( config . content ) ;
129
-
130
- /*
131
- config = {
181
+ var defaults = {
132
182
movable : false ,
133
183
closable : true ,
134
184
overlay : true ,
135
- level
136
- }
137
- */
185
+ layout : 'default' ,
186
+ content_el : null ,
187
+ js_module : null
188
+ } ;
138
189
139
- close_button . addEventListener ( 'click' , hide , false ) ;
190
+ var params = utils . extend ( defaults , config ) ;
191
+ console . log ( params ) ;
140
192
141
- // init
142
- content_wrapper . innerHTML = '' ;
143
- content_wrapper . appendChild ( content ) ;
193
+ var el = document . createElement ( 'div' ) ,
194
+ close_button = document . createElement ( 'div' ) ,
195
+ content_wrapper = document . createElement ( 'div' ) ,
196
+ overlay = params . overlay ? create_overlay ( ) : null ;
144
197
145
- if ( config . movable ) {
146
- el . classList . add ( 'window_movable' ) ;
147
-
148
- // move logic
198
+ this . el = params . content_el ;
199
+
200
+ if ( params . content_el . dataset [ 'header' ] ) {
201
+ var header = document . createElement ( 'h5' ) ;
202
+ header . className = 'window__header' ;
203
+ header . innerHTML = params . content_el . dataset [ 'header' ] ;
204
+ el . appendChild ( header ) ;
149
205
}
150
206
151
- if ( typeof config . js_module === 'function' ) {
152
- config . js_module ( content ) ;
207
+ el . className = 'window' ;
208
+ close_button . className = 'window__close-button' ;
209
+ content_wrapper . className = 'window__content' ;
210
+
211
+ if ( params . movable ) {
212
+ el . classList . add ( 'window_movable' ) ;
153
213
}
154
214
155
- function hide ( ) {
156
- el . style . display = 'none' ;
157
- } ;
215
+ el . appendChild ( close_button ) ;
216
+ el . appendChild ( content_wrapper ) ;
217
+ content_wrapper . appendChild ( params . content_el ) ;
218
+
219
+ document . body . appendChild ( el ) ;
158
220
221
+ if ( params . closable ) {
222
+ close_button . addEventListener ( 'click' , hide , false ) ;
223
+ overlay . addEventListener ( 'click' , hide , false ) ;
224
+ }
225
+
226
+
227
+ if ( typeof params . js_module === 'function' ) {
228
+ var result = params . js_module . call ( this , this ) ;
229
+ utils . mixin ( this , result ) ;
230
+ }
231
+
159
232
function show ( ) {
160
- el . style . display = 'block' ;
161
- } ;
233
+ utils . dom . show ( el ) ;
234
+ if ( overlay ) {
235
+ utils . dom . show ( overlay ) ;
236
+ }
237
+ layers . push ( this ) ;
238
+ }
239
+
240
+ function hide ( ) {
241
+ utils . dom . hide ( el ) ;
242
+ if ( overlay ) {
243
+ utils . dom . hide ( overlay ) ;
244
+ }
245
+ layers . pop ( this ) ;
246
+ }
162
247
163
248
this . show = show ;
164
249
this . hide = hide ;
165
250
}
166
251
167
-
168
- var a = new Window ( {
169
- content : '#help' ,
170
- movable : false ,
171
- closable : true ,
172
- overlay : true ,
173
- layout : 'black' ,
174
- header : 'This is window' ,
175
- js_module : function ( content_el ) {
176
- content_el . addEventListener ( 'click' , function ( ) {
177
- alert ( 3949732523 ) ;
178
- } , false ) ;
179
- }
180
- } ) ;
181
-
182
-
183
252
return {
184
- Menu : Menu ,
185
- Window : Window
253
+ utils : utils ,
254
+ Menu : Menu ,
255
+ Window : Window
186
256
} ;
187
257
} ) ( ) ;
0 commit comments