()
| 196 | } |
| 197 | |
| 198 | private fixPosition(): void { |
| 199 | const $container = this.$container; |
| 200 | const containerParent = $container.parent().get(0); |
| 201 | |
| 202 | if (containerParent !== document.body && !this.options.forceFixPosition) { |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | let orientation = this.options.orientation; |
| 207 | const containerHeight = $container.outerHeight() ?? 0; |
| 208 | const height = this.el.outerHeight() ?? 0; |
| 209 | const offset = this.el.offset() ?? { top: 0, left: 0 }; |
| 210 | const styles: { top: number; left: number; width?: string } = { |
| 211 | top: offset.top, |
| 212 | left: offset.left, |
| 213 | }; |
| 214 | |
| 215 | if (orientation === "auto") { |
| 216 | const viewPortHeight = $(window).height() ?? 0; |
| 217 | const scrollTop = $(window).scrollTop() ?? 0; |
| 218 | const topOverflow = -scrollTop + offset.top - containerHeight; |
| 219 | const bottomOverflow = |
| 220 | scrollTop + viewPortHeight - (offset.top + height + containerHeight); |
| 221 | |
| 222 | orientation = Math.max(topOverflow, bottomOverflow) === topOverflow ? "top" : "bottom"; |
| 223 | } |
| 224 | |
| 225 | styles.top += orientation === "top" ? -containerHeight : height; |
| 226 | |
| 227 | if (containerParent !== document.body && containerParent !== undefined) { |
| 228 | const opacity = $container.css("opacity"); |
| 229 | |
| 230 | if (!this.visible) { |
| 231 | $container.css("opacity", 0).show(); |
| 232 | } |
| 233 | |
| 234 | const parentOffsetDiff = $container.offsetParent().offset() ?? { top: 0, left: 0 }; |
| 235 | styles.top -= parentOffsetDiff.top; |
| 236 | styles.top += containerParent.scrollTop; |
| 237 | styles.left -= parentOffsetDiff.left; |
| 238 | |
| 239 | if (!this.visible) { |
| 240 | $container.css("opacity", opacity).hide(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (this.options.width === "auto") { |
| 245 | styles.width = `${this.el.outerWidth() ?? 0}px`; |
| 246 | } |
| 247 | |
| 248 | $container.css(styles); |
| 249 | } |
| 250 | |
| 251 | private isCursorAtEnd(): boolean { |
| 252 | const valLength = (this.el.val() as string).length; |
no test coverage detected