Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { debounce } from '@pluginjs/utils'
import Pj from '@pluginjs/factory'
/* Credit to http://naver.github.io/egjs/ MIT */
let isRotate = false
const latency = 250
const emitter = Pj.emitter
const scroll = debounce(() => {
if (isRotate) {
isRotate = false
return
}
emitter.emit('scrollend', {
top: window.pageYOffset,
left: window.pageXOffset
})
}, latency)
const onOrientationchange = () => {
isRotate = true
}
e => {
this.click(e)
},
$doc
)
if (this.is('popper')) {
this.POPPER.enableEventListeners()
this.POPPER.scheduleUpdate()
} else {
this.mobilePosition()
}
// this.position();
this.enter('showed')
Pj.emitter.on(this.eventNameWithId('resize'), () => {
// self.position();
if (this.is('popper')) {
this.POPPER.enableEventListeners()
} else {
this.mobilePosition()
}
})
// this.$element.focus();
bindEvent(
this.eventName('mousedown'),
e => {
this.prevent(e)
},
this.$picker
)
}
it('should return array when excute instance method on elements', () => {
const $parent = parseHTML(
'<div><div class="element"></div><div class="element"></div></div>'
)
const elements = queryAll('.element', $parent)
Pj.sample(elements)
expect(Pj.sample(elements, 'get')).toEqual([null, null])
Pj.sample(elements, 'set', 'hello world')
expect(Pj.sample(elements, 'get')).toEqual(['hello world', 'hello world'])
})
})
it('should return array when excute instance method on elements', () => {
const $parent = parseHTML(
'<div><div class="element"></div><div class="element"></div></div>'
)
const elements = queryAll('.element', $parent)
Pj.sample(elements)
expect(Pj.sample(elements, 'get')).toEqual([null, null])
Pj.sample(elements, 'set', 'hello world')
expect(Pj.sample(elements, 'get')).toEqual(['hello world', 'hello world'])
})
})
it('should access instance method with factory', () => {
const el = document.createElement('div')
Sample.of(el)
Pj.sample(el, 'set', 'hello world')
expect(Pj.sample(el, 'get')).toBe('hello world')
})
test('Pj.plugin constructor', () => {
const el = document.createElement('div')
el.classList.add('sample')
document.body.appendChild(el)
const api = Pj.sample('.sample')
expect(Sample.getInstances()).toHaveLength(1)
expect(api.element).toBe(el)
})
it('should return array when excute instance method on elements', () => {
const $parent = parseHTML(
'<div><div class="element"></div><div class="element"></div></div>'
)
const elements = queryAll('.element', $parent)
Pj.sample(elements)
expect(Pj.sample(elements, 'get')).toEqual([null, null])
Pj.sample(elements, 'set', 'hello world')
expect(Pj.sample(elements, 'get')).toEqual(['hello world', 'hello world'])
})
})
it('should access instance method with factory', () => {
const el = document.createElement('div')
Sample.of(el)
Pj.sample(el, 'set', 'hello world')
expect(Pj.sample(el, 'get')).toBe('hello world')
})
it('should register to Pj', () => {
expect(Pj.has(plugin)).toBeTrue()
})
function accessPrivate() {
Pj.sample(el, 'private')
}