Commit 3e0e91b8 by James Ooi

Defer auto start until DOM has loaded

parent 2129c69f
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
### Direct download ### Direct download
Download and install the latest distribution file from this 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 ```html
<script src="/path/to/foresight.min.js"></script> <script src="/path/to/foresight.min.js"></script>
......
...@@ -153,9 +153,11 @@ var Foresight = /** @class */ (function () { ...@@ -153,9 +153,11 @@ var Foresight = /** @class */ (function () {
}); });
}, this.options.observerOptions); }, this.options.observerOptions);
// Start tracking // Start tracking
if (!this.options.defer) { window.addEventListener('DOMContentLoaded', function () {
this.start(); if (!_this.options.defer) {
_this.start();
} }
});
} }
/** /**
* Start tracking all elements with tracking attributes for events. * Start tracking all elements with tracking attributes for events.
......
...@@ -97,9 +97,9 @@ class Foresight { ...@@ -97,9 +97,9 @@ class Foresight {
}, this.options.observerOptions); }, this.options.observerOptions);
// Start tracking // Start tracking
if (!this.options.defer) { window.addEventListener('DOMContentLoaded', () => {
this.start(); 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