intersection-observer 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  * Licensed under the W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE.
5
5
  *
6
6
  * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
7
- *
7
+ *
8
8
  */
9
9
 
10
10
  (function(window, document) {
@@ -124,6 +124,12 @@ IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
124
124
  */
125
125
  IntersectionObserver.prototype.POLL_INTERVAL = null;
126
126
 
127
+ /**
128
+ * Use a mutation observer on the root element
129
+ * to detect intersection changes.
130
+ */
131
+ IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
132
+
127
133
 
128
134
  /**
129
135
  * Starts observing a target element for intersection changes based on
@@ -131,10 +137,11 @@ IntersectionObserver.prototype.POLL_INTERVAL = null;
131
137
  * @param {Element} target The DOM element to observe.
132
138
  */
133
139
  IntersectionObserver.prototype.observe = function(target) {
134
- // If the target is already being observed, do nothing.
135
- if (this._observationTargets.some(function(item) {
140
+ var isTargetAlreadyObserved = this._observationTargets.some(function(item) {
136
141
  return item.element == target;
137
- })) {
142
+ });
143
+
144
+ if (isTargetAlreadyObserved) {
138
145
  return;
139
146
  }
140
147
 
@@ -260,7 +267,7 @@ IntersectionObserver.prototype._monitorIntersections = function() {
260
267
  addEvent(window, 'resize', this._checkForIntersections, true);
261
268
  addEvent(document, 'scroll', this._checkForIntersections, true);
262
269
 
263
- if ('MutationObserver' in window) {
270
+ if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
264
271
  this._domObserver = new MutationObserver(this._checkForIntersections);
265
272
  this._domObserver.observe(document, {
266
273
  attributes: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intersection-observer",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "A polyfill for IntersectionObserver",
5
5
  "main": "intersection-observer",
6
6
  "repository": {