]>
Commit | Line | Data |
---|---|---|
bb64de6e DM |
1 | // ExtJS related things |
2 | ||
3 | // do not send '_dc' parameter | |
4 | Ext.Ajax.disableCaching = false; | |
5 | ||
30076ed6 TL |
6 | // FIXME: HACK! Makes scrolling in number spinner work again. fixed in ExtJS >= 6.1 |
7 | if (Ext.isFirefox) { | |
8 | Ext.$eventNameMap.DOMMouseScroll = 'DOMMouseScroll'; | |
9 | } | |
10 | ||
bb64de6e DM |
11 | // custom Vtypes |
12 | Ext.apply(Ext.form.field.VTypes, { | |
13 | IPAddress: function(v) { | |
14 | return Proxmox.Utils.IP4_match.test(v); | |
15 | }, | |
16 | IPAddressText: gettext('Example') + ': 192.168.1.1', | |
17 | IPAddressMask: /[\d\.]/i, | |
18 | ||
19 | IPCIDRAddress: function(v) { | |
20 | var result = Proxmox.Utils.IP4_cidr_match.exec(v); | |
21 | // limits according to JSON Schema see | |
22 | // pve-common/src/PVE/JSONSchema.pm | |
23 | return (result !== null && result[1] >= 8 && result[1] <= 32); | |
24 | }, | |
25 | IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32', | |
26 | IPCIDRAddressMask: /[\d\.\/]/i, | |
27 | ||
28 | IP6Address: function(v) { | |
29 | return Proxmox.Utils.IP6_match.test(v); | |
30 | }, | |
31 | IP6AddressText: gettext('Example') + ': 2001:DB8::42', | |
32 | IP6AddressMask: /[A-Fa-f0-9:]/, | |
33 | ||
34 | IP6CIDRAddress: function(v) { | |
35 | var result = Proxmox.Utils.IP6_cidr_match.exec(v); | |
36 | // limits according to JSON Schema see | |
37 | // pve-common/src/PVE/JSONSchema.pm | |
a2fb6c87 | 38 | return (result !== null && result[1] >= 8 && result[1] <= 128); |
bb64de6e | 39 | }, |
a2fb6c87 | 40 | IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-128', |
bb64de6e DM |
41 | IP6CIDRAddressMask: /[A-Fa-f0-9:\/]/, |
42 | ||
43 | IP6PrefixLength: function(v) { | |
44 | return v >= 0 && v <= 128; | |
45 | }, | |
46 | IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128', | |
47 | IP6PrefixLengthMask: /[0-9]/, | |
48 | ||
49 | IP64Address: function(v) { | |
50 | return Proxmox.Utils.IP64_match.test(v); | |
51 | }, | |
52 | IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42', | |
53 | IP64AddressMask: /[A-Fa-f0-9\.:]/, | |
54 | ||
577b6c75 ML |
55 | IP64CIDRAddress: function(v) { |
56 | var result = Proxmox.Utils.IP64_cidr_match.exec(v); | |
57 | if (result === null) { | |
58 | return false; | |
59 | } | |
60 | if (result[1] !== undefined) { | |
61 | return result[1] >= 8 && result[1] <= 128; | |
62 | } else if (result[2] !== undefined) { | |
63 | return result[2] >= 8 && result[2] <= 32; | |
64 | } else { | |
65 | return false; | |
66 | } | |
67 | }, | |
68 | IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64', | |
69 | IP64CIDRAddressMask: /[A-Fa-f0-9\.:\/]/, | |
70 | ||
bb64de6e DM |
71 | MacAddress: function(v) { |
72 | return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v); | |
73 | }, | |
74 | MacAddressMask: /[a-fA-F0-9:]/, | |
75 | MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab', | |
76 | ||
8f449655 | 77 | MacPrefix: function(v) { |
add18fad | 78 | return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v); |
8f449655 TL |
79 | }, |
80 | MacPrefixMask: /[a-fA-F0-9:]/, | |
ffe26505 | 81 | MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'), |
8f449655 | 82 | |
bb64de6e DM |
83 | BridgeName: function(v) { |
84 | return (/^vmbr\d{1,4}$/).test(v); | |
85 | }, | |
86 | BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
87 | ||
88 | BondName: function(v) { | |
89 | return (/^bond\d{1,4}$/).test(v); | |
90 | }, | |
91 | BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
92 | ||
93 | InterfaceName: function(v) { | |
94 | return (/^[a-z][a-z0-9_]{1,20}$/).test(v); | |
95 | }, | |
96 | InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" + | |
97 | gettext("Minimum characters") + ": 2" + "<br />" + | |
98 | gettext("Maximum characters") + ": 21" + "<br />" + | |
99 | gettext("Must start with") + ": 'a-z'", | |
100 | ||
bb64de6e DM |
101 | StorageId: function(v) { |
102 | return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v); | |
103 | }, | |
104 | StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" + | |
105 | gettext("Minimum characters") + ": 2" + "<br />" + | |
106 | gettext("Must start with") + ": 'A-Z', 'a-z'<br />" + | |
107 | gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />", | |
108 | ||
109 | ConfigId: function(v) { | |
110 | return (/^[a-z][a-z0-9\_]+$/i).test(v); | |
111 | }, | |
112 | ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" + | |
113 | gettext("Minimum characters") + ": 2" + "<br />" + | |
114 | gettext("Must start with") + ": " + gettext("letter"), | |
115 | ||
116 | HttpProxy: function(v) { | |
117 | return (/^http:\/\/.*$/).test(v); | |
118 | }, | |
119 | HttpProxyText: gettext('Example') + ": http://username:password@host:port/", | |
120 | ||
121 | DnsName: function(v) { | |
122 | return Proxmox.Utils.DnsName_match.test(v); | |
123 | }, | |
124 | DnsNameText: gettext('This is not a valid DNS name'), | |
125 | ||
126 | // workaround for https://www.sencha.com/forum/showthread.php?302150 | |
127 | proxmoxMail: function(v) { | |
128 | return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v); | |
129 | }, | |
130 | proxmoxMailText: gettext('Example') + ": user@example.com", | |
131 | ||
ba916e58 DC |
132 | DnsOrIp: function(v) { |
133 | if (!Proxmox.Utils.DnsName_match.test(v) && | |
694a76f6 | 134 | !Proxmox.Utils.IP64_match.test(v)) { |
ba916e58 DC |
135 | return false; |
136 | } | |
137 | ||
138 | return true; | |
139 | }, | |
694a76f6 | 140 | DnsOrIpText: gettext('Not a valid DNS name or IP address.'), |
ba916e58 | 141 | |
bb64de6e DM |
142 | HostList: function(v) { |
143 | var list = v.split(/[\ \,\;]+/); | |
144 | var i; | |
145 | for (i = 0; i < list.length; i++) { | |
146 | if (list[i] == "") { | |
147 | continue; | |
148 | } | |
149 | ||
150 | if (!Proxmox.Utils.HostPort_match.test(list[i]) && | |
151 | !Proxmox.Utils.HostPortBrackets_match.test(list[i]) && | |
152 | !Proxmox.Utils.IP6_dotnotation_match.test(list[i])) { | |
153 | return false; | |
154 | } | |
155 | } | |
156 | ||
157 | return true; | |
158 | }, | |
36704a2f DM |
159 | HostListText: gettext('Not a valid list of hosts'), |
160 | ||
161 | password: function(val, field) { | |
162 | if (field.initialPassField) { | |
163 | var pwd = field.up('form').down( | |
164 | '[name=' + field.initialPassField + ']'); | |
165 | return (val == pwd.getValue()); | |
166 | } | |
167 | return true; | |
168 | }, | |
169 | ||
170 | passwordText: gettext('Passwords do not match') | |
bb64de6e DM |
171 | }); |
172 | ||
aea77b2c DC |
173 | // Firefox 52+ Touchscreen bug |
174 | // see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2 | |
175 | // and https://bugzilla.proxmox.com/show_bug.cgi?id=1223 | |
176 | Ext.define('EXTJS_23846.Element', { | |
177 | override: 'Ext.dom.Element' | |
178 | }, function(Element) { | |
179 | var supports = Ext.supports, | |
180 | proto = Element.prototype, | |
181 | eventMap = proto.eventMap, | |
182 | additiveEvents = proto.additiveEvents; | |
183 | ||
184 | if (Ext.os.is.Desktop && supports.TouchEvents && !supports.PointerEvents) { | |
185 | eventMap.touchstart = 'mousedown'; | |
186 | eventMap.touchmove = 'mousemove'; | |
187 | eventMap.touchend = 'mouseup'; | |
188 | eventMap.touchcancel = 'mouseup'; | |
189 | ||
190 | additiveEvents.mousedown = 'mousedown'; | |
191 | additiveEvents.mousemove = 'mousemove'; | |
192 | additiveEvents.mouseup = 'mouseup'; | |
193 | additiveEvents.touchstart = 'touchstart'; | |
194 | additiveEvents.touchmove = 'touchmove'; | |
195 | additiveEvents.touchend = 'touchend'; | |
196 | additiveEvents.touchcancel = 'touchcancel'; | |
197 | ||
198 | additiveEvents.pointerdown = 'mousedown'; | |
199 | additiveEvents.pointermove = 'mousemove'; | |
200 | additiveEvents.pointerup = 'mouseup'; | |
201 | additiveEvents.pointercancel = 'mouseup'; | |
202 | } | |
203 | }); | |
204 | ||
205 | Ext.define('EXTJS_23846.Gesture', { | |
206 | override: 'Ext.event.publisher.Gesture' | |
207 | }, function(Gesture) { | |
208 | var me = Gesture.instance; | |
209 | ||
210 | if (Ext.supports.TouchEvents && !Ext.isWebKit && Ext.os.is.Desktop) { | |
211 | me.handledDomEvents.push('mousedown', 'mousemove', 'mouseup'); | |
212 | me.registerEvents(); | |
213 | } | |
214 | }); | |
215 | ||
acfbf255 DC |
216 | Ext.define('EXTJS_18900.Pie', { |
217 | override: 'Ext.chart.series.Pie', | |
218 | ||
219 | // from 6.0.2 | |
220 | betweenAngle: function (x, a, b) { | |
221 | var pp = Math.PI * 2, | |
222 | offset = this.rotationOffset; | |
223 | ||
224 | if (a === b) { | |
225 | return false; | |
226 | } | |
227 | ||
228 | if (!this.getClockwise()) { | |
229 | x *= -1; | |
230 | a *= -1; | |
231 | b *= -1; | |
232 | a -= offset; | |
233 | b -= offset; | |
234 | } else { | |
235 | a += offset; | |
236 | b += offset; | |
237 | } | |
238 | ||
239 | x -= a; | |
240 | b -= a; | |
241 | ||
242 | // Normalize, so that both x and b are in the [0,360) interval. | |
243 | x %= pp; | |
244 | b %= pp; | |
245 | x += pp; | |
246 | b += pp; | |
247 | x %= pp; | |
248 | b %= pp; | |
249 | ||
250 | // Because 360 * n angles will be normalized to 0, | |
251 | // we need to treat b === 0 as a special case. | |
252 | return x < b || b === 0; | |
253 | }, | |
254 | }); | |
255 | ||
3c158249 TL |
256 | // we always want the number in x.y format and never in, e.g., x,y |
257 | Ext.define('PVE.form.field.Number', { | |
258 | override: 'Ext.form.field.Number', | |
259 | submitLocaleSeparator: false | |
260 | }); | |
261 | ||
bb64de6e DM |
262 | // ExtJs 5-6 has an issue with caching |
263 | // see https://www.sencha.com/forum/showthread.php?308989 | |
264 | Ext.define('Proxmox.UnderlayPool', { | |
265 | override: 'Ext.dom.UnderlayPool', | |
266 | ||
267 | checkOut: function () { | |
268 | var cache = this.cache, | |
269 | len = cache.length, | |
270 | el; | |
271 | ||
272 | // do cleanup because some of the objects might have been destroyed | |
273 | while (len--) { | |
274 | if (cache[len].destroyed) { | |
275 | cache.splice(len, 1); | |
276 | } | |
277 | } | |
278 | // end do cleanup | |
279 | ||
280 | el = cache.shift(); | |
281 | ||
282 | if (!el) { | |
283 | el = Ext.Element.create(this.elementConfig); | |
284 | el.setVisibilityMode(2); | |
285 | //<debug> | |
286 | // tell the spec runner to ignore this element when checking if the dom is clean | |
287 | el.dom.setAttribute('data-sticky', true); | |
288 | //</debug> | |
289 | } | |
290 | ||
291 | return el; | |
292 | } | |
293 | }); | |
294 | ||
a2d8b9a9 DC |
295 | // 'Enter' in Textareas and aria multiline fields should not activate the |
296 | // defaultbutton, fixed in extjs 6.0.2 | |
297 | Ext.define('PVE.panel.Panel', { | |
298 | override: 'Ext.panel.Panel', | |
299 | ||
300 | fireDefaultButton: function(e) { | |
301 | if (e.target.getAttribute('aria-multiline') === 'true' || | |
302 | e.target.tagName === "TEXTAREA") { | |
303 | return true; | |
304 | } | |
305 | return this.callParent(arguments); | |
306 | } | |
307 | }); | |
308 | ||
bb64de6e DM |
309 | // if the order of the values are not the same in originalValue and value |
310 | // extjs will not overwrite value, but marks the field dirty and thus | |
311 | // the reset button will be enabled (but clicking it changes nothing) | |
312 | // so if the arrays are not the same after resetting, we | |
313 | // clear and set it | |
314 | Ext.define('Proxmox.form.ComboBox', { | |
315 | override: 'Ext.form.field.ComboBox', | |
316 | ||
317 | reset: function() { | |
318 | // copied from combobox | |
319 | var me = this; | |
320 | me.callParent(); | |
bb64de6e DM |
321 | |
322 | // clear and set when not the same | |
323 | var value = me.getValue(); | |
324 | if (Ext.isArray(me.originalValue) && Ext.isArray(value) && !Ext.Array.equals(value, me.originalValue)) { | |
325 | me.clearValue(); | |
326 | me.setValue(me.originalValue); | |
327 | } | |
328 | } | |
329 | }); | |
330 | ||
47d1c80c TL |
331 | // when refreshing a grid/tree view, restoring the focus moves the view back to |
332 | // the previously focused item. Save scroll position before refocusing. | |
333 | Ext.define(null, { | |
334 | override: 'Ext.view.Table', | |
335 | ||
336 | jumpToFocus: false, | |
337 | ||
338 | saveFocusState: function() { | |
339 | var me = this, | |
340 | store = me.dataSource, | |
341 | actionableMode = me.actionableMode, | |
342 | navModel = me.getNavigationModel(), | |
343 | focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true), | |
344 | refocusRow, refocusCol; | |
345 | ||
346 | if (focusPosition) { | |
347 | // Separate this from the instance that the nav model is using. | |
348 | focusPosition = focusPosition.clone(); | |
349 | ||
350 | // Exit actionable mode. | |
351 | // We must inform any Actionables that they must relinquish control. | |
352 | // Tabbability must be reset. | |
353 | if (actionableMode) { | |
354 | me.ownerGrid.setActionableMode(false); | |
355 | } | |
356 | ||
357 | // Blur the focused descendant, but do not trigger focusLeave. | |
358 | me.el.dom.focus(); | |
359 | ||
360 | // Exiting actionable mode navigates to the owning cell, so in either focus mode we must | |
361 | // clear the navigation position | |
362 | navModel.setPosition(); | |
363 | ||
364 | // The following function will attempt to refocus back in the same mode to the same cell | |
365 | // as it was at before based upon the previous record (if it's still inthe store), or the row index. | |
366 | return function() { | |
367 | // If we still have data, attempt to refocus in the same mode. | |
368 | if (store.getCount()) { | |
369 | ||
370 | // Adjust expectations of where we are able to refocus according to what kind of destruction | |
371 | // might have been wrought on this view's DOM during focus save. | |
372 | refocusRow = Math.min(focusPosition.rowIdx, me.all.getCount() - 1); | |
373 | refocusCol = Math.min(focusPosition.colIdx, me.getVisibleColumnManager().getColumns().length - 1); | |
374 | focusPosition = new Ext.grid.CellContext(me).setPosition( | |
375 | store.contains(focusPosition.record) ? focusPosition.record : refocusRow, refocusCol); | |
376 | ||
377 | if (actionableMode) { | |
378 | me.ownerGrid.setActionableMode(true, focusPosition); | |
379 | } else { | |
380 | me.cellFocused = true; | |
381 | ||
382 | // we sometimes want to scroll back to where we were | |
383 | var x = me.getScrollX(); | |
384 | var y = me.getScrollY(); | |
385 | ||
386 | // Pass "preventNavigation" as true so that that does not cause selection. | |
387 | navModel.setPosition(focusPosition, null, null, null, true); | |
388 | ||
389 | if (!me.jumpToFocus) { | |
390 | me.scrollTo(x,y); | |
391 | } | |
392 | } | |
393 | } | |
394 | // No rows - focus associated column header | |
395 | else { | |
396 | focusPosition.column.focus(); | |
397 | } | |
398 | }; | |
399 | } | |
400 | return Ext.emptyFn; | |
401 | } | |
402 | }); | |
403 | ||
bb64de6e DM |
404 | // should be fixed with ExtJS 6.0.2, see: |
405 | // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll | |
406 | Ext.define('Proxmox.Datepicker', { | |
407 | override: 'Ext.picker.Date', | |
408 | hideMode: 'visibility' | |
409 | }); | |
410 | ||
a55813d6 DM |
411 | // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs). |
412 | // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns | |
413 | // data to be submitted. | |
1d9804a9 DM |
414 | Ext.define('Proxmox.form.field.Text', { |
415 | override: 'Ext.form.field.Text', | |
416 | ||
417 | setSubmitValue: function(v) { | |
418 | this.submitValue = v; | |
419 | }, | |
1d9804a9 DM |
420 | }); |
421 | ||
1fb41f2e TL |
422 | // this should be fixed with ExtJS 6.0.2 |
423 | // make mousescrolling work in firefox in the containers overflowhandler | |
424 | Ext.define(null, { | |
425 | override: 'Ext.layout.container.boxOverflow.Scroller', | |
426 | ||
427 | createWheelListener: function() { | |
428 | var me = this; | |
429 | if (Ext.isFirefox) { | |
430 | me.wheelListener = me.layout.innerCt.on('wheel', me.onMouseWheelFirefox, me, {destroyable: true}); | |
431 | } else { | |
432 | me.wheelListener = me.layout.innerCt.on('mousewheel', me.onMouseWheel, me, {destroyable: true}); | |
433 | } | |
434 | }, | |
435 | ||
436 | // special wheel handler for firefox. differs from the default onMouseWheel | |
437 | // handler by using deltaY instead of wheelDeltaY and no normalizing, | |
438 | // because it is already | |
439 | onMouseWheelFirefox: function(e) { | |
440 | e.stopEvent(); | |
441 | var delta = e.browserEvent.deltaY || 0; | |
442 | this.scrollBy(delta * this.wheelIncrement, false); | |
443 | } | |
444 | ||
445 | }); | |
446 | ||
312310e0 DC |
447 | // add '@' to the valid id |
448 | Ext.define('Proxmox.validIdReOverride', { | |
449 | override: 'Ext.Component', | |
450 | validIdRe: /^[a-z_][a-z0-9\-_\@]*$/i, | |
451 | }); | |
452 | ||
bb64de6e DM |
453 | // force alert boxes to be rendered with an Error Icon |
454 | // since Ext.Msg is an object and not a prototype, we need to override it | |
455 | // after the framework has been initiated | |
456 | Ext.onReady(function() { | |
457 | /*jslint confusion: true */ | |
458 | Ext.override(Ext.Msg, { | |
459 | alert: function(title, message, fn, scope) { | |
460 | if (Ext.isString(title)) { | |
461 | var config = { | |
462 | title: title, | |
463 | message: message, | |
464 | icon: this.ERROR, | |
465 | buttons: this.OK, | |
466 | fn: fn, | |
467 | scope : scope, | |
468 | minWidth: this.minWidth | |
469 | }; | |
470 | return this.show(config); | |
471 | } | |
472 | } | |
473 | }); | |
474 | /*jslint confusion: false */ | |
475 | }); | |
476 | Ext.define('Ext.ux.IFrame', { | |
477 | extend: 'Ext.Component', | |
478 | ||
479 | alias: 'widget.uxiframe', | |
480 | ||
481 | loadMask: 'Loading...', | |
482 | ||
483 | src: 'about:blank', | |
484 | ||
485 | renderTpl: [ | |
486 | '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>' | |
487 | ], | |
488 | childEls: ['iframeEl'], | |
489 | ||
490 | initComponent: function () { | |
491 | this.callParent(); | |
492 | ||
493 | this.frameName = this.frameName || this.id + '-frame'; | |
494 | }, | |
495 | ||
496 | initEvents : function() { | |
497 | var me = this; | |
498 | me.callParent(); | |
499 | me.iframeEl.on('load', me.onLoad, me); | |
500 | }, | |
501 | ||
502 | initRenderData: function() { | |
503 | return Ext.apply(this.callParent(), { | |
504 | src: this.src, | |
505 | frameName: this.frameName | |
506 | }); | |
507 | }, | |
508 | ||
509 | getBody: function() { | |
510 | var doc = this.getDoc(); | |
511 | return doc.body || doc.documentElement; | |
512 | }, | |
513 | ||
514 | getDoc: function() { | |
515 | try { | |
516 | return this.getWin().document; | |
517 | } catch (ex) { | |
518 | return null; | |
519 | } | |
520 | }, | |
521 | ||
522 | getWin: function() { | |
523 | var me = this, | |
524 | name = me.frameName, | |
525 | win = Ext.isIE | |
526 | ? me.iframeEl.dom.contentWindow | |
527 | : window.frames[name]; | |
528 | return win; | |
529 | }, | |
530 | ||
531 | getFrame: function() { | |
532 | var me = this; | |
533 | return me.iframeEl.dom; | |
534 | }, | |
535 | ||
536 | beforeDestroy: function () { | |
537 | this.cleanupListeners(true); | |
538 | this.callParent(); | |
539 | }, | |
540 | ||
541 | cleanupListeners: function(destroying){ | |
542 | var doc, prop; | |
543 | ||
544 | if (this.rendered) { | |
545 | try { | |
546 | doc = this.getDoc(); | |
547 | if (doc) { | |
548 | /*jslint nomen: true*/ | |
549 | Ext.get(doc).un(this._docListeners); | |
550 | /*jslint nomen: false*/ | |
551 | if (destroying && doc.hasOwnProperty) { | |
552 | for (prop in doc) { | |
553 | if (doc.hasOwnProperty(prop)) { | |
554 | delete doc[prop]; | |
555 | } | |
556 | } | |
557 | } | |
558 | } | |
559 | } catch(e) { } | |
560 | } | |
561 | }, | |
562 | ||
563 | onLoad: function() { | |
564 | var me = this, | |
565 | doc = me.getDoc(), | |
566 | fn = me.onRelayedEvent; | |
567 | ||
568 | if (doc) { | |
569 | try { | |
570 | // These events need to be relayed from the inner document (where they stop | |
571 | // bubbling) up to the outer document. This has to be done at the DOM level so | |
572 | // the event reaches listeners on elements like the document body. The effected | |
573 | // mechanisms that depend on this bubbling behavior are listed to the right | |
574 | // of the event. | |
575 | /*jslint nomen: true*/ | |
576 | Ext.get(doc).on( | |
577 | me._docListeners = { | |
578 | mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) | |
579 | mousemove: fn, // window resize drag detection | |
580 | mouseup: fn, // window resize termination | |
581 | click: fn, // not sure, but just to be safe | |
582 | dblclick: fn, // not sure again | |
583 | scope: me | |
584 | } | |
585 | ); | |
586 | /*jslint nomen: false*/ | |
587 | } catch(e) { | |
588 | // cannot do this xss | |
589 | } | |
590 | ||
591 | // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! | |
592 | Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); | |
593 | ||
594 | this.el.unmask(); | |
595 | this.fireEvent('load', this); | |
596 | ||
597 | } else if (me.src) { | |
598 | ||
599 | this.el.unmask(); | |
600 | this.fireEvent('error', this); | |
601 | } | |
602 | ||
603 | ||
604 | }, | |
605 | ||
606 | onRelayedEvent: function (event) { | |
607 | // relay event from the iframe's document to the document that owns the iframe... | |
608 | ||
609 | var iframeEl = this.iframeEl, | |
610 | ||
611 | // Get the left-based iframe position | |
612 | iframeXY = iframeEl.getTrueXY(), | |
613 | originalEventXY = event.getXY(), | |
614 | ||
615 | // Get the left-based XY position. | |
616 | // This is because the consumer of the injected event will | |
617 | // perform its own RTL normalization. | |
618 | eventXY = event.getTrueXY(); | |
619 | ||
620 | // the event from the inner document has XY relative to that document's origin, | |
621 | // so adjust it to use the origin of the iframe in the outer document: | |
622 | event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; | |
623 | ||
624 | event.injectEvent(iframeEl); // blame the iframe for the event... | |
625 | ||
626 | event.xy = originalEventXY; // restore the original XY (just for safety) | |
627 | }, | |
628 | ||
629 | load: function (src) { | |
630 | var me = this, | |
631 | text = me.loadMask, | |
632 | frame = me.getFrame(); | |
633 | ||
634 | if (me.fireEvent('beforeload', me, src) !== false) { | |
635 | if (text && me.el) { | |
636 | me.el.mask(text); | |
637 | } | |
638 | ||
639 | frame.src = me.src = (src || me.src); | |
640 | } | |
641 | } | |
642 | }); |