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