|
|
@ -1,4 +1,4 @@ |
|
|
|
import * as doms from '../shared/utils/dom'; |
|
|
|
import * as doms from '../../shared/utils/dom'; |
|
|
|
|
|
|
|
|
|
|
|
const SCROLL_DELTA_X = 64; |
|
|
|
const SCROLL_DELTA_X = 64; |
|
|
|
const SCROLL_DELTA_Y = 64; |
|
|
|
const SCROLL_DELTA_Y = 64; |
|
|
@ -94,30 +94,47 @@ class Scroller { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const getScroll = () => { |
|
|
|
type Point = { x: number, y: number }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default interface ScrollPresenter { |
|
|
|
|
|
|
|
getScroll(): Point; |
|
|
|
|
|
|
|
scrollVertically(amount: number, smooth: boolean): void; |
|
|
|
|
|
|
|
scrollHorizonally(amount: number, smooth: boolean): void; |
|
|
|
|
|
|
|
scrollPages(amount: number, smooth: boolean): void; |
|
|
|
|
|
|
|
scrollTo(x: number, y: number, smooth: boolean): void; |
|
|
|
|
|
|
|
scrollToTop(smooth: boolean): void; |
|
|
|
|
|
|
|
scrollToBottom(smooth: boolean): void; |
|
|
|
|
|
|
|
scrollToHome(smooth: boolean): void; |
|
|
|
|
|
|
|
scrollToEnd(smooth: boolean): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line semi
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class ScrollPresenterImpl { |
|
|
|
|
|
|
|
getScroll(): Point { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
return { x: target.scrollLeft, y: target.scrollTop }; |
|
|
|
return { x: target.scrollLeft, y: target.scrollTop }; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollVertically = (count: number, smooth: boolean): void => { |
|
|
|
scrollVertically(count: number, smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let delta = SCROLL_DELTA_Y * count; |
|
|
|
let delta = SCROLL_DELTA_Y * count; |
|
|
|
if (scrolling) { |
|
|
|
if (scrolling) { |
|
|
|
delta = SCROLL_DELTA_Y * count * 4; |
|
|
|
delta = SCROLL_DELTA_Y * count * 4; |
|
|
|
} |
|
|
|
} |
|
|
|
new Scroller(target, smooth).scrollBy(0, delta); |
|
|
|
new Scroller(target, smooth).scrollBy(0, delta); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollHorizonally = (count: number, smooth: boolean): void => { |
|
|
|
scrollHorizonally(count: number, smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let delta = SCROLL_DELTA_X * count; |
|
|
|
let delta = SCROLL_DELTA_X * count; |
|
|
|
if (scrolling) { |
|
|
|
if (scrolling) { |
|
|
|
delta = SCROLL_DELTA_X * count * 4; |
|
|
|
delta = SCROLL_DELTA_X * count * 4; |
|
|
|
} |
|
|
|
} |
|
|
|
new Scroller(target, smooth).scrollBy(delta, 0); |
|
|
|
new Scroller(target, smooth).scrollBy(delta, 0); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollPages = (count: number, smooth: boolean): void => { |
|
|
|
scrollPages(count: number, smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let height = target.clientHeight; |
|
|
|
let height = target.clientHeight; |
|
|
|
let delta = height * count; |
|
|
|
let delta = height * count; |
|
|
@ -125,44 +142,38 @@ const scrollPages = (count: number, smooth: boolean): void => { |
|
|
|
delta = height * count; |
|
|
|
delta = height * count; |
|
|
|
} |
|
|
|
} |
|
|
|
new Scroller(target, smooth).scrollBy(0, delta); |
|
|
|
new Scroller(target, smooth).scrollBy(0, delta); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollTo = (x: number, y: number, smooth: boolean): void => { |
|
|
|
scrollTo(x: number, y: number, smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollToTop = (smooth: boolean): void => { |
|
|
|
scrollToTop(smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let x = target.scrollLeft; |
|
|
|
let x = target.scrollLeft; |
|
|
|
let y = 0; |
|
|
|
let y = 0; |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollToBottom = (smooth: boolean): void => { |
|
|
|
scrollToBottom(smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let x = target.scrollLeft; |
|
|
|
let x = target.scrollLeft; |
|
|
|
let y = target.scrollHeight; |
|
|
|
let y = target.scrollHeight; |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollToHome = (smooth: boolean): void => { |
|
|
|
scrollToHome(smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let x = 0; |
|
|
|
let x = 0; |
|
|
|
let y = target.scrollTop; |
|
|
|
let y = target.scrollTop; |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const scrollToEnd = (smooth: boolean): void => { |
|
|
|
scrollToEnd(smooth: boolean): void { |
|
|
|
let target = scrollTarget(); |
|
|
|
let target = scrollTarget(); |
|
|
|
let x = target.scrollWidth; |
|
|
|
let x = target.scrollWidth; |
|
|
|
let y = target.scrollTop; |
|
|
|
let y = target.scrollTop; |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
new Scroller(target, smooth).scrollTo(x, y); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
export { |
|
|
|
|
|
|
|
getScroll, |
|
|
|
|
|
|
|
scrollVertically, scrollHorizonally, scrollPages, |
|
|
|
|
|
|
|
scrollTo, |
|
|
|
|
|
|
|
scrollToTop, scrollToBottom, scrollToHome, scrollToEnd |
|
|
|
|
|
|
|
}; |
|
|
|
|