Skip to content

Commit eab5e1b

Browse files
committed
Trigger initially the resize sensor, fixes #265
1 parent 389ca99 commit eab5e1b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/ElementQueries.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,12 @@
170170
if (!element.elementQueriesSetupInformation) {
171171
element.elementQueriesSetupInformation = new SetupInformation(element, id);
172172
}
173+
173174
if (!element.elementQueriesSensor) {
174175
element.elementQueriesSensor = new ResizeSensor(element, function () {
175176
element.elementQueriesSetupInformation.call();
176177
});
177178
}
178-
179-
element.elementQueriesSetupInformation.call();
180179
}
181180

182181
/**
@@ -441,7 +440,7 @@
441440
for (var i = 0, j = document.styleSheets.length; i < j; i++) {
442441
try {
443442
if (document.styleSheets[i].href && 0 === document.styleSheets[i].href.indexOf('file://')) {
444-
console.log("CssElementQueries: unable to parse local css files, " + document.styleSheets[i].href);
443+
console.warn("CssElementQueries: unable to parse local css files, " + document.styleSheets[i].href);
445444
}
446445

447446
readRules(document.styleSheets[i].cssRules || document.styleSheets[i].rules || document.styleSheets[i].cssText);

src/ResizeSensor.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
export declare type ResizeSensorCallback = (size: { width: number; height: number; }) => void;
22

33
export declare class ResizeSensor {
4+
/**
5+
* Creates a new resize sensor on given elements. The provided callback is called max 1 times per requestAnimationFrame and
6+
* is called initially.
7+
*/
48
constructor(element: Element | Element[], callback: ResizeSensorCallback);
9+
10+
/**
11+
* Removes the resize sensor, and stops listening to resize events.
12+
*/
513
detach(callback?: ResizeSensorCallback): void;
14+
15+
/**
16+
* Resets the resize sensors, so for the next element resize is correctly detected. This is rare cases necessary
17+
* when the resize sensor isn't initialised correctly or is in a broken state due to DOM modifications.
18+
*/
619
reset(): void;
720

21+
/**
22+
* Removes the resize sensor, and stops listening to resize events.
23+
*/
824
static detach(element: Element | Element[], callback?: ResizeSensorCallback): void;
25+
26+
/**
27+
* Resets the resize sensors, so for the next element resize is correctly detected. This is rare cases necessary
28+
* when the resize sensor isn't initialised correctly or is in a broken state due to DOM modifications.
29+
*/
930
static reset(element: Element | Element[]): void;
1031
}
1132

src/ResizeSensor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@
201201

202202
var dirty, rafId;
203203
var size = getElementSize(element);
204-
var lastWidth = size.width;
205-
var lastHeight = size.height;
204+
var lastWidth = 0;
205+
var lastHeight = 0;
206206
var initialHiddenCheck = true;
207207
var lastAnimationFrame = 0;
208208

0 commit comments

Comments
 (0)