|
1 | 1 | /** |
2 | 2 | * This is designed to help with the problem of rendering dynamic content into Ext4 panels. It's a little ugly, but this |
3 | | - * component provides a div into which you render the webpart or report. On load, it will listen for that element's DOMSubtreeModified/DOMNodeInserted |
4 | | - * event, and resize the Ext containers if needed. It attempts to batch these events and only actually trigger a layout when a resize |
5 | | - * is needed. |
| 3 | + * component provides a div into which you render the webpart or report. On load, it will use a mutation observer to listen for |
| 4 | + * events that indicate content has been inserted. When that happens, it will fire a 'contentsizechange' event and resize |
| 5 | + * the Ext containers if needed. It attempts to batch these events and only actually trigger a layout when a resize is needed. |
6 | 6 | * |
7 | | - * NOTE: this currently handles the problem by adding DOMSubtreeModified/DOMNodeInserted listeners and manually resizing on change. |
| 7 | + * NOTE: this currently handles the problem by adding a mutation observer and manually resizing on change. |
8 | 8 | * A more elegant solution would be to dig into Ext's layout engine and make a custom layout that will |
9 | 9 | * auto-size itself based on the width of our target element. We'd need to override the methods that calculate weight and height. |
10 | 10 | * Figuring that out will make WebPartPanel work better too. |
@@ -40,41 +40,15 @@ Ext4.define('LDK.mixin.ContentResizing', { |
40 | 40 | return; |
41 | 41 | } |
42 | 42 |
|
43 | | - if (Ext4.isIE){ |
44 | | - var cmp = this; |
45 | | - |
46 | | - el = el.query('*[name="webpart"]')[0]; |
47 | | - if (!Ext4.isDefined(el) && !isRetry){ |
48 | | - Ext4.defer(this.createListeners, 250, this, [true]); |
49 | | - return; |
50 | | - } |
51 | | - |
52 | | - if (!el && isRetry) { |
53 | | - return; |
54 | | - } |
55 | | - |
56 | | - if (el.addEventListener){ |
57 | | - el.addEventListener('DOMSubtreeModified', function(){ |
58 | | - cmp.fireEvent('contentsizechange'); |
59 | | - }, false); |
60 | | - } |
61 | | - else if (el.attachEvent){ |
62 | | - el.attachEvent('DOMSubtreeModified', function(){ |
63 | | - cmp.fireEvent('contentsizechange'); |
64 | | - }); |
65 | | - } |
66 | | - else { |
67 | | - LDK.Utils.logToServer({ |
68 | | - message: 'Unable to find appropriate event in ContentResizingPanel', |
69 | | - level: 'ERROR', |
70 | | - includeContext: true |
71 | | - }); |
72 | | - } |
73 | | - } |
74 | | - else if (Ext4.isDefined(el)) { |
75 | | - el.on('DOMNodeInserted', function(){ |
76 | | - this.fireEvent('contentsizechange'); |
77 | | - }, this); |
| 43 | + if (Ext4.isDefined(el)) { |
| 44 | + // Issue 50942: Removal of support for mutation events. This replaces DOMNodeInserted event handler. |
| 45 | + const observer = new MutationObserver(mutationList => |
| 46 | + mutationList.filter(m => m.type === 'childList').forEach(m => { |
| 47 | + m.addedNodes.forEach(function(){ |
| 48 | + this.fireEvent('contentsizechange'); |
| 49 | + }, this); |
| 50 | + })); |
| 51 | + observer.observe(el.dom,{childList: true, subtree: true}); |
78 | 52 |
|
79 | 53 | // Issue 31454: if the output has a clickable labkey-wp-header, also listen for that event |
80 | 54 | Ext4.each(el.query('.labkey-wp-header'), function(wpHeader) { |
|
0 commit comments