| 198 | stateChange: (callback: Listener, isOne: boolean) => void; |
| 199 | |
| 200 | on(event: EventName, callback: Listener, isOne = false) { |
| 201 | // trigger the event if it applies to the element right now. |
| 202 | switch (true) { |
| 203 | case event === VISIBILITYCHANGE && !this.isInViewport && this.isAboveViewport: |
| 204 | case event === ENTERVIEWPORT && this.isInViewport: |
| 205 | case event === FULLYENTERVIEWPORT && this.isFullyInViewport: |
| 206 | case event === EXITVIEWPORT && this.isAboveViewport && !this.isInViewport: |
| 207 | case event === PARTIALLYEXITVIEWPORT && this.isInViewport && this.isAboveViewport: |
| 208 | callback.call(this, this); |
| 209 | if (isOne) { |
| 210 | return; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (this.callbacks[event]) { |
| 215 | this.callbacks[event].push({ callback, isOne }); |
| 216 | } else { |
| 217 | throw new Error( |
| 218 | 'Tried to add a scroll monitor listener of type ' + |
| 219 | event + |
| 220 | '. Your options are: ' + |
| 221 | eventTypes.join(', ') |
| 222 | ); |
| 223 | } |
| 224 | } |
| 225 | off(event: EventName, callback: Listener) { |
| 226 | if (this.callbacks[event]) { |
| 227 | for (var i = 0, item; (item = this.callbacks[event][i]); i++) { |