1 | (function() |
---|
2 | { |
---|
3 | var _drag_drop = new DragDrop(); |
---|
4 | |
---|
5 | var _xtools; |
---|
6 | var index = 10000; |
---|
7 | var _all_windows = []; |
---|
8 | |
---|
9 | function _load(pId) |
---|
10 | { |
---|
11 | if ( !(top.document.getElementById(pId + '__window_master')) ) |
---|
12 | { |
---|
13 | var xml = _xtools.xml('window'); |
---|
14 | |
---|
15 | var name = xml.createElement('name'); |
---|
16 | name.appendChild(xml.createTextNode(pId)); |
---|
17 | xml.documentElement.appendChild(name); |
---|
18 | |
---|
19 | var _window = top.document.createElement("div"); |
---|
20 | _window.innerHTML = _xtools.parse(xml, 'window.xsl'); |
---|
21 | _window.setAttribute('id', pId + '__window_master'); |
---|
22 | _window.setAttribute('class', 'window'); |
---|
23 | _window.setAttribute('className', 'window'); |
---|
24 | |
---|
25 | _window = this._TARGET.appendChild(_window); |
---|
26 | |
---|
27 | _focus(_window); |
---|
28 | |
---|
29 | function _click(e) |
---|
30 | { |
---|
31 | _focus(e); |
---|
32 | _window.oncontextmenu = new Function("return false"); |
---|
33 | return false; |
---|
34 | } |
---|
35 | |
---|
36 | _config(_window, 'onmousedown', _click); |
---|
37 | |
---|
38 | _drag_drop.drag(_window); |
---|
39 | _window.childNodes[1].setAttribute('dragdrop_child','true'); |
---|
40 | _window.childNodes[1].childNodes[0].setAttribute('dragdrop_child','true'); |
---|
41 | _window.childNodes[1].childNodes[1].setAttribute('dragdrop_child','true'); |
---|
42 | |
---|
43 | _config(_window.childNodes[1].childNodes[2].childNodes[0], 'onclick', _button); |
---|
44 | _config(_window.childNodes[1].childNodes[2].childNodes[1], 'onclick', _button); |
---|
45 | _config(_window.childNodes[1].childNodes[2].childNodes[2], 'onclick', _button); |
---|
46 | |
---|
47 | _all_windows[pId + '__window_master'] = { |
---|
48 | 'id' : pId, |
---|
49 | 'wm' : _window, // wm - window master |
---|
50 | 'ic' : _window.childNodes[1].firstChild, // wt - window title |
---|
51 | 'wt' : _window.childNodes[1].childNodes[1], // wt - window title |
---|
52 | 'bc' : _window.childNodes[1].childNodes[2].childNodes[0], // bc - button close |
---|
53 | 'bx' : _window.childNodes[1].childNodes[2].childNodes[1], // bx - button maximize |
---|
54 | 'bz' : _window.childNodes[1].childNodes[2].childNodes[2], // bz - button minimize |
---|
55 | 'wc' : _window.childNodes[2].firstChild, // wc - window content |
---|
56 | 'wf' : _window.childNodes[3], // wf - window footer |
---|
57 | 'button' : _button, |
---|
58 | 'content' : _content, |
---|
59 | 'close' : function() |
---|
60 | { |
---|
61 | _button(_window.childNodes[1].childNodes[2].childNodes[0]); |
---|
62 | }, |
---|
63 | 'focus' : _focus, |
---|
64 | 'hidden' : function() |
---|
65 | { |
---|
66 | _button(_window.childNodes[1].childNodes[2].childNodes[2]); |
---|
67 | }, |
---|
68 | 'icon' : _icon, |
---|
69 | 'loading' : function() |
---|
70 | { |
---|
71 | var _information = top.document.createElement('span'); |
---|
72 | _information.appendChild( |
---|
73 | top.document.createTextNode(imGetLang('Loading')) |
---|
74 | ); |
---|
75 | |
---|
76 | var _loading = top.document.createElement('div'); |
---|
77 | _loading.className = 'loading'; |
---|
78 | _loading.appendChild(_information); |
---|
79 | |
---|
80 | _content.call(this, _loading); |
---|
81 | }, |
---|
82 | 'position' : _position, |
---|
83 | 'show' : function() |
---|
84 | { |
---|
85 | _window.style.display = 'block'; |
---|
86 | }, |
---|
87 | 'size' : _size, |
---|
88 | 'title' : _title |
---|
89 | }; |
---|
90 | |
---|
91 | } |
---|
92 | return _all_windows[pId + '__window_master']; |
---|
93 | } |
---|
94 | |
---|
95 | function _browser() |
---|
96 | { |
---|
97 | var _width = 0, _height = 0; |
---|
98 | if ( typeof( window.innerWidth ) == 'number' ) |
---|
99 | { |
---|
100 | //Non-IE |
---|
101 | _width = top.window.innerWidth; |
---|
102 | _height = top.window.innerHeight; |
---|
103 | } |
---|
104 | else if ( top.document.documentElement && ( top.document.documentElement.clientWidth || top.document.documentElement.clientHeight ) ) |
---|
105 | { |
---|
106 | //IE 6+ in 'standards compliant mode' |
---|
107 | _width = top.document.documentElement.clientWidth; |
---|
108 | _height = top.document.documentElement.clientHeight; |
---|
109 | } |
---|
110 | else if( top.document.body && ( top.document.body.clientWidth || top.document.body.clientHeight ) ) |
---|
111 | { |
---|
112 | //IE 4 compatible |
---|
113 | _width = top.document.body.clientWidth; |
---|
114 | _height = top.document.body.clientHeight; |
---|
115 | } |
---|
116 | |
---|
117 | return {'width' : _width, 'height' : _height} |
---|
118 | } |
---|
119 | |
---|
120 | function _button() |
---|
121 | { |
---|
122 | var b = arguments[0]; |
---|
123 | b = ( !b.type ) ? |
---|
124 | b : ( b.target ) ? |
---|
125 | b.target : b.srcElement; |
---|
126 | |
---|
127 | var w = b.parentNode.parentNode.parentNode; |
---|
128 | switch ( b.title ) |
---|
129 | { |
---|
130 | case 'close' : |
---|
131 | w.parentNode.removeChild(w); |
---|
132 | delete _all_windows[w.id]; |
---|
133 | break; |
---|
134 | case 'minimize' : |
---|
135 | w.style.display = 'none'; |
---|
136 | break; |
---|
137 | case 'maximize' : |
---|
138 | if ( !w.getAttribute('wParams') ) |
---|
139 | { |
---|
140 | var _wParams = (parseFloat(w.style.width) - 13); |
---|
141 | _wParams += ':' + parseFloat(w.childNodes[2].firstChild.style.maxHeight); |
---|
142 | _wParams += ':' + parseFloat(w.style.left); |
---|
143 | _wParams += ':' + parseFloat(w.style.right); |
---|
144 | _wParams += ':' + parseFloat(w.style.top); |
---|
145 | _wParams += ':' + parseFloat(w.style.bottom); |
---|
146 | w.setAttribute('wParams', _wParams); |
---|
147 | |
---|
148 | var _bwr = _browser(); |
---|
149 | w.style.top = "0px"; |
---|
150 | w.style.left = "0px"; |
---|
151 | w.style.height = "100%"; |
---|
152 | w.style.width = "100%"; |
---|
153 | |
---|
154 | var _style = w.childNodes[2].firstChild.getAttribute('style'); |
---|
155 | if ( typeof _style == 'object' && _style.cssText ) |
---|
156 | _style = _style.cssText; |
---|
157 | |
---|
158 | if ( w.childNodes[2].firstChild.style.cssText ) |
---|
159 | w.childNodes[2].firstChild.style.cssText = ''; |
---|
160 | |
---|
161 | _style = _style.replace(/max-height: ?\d+;?/i, ''); |
---|
162 | |
---|
163 | w.childNodes[2].firstChild.setAttribute('style', _style); |
---|
164 | |
---|
165 | w.childNodes[2].firstChild.style.height = (_bwr.height - 41) + "px"; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | var _wParams = w.getAttribute('wParams').split(':'); |
---|
170 | w.removeAttribute('wParams'); |
---|
171 | |
---|
172 | var _style = w.getAttribute('style'); |
---|
173 | if ( typeof _style == 'object' && _style.cssText ) |
---|
174 | _style = _style.cssText; |
---|
175 | |
---|
176 | _style = _style.replace(/height: ?100%;?/i, '').replace(/width: ?100%;?/i, ''); |
---|
177 | _style = _style.replace(/left: ?0px;?/i, '').replace(/top: ?0px;?/i, ''); |
---|
178 | |
---|
179 | // for IE |
---|
180 | if ( w.style.cssText ) |
---|
181 | w.style.cssText = ''; |
---|
182 | |
---|
183 | w.setAttribute('style', _style); |
---|
184 | |
---|
185 | w = _all_windows[w.id]; |
---|
186 | |
---|
187 | _style = w.wc.getAttribute('style'); |
---|
188 | if ( typeof _style == 'object' && _style.cssText ) |
---|
189 | _style = _style.cssText; |
---|
190 | |
---|
191 | _style = _style.replace(/height: ?\d+px;?/i, ''); |
---|
192 | |
---|
193 | // for IE |
---|
194 | if ( w.wc.style.cssText ) |
---|
195 | w.wc.style.cssText = ''; |
---|
196 | |
---|
197 | w.wc.setAttribute('style', _style); |
---|
198 | |
---|
199 | w.size(parseFloat(_wParams[0]), parseFloat(_wParams[1])); |
---|
200 | |
---|
201 | var x = ''; |
---|
202 | var _right = false; |
---|
203 | if ( !isNaN(_wParams[2]) ) |
---|
204 | x = parseFloat(_wParams[2]); |
---|
205 | else if ( !isNaN(_wParams[3]) ) |
---|
206 | { |
---|
207 | x = parseFloat(_wParams[3]); |
---|
208 | _right = true; |
---|
209 | } |
---|
210 | |
---|
211 | var y = ''; |
---|
212 | var _bottom = false; |
---|
213 | if ( !isNaN(_wParams[4]) ) |
---|
214 | y = parseFloat(_wParams[4]); |
---|
215 | else if ( !isNaN(_wParams[5]) ) |
---|
216 | { |
---|
217 | y = parseFloat(_wParams[5]); |
---|
218 | _bottom = true; |
---|
219 | } |
---|
220 | |
---|
221 | w.position(x, y, _right, _bottom); |
---|
222 | } |
---|
223 | break; |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | function _config(pObj, pEvent, pHandler) |
---|
228 | { |
---|
229 | if ( typeof pObj == 'object' ) |
---|
230 | { |
---|
231 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
232 | pEvent = pEvent.substring(2, pEvent.length); |
---|
233 | |
---|
234 | if ( pObj.addEventListener ) |
---|
235 | pObj.addEventListener(pEvent, pHandler, false); |
---|
236 | else if ( pObj.attachEvent ) |
---|
237 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | function _content() |
---|
242 | { |
---|
243 | var _content = this.wc; |
---|
244 | while ( _content.hasChildNodes() ) |
---|
245 | _content.removeChild(_content.firstChild); |
---|
246 | var l = arguments.length; |
---|
247 | for ( var i = 0; i < l; i++ ) |
---|
248 | if ( typeof arguments[i] == 'object' ) |
---|
249 | _content.appendChild(arguments[i]); |
---|
250 | else if ( typeof arguments[i] == 'string' ) |
---|
251 | _content.innerHTML += arguments[i]; |
---|
252 | } |
---|
253 | |
---|
254 | function _focus() |
---|
255 | { |
---|
256 | var w; |
---|
257 | if ( arguments.length ) |
---|
258 | w = arguments[0]; |
---|
259 | else |
---|
260 | w = this.wm; |
---|
261 | |
---|
262 | w = ( !w.type ) ? |
---|
263 | w : ( w.target ) ? |
---|
264 | w.target : w.srcElement; |
---|
265 | |
---|
266 | while ( w.id.indexOf('__window_master') == -1 ) |
---|
267 | w = w.parentNode; |
---|
268 | |
---|
269 | index += 10; |
---|
270 | w.style.zIndex = index; |
---|
271 | } |
---|
272 | |
---|
273 | function _get(_pId) |
---|
274 | { |
---|
275 | var _win = false; |
---|
276 | if ( _all_windows[_pId + '__window_master'] ) |
---|
277 | _win = _all_windows[_pId + '__window_master']; |
---|
278 | return _win; |
---|
279 | } |
---|
280 | |
---|
281 | function _icon(_pIcon) |
---|
282 | { |
---|
283 | if ( typeof _pIcon == 'string' ) |
---|
284 | this.ic.style.backgroundImage = 'url(' + _pIcon + ')'; |
---|
285 | } |
---|
286 | |
---|
287 | function _position(pX, pY) |
---|
288 | { |
---|
289 | // for IE |
---|
290 | //if ( window.ActiveXObject ) |
---|
291 | // this.wm.style.position = 'absolute'; |
---|
292 | |
---|
293 | if ( typeof pX == 'number' ) |
---|
294 | if ( arguments[2] === true ) |
---|
295 | this.wm.style.right = pX + 'px'; |
---|
296 | else |
---|
297 | this.wm.style.left = pX + 'px'; |
---|
298 | |
---|
299 | if ( typeof pY == 'number' ) |
---|
300 | if ( arguments[3] === true ) |
---|
301 | this.wm.style.bottom = pY + 'px'; |
---|
302 | else |
---|
303 | this.wm.style.top = pY + 'px'; |
---|
304 | } |
---|
305 | |
---|
306 | function _size(pWidth, pHeight) |
---|
307 | { |
---|
308 | if ( typeof pWidth == 'number' && !isNaN(pWidth) ) |
---|
309 | this.wm.style.width = (13 + pWidth) + 'px'; |
---|
310 | |
---|
311 | if ( typeof pHeight == 'number' && !isNaN(pHeight) ) |
---|
312 | this.wc.style.maxHeight = pHeight + 'px'; |
---|
313 | } |
---|
314 | |
---|
315 | function _title(pTitle) |
---|
316 | { |
---|
317 | var _title = this.wt; |
---|
318 | while ( _title.hasChildNodes() ) |
---|
319 | _title.removeChild(_title.firstChild); |
---|
320 | _title.appendChild(top.document.createTextNode(pTitle)); |
---|
321 | } |
---|
322 | |
---|
323 | function Windows() |
---|
324 | { |
---|
325 | var _argv = arguments; |
---|
326 | var _argc = _argv.length; |
---|
327 | if ( (_argv[_argc - 1] != null) && (_argv[_argc - 1]).id ) |
---|
328 | this._TARGET = _argv[_argc - 1]; |
---|
329 | else |
---|
330 | this._TARGET = top.document.body; |
---|
331 | |
---|
332 | _xtools = arguments[0]; |
---|
333 | } |
---|
334 | |
---|
335 | Windows.prototype.load = _load; |
---|
336 | Windows.prototype.get = _get; |
---|
337 | window.Windows = Windows; |
---|
338 | } |
---|
339 | )(); |
---|