aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Bare.js
blob: 190aa1fd92fde7a5bd39b7c7b66997799eff4eed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
import { registerMethods } from '../utils/methods.js'
import Container from './Container.js'
import { globals } from '../utils/window.js'

export default class Bare extends Container {

  constructor ( node, attrs ) {

    super( nodeOrNew( node, typeof node === 'string' ? null : node ), attrs )

  }

  words ( text ) {

    // remove contents
    while ( this.node.hasChildNodes() ) {

      this.node.removeChild( this.node.lastChild )

    }

    // create text node
    this.node.appendChild( globals.document.createTextNode( text ) )

    return this

  }

}

register( Bare )

registerMethods( 'Container', {
  // Create an element that is not described by SVG.js
  element: wrapWithAttrCheck( function ( node ) {

    return this.put( new Bare( node ) )

  } )
} )