2bf710491a97dd71fb6298ad532629a069810a56780d100aa3f832725ef2ec214700a85c502cf84f176d39b9f8f08eb13cbb486cacfe1aaaee864df0878bed 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* @flow */
  2. import { namespaceMap } from 'web/util/index'
  3. export function createElement (tagName: string, vnode: VNode): Element {
  4. const elm = document.createElement(tagName)
  5. if (tagName !== 'select') {
  6. return elm
  7. }
  8. // false or null will remove the attribute but undefined will not
  9. if (vnode.data && vnode.data.attrs && vnode.data.attrs.multiple !== undefined) {
  10. elm.setAttribute('multiple', 'multiple')
  11. }
  12. return elm
  13. }
  14. export function createElementNS (namespace: string, tagName: string): Element {
  15. return document.createElementNS(namespaceMap[namespace], tagName)
  16. }
  17. export function createTextNode (text: string): Text {
  18. return document.createTextNode(text)
  19. }
  20. export function createComment (text: string): Comment {
  21. return document.createComment(text)
  22. }
  23. export function insertBefore (parentNode: Node, newNode: Node, referenceNode: Node) {
  24. parentNode.insertBefore(newNode, referenceNode)
  25. }
  26. export function removeChild (node: Node, child: Node) {
  27. node.removeChild(child)
  28. }
  29. export function appendChild (node: Node, child: Node) {
  30. node.appendChild(child)
  31. }
  32. export function parentNode (node: Node): ?Node {
  33. return node.parentNode
  34. }
  35. export function nextSibling (node: Node): ?Node {
  36. return node.nextSibling
  37. }
  38. export function tagName (node: Element): string {
  39. return node.tagName
  40. }
  41. export function setTextContent (node: Node, text: string) {
  42. node.textContent = text
  43. }
  44. export function setStyleScope (node: Element, scopeId: string) {
  45. node.setAttribute(scopeId, '')
  46. }