summaryrefslogtreecommitdiffstats
path: root/src/spof.js
blob: cf4fe2f6be8788900a43a0a018d135a5bfe40b2b (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
// Fix for possible sub-pixel offset. See:
// https://bugzilla.mozilla.org/show_bug.cgi?id=608812
SVG.extend(SVG.Doc, {
  // Callback
  spof: function() {
    if (this.doSpof) {
      var pos = this.node.getScreenCTM()
      
      if (pos)
        this
          .style('left', (-pos.e % 1) + 'px')
          .style('top',  (-pos.f % 1) + 'px')
    }
    
    return this
  }

  // Sub-pixel offset enabler
, fixSubPixelOffset: function() {
    var self = this

    // Enable spof
    this.doSpof = true

    // Make sure sub-pixel offset is fixed every time the window is resized
    SVG.on(window, 'resize', function() { self.spof() })

    return this.spof()
  }
  
})