Commit 3e0e91b8 by James Ooi

Defer auto start until DOM has loaded

parent 2129c69f
......@@ -9,7 +9,7 @@
### Direct download
Download and install the latest distribution file from this
Git repository and load it in your webpage. For production cases, we encourage you to download the minified version ([`foresight.min.js`](blob/master/dist/foresight.min.js))
Git repository and load it in your webpage. For production cases, we encourage you to download the minified version ([`foresight.min.js`](dist/foresight.min.js))
```html
<script src="/path/to/foresight.min.js"></script>
......
......@@ -153,9 +153,11 @@ var Foresight = /** @class */ (function () {
});
}, this.options.observerOptions);
// Start tracking
if (!this.options.defer) {
this.start();
window.addEventListener('DOMContentLoaded', function () {
if (!_this.options.defer) {
_this.start();
}
});
}
/**
* Start tracking all elements with tracking attributes for events.
......
......@@ -97,9 +97,9 @@ class Foresight {
}, this.options.observerOptions);
// Start tracking
if (!this.options.defer) {
this.start();
}
window.addEventListener('DOMContentLoaded', () => {
if (!this.options.defer) { this.start(); }
});
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment