show.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* @flow */
  2. import { isIE9 } from 'web/util/index'
  3. import { enter, leave } from '../modules/transition'
  4. // recursively search for possible transition defined inside the component root
  5. function locateNode (vnode: VNode): VNodeWithData {
  6. return vnode.child && (!vnode.data || !vnode.data.transition)
  7. ? locateNode(vnode.child._vnode)
  8. : vnode
  9. }
  10. export default {
  11. bind (el: HTMLElement, { value }: VNodeDirective, vnode: VNodeWithData) {
  12. vnode = locateNode(vnode)
  13. const transition = vnode.data && vnode.data.transition
  14. if (value && transition && transition.appear && !isIE9) {
  15. enter(vnode)
  16. }
  17. el.style.display = value ? '' : 'none'
  18. },
  19. update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) {
  20. /* istanbul ignore if */
  21. if (value === oldValue) return
  22. vnode = locateNode(vnode)
  23. const transition = vnode.data && vnode.data.transition
  24. if (transition && !isIE9) {
  25. if (value) {
  26. enter(vnode)
  27. el.style.display = ''
  28. } else {
  29. leave(vnode, () => {
  30. el.style.display = 'none'
  31. })
  32. }
  33. } else {
  34. el.style.display = value ? '' : 'none'
  35. }
  36. }
  37. }