summaryrefslogtreecommitdiffstats
path: root/src/doc.js
blob: 2e2fd0af4e02e727261dd57c5b8a3dab2da88ead (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ### This module accounts for the main svg document

//
SVG.Doc = function(element) {
  this.constructor.call(this, SVG.create('svg'))
  
  /* ensure the presence of a html element */
  this.parent = typeof element == 'string' ?
    document.getElementById(element) :
    element
  
  /* set svg element attributes and create the <defs> node */
  this
    .attr({ xmlns: SVG.ns, version: '1.1', width: '100%', height: '100%' })
    .attr('xlink', SVG.xlink, SVG.ns)
    .defs()
  
  /* ensure correct rendering for safari */
  this.stage()
}

// Inherits from SVG.Container
SVG.Doc.prototype = new SVG.Container

// Hack for safari preventing text to be rendered in one line.
// Basically it sets the position of the svg node to absolute
// when the dom is loaded, and resets it to relative a few milliseconds later.
SVG.Doc.prototype.stage = function() {
  var check
    , element = this
    , wrapper = document.createElement('div')
  
  /* set temp wrapper to position relative */
  wrapper.style.cssText = 'position:relative;height:100%;'
  
  /* put element into wrapper */
  element.parent.appendChild(wrapper)
  wrapper.appendChild(element.node)
  
  /* check for dom:ready */
  check = function() {
    if (document.readyState === 'complete') {
      element.style('position:absolute;')
      setTimeout(function() {
        /* set position back to relative */
        element.style('position:relative;')
        
        /* remove temp wrapper */
        element.parent.removeChild(element.node.parentNode)
        element.node.parentNode.removeChild(element.node)
        element.parent.appendChild(element.node)
        
      }, 5)
    } else {
      setTimeout(check, 10)
    }
  }
  
  check()
  
  return this
}