(item: HTMLElement, parentWatcher?: ScrollMonitorContainer)
| 82 | eventTypes = eventTypes; |
| 83 | |
| 84 | constructor(item: HTMLElement, parentWatcher?: ScrollMonitorContainer) { |
| 85 | var self = this; |
| 86 | |
| 87 | this.item = item; |
| 88 | this.watchers = []; |
| 89 | this.viewportTop = null; |
| 90 | this.viewportBottom = null; |
| 91 | this.documentHeight = getContentHeight(item); |
| 92 | this.viewportHeight = getViewportHeight(item); |
| 93 | this.DOMListener = function () { |
| 94 | ScrollMonitorContainer.prototype.DOMListener.apply(self, arguments); |
| 95 | }; |
| 96 | |
| 97 | if (parentWatcher) { |
| 98 | this.containerWatcher = parentWatcher.create(item); |
| 99 | } |
| 100 | |
| 101 | var previousDocumentHeight: number; |
| 102 | |
| 103 | var calculateViewportI; |
| 104 | function calculateViewport() { |
| 105 | self.viewportTop = scrollTop(item); |
| 106 | self.viewportBottom = self.viewportTop + self.viewportHeight; |
| 107 | self.documentHeight = getContentHeight(item); |
| 108 | if (self.documentHeight !== previousDocumentHeight) { |
| 109 | calculateViewportI = self.watchers.length; |
| 110 | while (calculateViewportI--) { |
| 111 | self.watchers[calculateViewportI].recalculateLocation(); |
| 112 | } |
| 113 | previousDocumentHeight = self.documentHeight; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | var updateAndTriggerWatchersI; |
| 118 | function updateAndTriggerWatchers() { |
| 119 | // update all watchers then trigger the events so one can rely on another being up to date. |
| 120 | updateAndTriggerWatchersI = self.watchers.length; |
| 121 | while (updateAndTriggerWatchersI--) { |
| 122 | self.watchers[updateAndTriggerWatchersI].update(); |
| 123 | } |
| 124 | |
| 125 | updateAndTriggerWatchersI = self.watchers.length; |
| 126 | while (updateAndTriggerWatchersI--) { |
| 127 | self.watchers[updateAndTriggerWatchersI].triggerCallbacks(undefined); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | this.update = function () { |
| 132 | calculateViewport(); |
| 133 | updateAndTriggerWatchers(); |
| 134 | }; |
| 135 | this.recalculateLocations = function () { |
| 136 | this.documentHeight = 0; |
| 137 | this.update(); |
| 138 | }; |
| 139 | } |
| 140 | |
| 141 | listenToDOM() { |
nothing calls this directly
no test coverage detected