Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeAll(() => {
// create DOM
const wrapper = document.createElement('div')
const content = document.createElement('div')
wrapper.appendChild(content)
// mock bscroll
bscroll = new BScroll(wrapper, {})
bscroll.maxScrollY = MAX_SCROLL_Y
bscroll.movingDirectionY = MOVING_DIRECTION_Y
})
beforeAll(() => {
// create Dom
const wrapper = document.createElement('div')
const content = document.createElement('div')
wrapper.appendChild(content)
// mock bscroll
options = {
scrollbar: CONFIG_SCROLL_BAR,
scrollX: true,
scrollY: true
}
bscroll = new BScroll(wrapper, options)
})
it("should make childScroll'options.click false when both BScroll' options.click are true", () => {
const parentScroll = new BScroll(parentWrapper, {
click: true
})
const childScroll = new BScroll(childWrapper, {
click: true
})
let nestedScroll1 = new NestedScroll(parentScroll)
let nestedScroll2 = new NestedScroll(childScroll)
expect(childScroll.options.click).toBe(false)
})
})
function createBScroll(
hooks: EventEmitter,
zoomOptions: {
start: number
min: number
max: number
}
) {
const mockscrollTo = jest.fn()
const { partOfbscroll, dom } = bscrollZoom(zoomOptions)
const bscroll = new BScroll(dom) as any
replaceBscrollProperties(bscroll, partOfbscroll)
bscroll.hooks = hooks
bscroll.scroller.hooks = hooks
bscroll.scroller.translater.hooks = hooks
bscroll.scroller.animater = {
hooks: hooks
}
bscroll.scroller.actions = {
hooks: hooks
}
bscroll.scroller.scrollTo = mockscrollTo
return {
bscroll,
mockscrollTo
}
}
function createBS() {
const dom = createDiv(300, 300)
const contentDom = createDiv(300, 300)
dom.appendChild(contentDom)
const bs = new BScroll(dom) as any
return bs
}
_initScroll() {
if (!this.$refs.wrapper) {
return
}
this.scroll = new BScroll(this.$refs.wrapper, {
probeType: this.event ? 2 : 0,
click: true,
scrollX: this.scrollX,
scrollY: !this.scrollX,
stopPropagation: this.stop
})
if (this.event) {
this.scroll.on('scroll', ({ y }) => {
const direction = this.scroll.movingDirectionY
this.$emit('scroll', {
offset: Math.max(-y, 0),
isUp: direction === -1
})
if (direction === -1) {
if (y > -50) {
this.$emit('pull-down')
initBscroll() {
this.bscroll = new BScroll(this.$refs.bsWrapper, {
scrollY: true,
bounceTime: TIME_BOUNCE,
pullDownRefresh: {
threshold: THRESHOLD,
stop: STOP
}
})
this.bscroll.on('pullingDown', this.pullingDownHandler)
this.bscroll.on('scroll', this.scrollHandler)
},
scrollHandler(pos) {
createInfinityScroll() {
this.scroll = new BScroll(this.$refs.chat, {
infinity: {
render: (item, div) => {
div = div || this.$refs.message.cloneNode(true)
div.dataset.id = item.id
div.querySelector('.infinity-avatar').src = require(`./image/avatar${item.avatar}.jpg`)
div.querySelector('.infinity-bubble p').textContent = item.id + ' ' + item.message
div.querySelector('.infinity-bubble .infinity-posted-date').textContent = item.time.toString()
let img = div.querySelector('.infinity-bubble img')
if (item.image !== '') {
img.style.display = ''
img.src = item.image.src
img.width = item.image.width
img.height = item.image.height
} else {
img.src = ''
initBscroll() {
this.bscroll = new BScroll(this.$refs.scroller, {
scrollY: true,
scrollbar: true
})
}
}
initScroll () {
let outerScroll = new BScroll(this.$refs.outerScroll, {
nestedScroll: true
})
let innerScroll = new BScroll(this.$refs.innerScroll, {
nestedScroll: true,
scrollX: true,
scrollY: false,
slide: {
loop: true,
threshold: 100
},
useTransition: true,
momentum: false,
bounce: false
})
}