diff options
author | wout <wout@impinc.co.uk> | 2013-04-22 09:57:25 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-04-22 09:57:25 +0100 |
commit | 11ded2fe8fabf4392633fcdb3713a49e084746a1 (patch) | |
tree | 16c325b6261d8159bade92faf6b763acbccad148 /src/doc.js | |
parent | a736acc12e4ca1a71b9f563f7ed361e2a3540469 (diff) | |
download | svg.js-11ded2fe8fabf4392633fcdb3713a49e084746a1.tar.gz svg.js-11ded2fe8fabf4392633fcdb3713a49e084746a1.zip |
Added the rbox() method, bumped to v0.140.15
Diffstat (limited to 'src/doc.js')
-rw-r--r-- | src/doc.js | 97 |
1 files changed, 61 insertions, 36 deletions
@@ -7,16 +7,18 @@ SVG.Doc = function(element) { document.getElementById(element) : element - /* set svg element attributes and create the <defs> node */ + /* If the target is an svg element, use that element as the main wrapper. + This allows svg.js to work with svg documents as well. */ this.constructor .call(this, this.parent.nodeName == 'svg' ? this.parent : SVG.create('svg')) + /* 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 */ + /* ensure correct rendering */ if (this.parent.nodeName != 'svg') this.stage() } @@ -24,41 +26,64 @@ SVG.Doc = function(element) { // 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) + +SVG.extend(SVG.Doc, { + // 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. + // It also handles sub-pixel offset rendering properly. + stage: function() { + var check + , element = this + , wrapper = document.createElement('div') + + /* set temporary 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 temporary wrapper */ + element.parent.removeChild(element.node.parentNode) + element.node.parentNode.removeChild(element.node) + element.parent.appendChild(element.node) + + /* after wrapping is done, fix sub-pixel offset */ + element.fixSubPixelOffset() + + /* make sure sub-pixel offset is fixed every time the window is resized */ + SVG.on(window, 'resize', function() { + element.fixSubPixelOffset() + }) + + }, 5) + } else { + setTimeout(check, 10) + } } + + check() + + return this } + + // Fix for possible sub-pixel offset. See: + // https://bugzilla.mozilla.org/show_bug.cgi?id=608812 +, fixSubPixelOffset: function() { + var pos = this.node.getScreenCTM() - check() + this + .style('left', (-pos.e % 1) + 'px') + .style('top', (-pos.f % 1) + 'px') + } - return this -}
\ No newline at end of file +}) |