|
83 | 83 | * @constructor
|
84 | 84 | */
|
85 | 85 | var ResizeSensor = function(element, callback) {
|
86 |
| - |
| 86 | + |
87 | 87 | var observer;
|
88 |
| - |
| 88 | + |
89 | 89 | /**
|
90 | 90 | *
|
91 | 91 | * @constructor
|
|
161 | 161 | var lastWidth = size.width;
|
162 | 162 | var lastHeight = size.height;
|
163 | 163 | var initialHiddenCheck = true, resetRAF_id;
|
164 |
| - |
165 |
| - |
| 164 | + |
| 165 | + |
166 | 166 | var resetExpandShrink_ = function () {
|
167 |
| - expandChild.style.width = '100000px'; |
168 |
| - expandChild.style.height = '100000px'; |
169 |
| - |
170 |
| - expand.scrollLeft = 100000; |
171 |
| - expand.scrollTop = 100000; |
172 |
| - |
173 |
| - shrink.scrollLeft = 100000; |
174 |
| - shrink.scrollTop = 100000; |
175 |
| - }; |
| 167 | + expandChild.style.width = '100000px'; |
| 168 | + expandChild.style.height = '100000px'; |
| 169 | + |
| 170 | + expand.scrollLeft = 100000; |
| 171 | + expand.scrollTop = 100000; |
| 172 | + |
| 173 | + shrink.scrollLeft = 100000; |
| 174 | + shrink.scrollTop = 100000; |
| 175 | + }; |
176 | 176 | var reset = function() {
|
177 |
| - // Check if element is hidden |
178 |
| - if (initialHiddenCheck){ |
179 |
| - if (!expand.scrollTop && !expand.scrollLeft) { |
180 |
| - |
181 |
| - // reset |
182 |
| - resetExpandShrink_(); |
183 |
| - |
184 |
| - // Check in next frame |
185 |
| - if (!resetRAF_id){ |
186 |
| - resetRAF_id = requestAnimationFrame(function(){ |
187 |
| - resetRAF_id = 0; |
188 |
| - |
189 |
| - reset(); |
190 |
| - }); |
191 |
| - } |
192 |
| - |
193 |
| - return; |
194 |
| - } |
195 |
| - // Stop checking |
196 |
| - else{ |
197 |
| - initialHiddenCheck = false; |
198 |
| - } |
199 |
| - } |
200 |
| - |
201 |
| - resetExpandShrink_(); |
| 177 | + // Check if element is hidden |
| 178 | + if (initialHiddenCheck){ |
| 179 | + if (!expand.scrollTop && !expand.scrollLeft) { |
| 180 | + |
| 181 | + // reset |
| 182 | + resetExpandShrink_(); |
| 183 | + |
| 184 | + // Check in next frame |
| 185 | + if (!resetRAF_id){ |
| 186 | + resetRAF_id = requestAnimationFrame(function(){ |
| 187 | + resetRAF_id = 0; |
| 188 | + |
| 189 | + reset(); |
| 190 | + }); |
| 191 | + } |
| 192 | + |
| 193 | + return; |
| 194 | + } |
| 195 | + // Stop checking |
| 196 | + else{ |
| 197 | + initialHiddenCheck = false; |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + resetExpandShrink_(); |
202 | 202 | };
|
203 | 203 | element.resizeSensor.resetSensor = reset;
|
204 | 204 |
|
|
240 | 240 |
|
241 | 241 | addEvent(expand, 'scroll', onScroll);
|
242 | 242 | addEvent(shrink, 'scroll', onScroll);
|
243 |
| - |
| 243 | + |
244 | 244 | // Fix for custom Elements
|
245 | 245 | requestAnimationFrame(reset);
|
246 | 246 | }
|
247 |
| - |
| 247 | + |
248 | 248 | if (typeof ResizeObserver != "undefined") {
|
249 |
| - observer = new ResizeObserver(function(entries){ |
250 |
| - for (var entry of entries) { |
| 249 | + observer = new ResizeObserver(function(element){ |
| 250 | + forEachElement(element, function (elem) { |
251 | 251 | callback.call(
|
252 | 252 | this,
|
253 | 253 | {
|
254 |
| - width: entry.contentRect.width, |
255 |
| - height: entry.contentRect.height |
| 254 | + width: elem.contentRect.width, |
| 255 | + height: elem.contentRect.height |
256 | 256 | }
|
257 | 257 | );
|
258 |
| - } |
| 258 | + }); |
259 | 259 | });
|
260 | 260 | if (element !== undefined) {
|
261 | 261 | forEachElement(element, function(elem){
|
|
0 commit comments