* Measures the scroll offset relative to the specified edge of the viewport. This method can be * used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent * about what scrollLeft means in RTL. The values returned by this method are normalized such that *
(from: 'top' | 'left' | 'right' | 'bottom' | 'start' | 'end')
| 151 | * @param from The edge to measure from. |
| 152 | */ |
| 153 | measureScrollOffset(from: 'top' | 'left' | 'right' | 'bottom' | 'start' | 'end'): number { |
| 154 | const LEFT = 'left'; |
| 155 | const RIGHT = 'right'; |
| 156 | const el = this.elementRef.nativeElement; |
| 157 | if (from == 'top') { |
| 158 | return el.scrollTop; |
| 159 | } |
| 160 | if (from == 'bottom') { |
| 161 | return el.scrollHeight - el.clientHeight - el.scrollTop; |
| 162 | } |
| 163 | |
| 164 | // Rewrite start & end as left or right offsets. |
| 165 | const isRtl = this.dir && this.dir.value == 'rtl'; |
| 166 | if (from == 'start') { |
| 167 | from = isRtl ? RIGHT : LEFT; |
| 168 | } else if (from == 'end') { |
| 169 | from = isRtl ? LEFT : RIGHT; |
| 170 | } |
| 171 | |
| 172 | if (isRtl && getRtlScrollAxisType() == RtlScrollAxisType.INVERTED) { |
| 173 | // For INVERTED, scrollLeft is (scrollWidth - clientWidth) when scrolled all the way left and |
| 174 | // 0 when scrolled all the way right. |
| 175 | if (from == LEFT) { |
| 176 | return el.scrollWidth - el.clientWidth - el.scrollLeft; |
| 177 | } else { |
| 178 | return el.scrollLeft; |
| 179 | } |
| 180 | } else if (isRtl && getRtlScrollAxisType() == RtlScrollAxisType.NEGATED) { |
| 181 | // For NEGATED, scrollLeft is -(scrollWidth - clientWidth) when scrolled all the way left and |
| 182 | // 0 when scrolled all the way right. |
| 183 | if (from == LEFT) { |
| 184 | return el.scrollLeft + el.scrollWidth - el.clientWidth; |
| 185 | } else { |
| 186 | return -el.scrollLeft; |
| 187 | } |
| 188 | } else { |
| 189 | // For NORMAL, as well as non-RTL contexts, scrollLeft is 0 when scrolled all the way left and |
| 190 | // (scrollWidth - clientWidth) when scrolled all the way right. |
| 191 | if (from == LEFT) { |
| 192 | return el.scrollLeft; |
| 193 | } else { |
| 194 | return el.scrollWidth - el.clientWidth - el.scrollLeft; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
no test coverage detected