aboutsummaryrefslogtreecommitdiffstats
path: root/src/doc.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
committerwout <wout@impinc.co.uk>2014-02-03 15:14:47 +0100
commite2304534e0cfb6f6f4ab8c37ea5275ae26cd455a (patch)
tree2386e9f361d9c5fa1308387aeeaf33f00241b3c5 /src/doc.js
parent7a29817ffd764cf7ab6906250b57f234801c94e0 (diff)
downloadsvg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.tar.gz
svg.js-e2304534e0cfb6f6f4ab8c37ea5275ae26cd455a.zip
Implemented SVG.invent function and bumped to v1.0rc3
Diffstat (limited to 'src/doc.js')
-rwxr-xr-xsrc/doc.js184
1 files changed, 92 insertions, 92 deletions
diff --git a/src/doc.js b/src/doc.js
index 7e9eef3..5129dd9 100755
--- a/src/doc.js
+++ b/src/doc.js
@@ -1,112 +1,112 @@
-// ### This module accounts for the main svg document
-
-//
-SVG.Doc = function(element) {
- /* ensure the presence of a html element */
- this.parent = typeof element == 'string' ?
- document.getElementById(element) :
- element
-
- /* 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 */
- this
- .attr({ xmlns: SVG.ns, version: '1.1', width: '100%', height: '100%' })
- .attr('xmlns:xlink', SVG.xlink, SVG.xmlns)
-
- /* create the <defs> node */
- this._defs = new SVG.Defs
- this._defs.parent = this
- this.node.appendChild(this._defs.node)
+SVG.Doc = SVG.invent({
+ // Initialize node
+ create: function(element) {
+ /* ensure the presence of a html element */
+ this.parent = typeof element == 'string' ?
+ document.getElementById(element) :
+ element
+
+ /* 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 */
+ this
+ .attr({ xmlns: SVG.ns, version: '1.1', width: '100%', height: '100%' })
+ .attr('xmlns:xlink', SVG.xlink, SVG.xmlns)
+
+ /* create the <defs> node */
+ this._defs = new SVG.Defs
+ this._defs.parent = this
+ this.node.appendChild(this._defs.node)
- /* turno of sub pixel offset by default */
- this.doSubPixelOffsetFix = false
-
- /* ensure correct rendering */
- if (this.parent.nodeName != 'svg')
- this.stage()
-}
+ /* turno of sub pixel offset by default */
+ this.doSubPixelOffsetFix = false
+
+ /* ensure correct rendering */
+ if (this.parent.nodeName != 'svg')
+ this.stage()
+ }
-// Inherits from SVG.Container
-SVG.Doc.prototype = new SVG.Container
+ // Inherit from
+, inherit: SVG.Container
-//
-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')
+ // Add class methods
+, extend: {
+ // 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%;'
+ /* 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)
+ /* 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;overflow:hidden;')
+ /* 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;overflow:hidden;')
- /* remove temporary wrapper */
- element.parent.removeChild(element.node.parentNode)
- element.node.parentNode.removeChild(element.node)
- element.parent.appendChild(element.node)
+ /* 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.subPixelOffsetFix()
-
- /* make sure sub-pixel offset is fixed every time the window is resized */
- SVG.on(window, 'resize', function() {
+ /* after wrapping is done, fix sub-pixel offset */
element.subPixelOffsetFix()
- })
-
- }, 5)
- } else {
- setTimeout(check, 10)
+
+ /* make sure sub-pixel offset is fixed every time the window is resized */
+ SVG.on(window, 'resize', function() {
+ element.subPixelOffsetFix()
+ })
+
+ }, 5)
+ } else {
+ setTimeout(check, 10)
+ }
}
- }
- check()
+ check()
- return this
- }
+ return this
+ }
- // Creates and returns defs element
-, defs: function() {
- return this._defs
- }
+ // Creates and returns defs element
+ , defs: function() {
+ return this._defs
+ }
- // Fix for possible sub-pixel offset. See:
- // https://bugzilla.mozilla.org/show_bug.cgi?id=608812
-, subPixelOffsetFix: function() {
- if (this.doSubPixelOffsetFix) {
- var pos = this.node.getScreenCTM()
+ // Fix for possible sub-pixel offset. See:
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=608812
+ , subPixelOffsetFix: function() {
+ if (this.doSubPixelOffsetFix) {
+ var pos = this.node.getScreenCTM()
+
+ if (pos)
+ this
+ .style('left', (-pos.e % 1) + 'px')
+ .style('top', (-pos.f % 1) + 'px')
+ }
- if (pos)
- this
- .style('left', (-pos.e % 1) + 'px')
- .style('top', (-pos.f % 1) + 'px')
+ return this
}
-
- return this
- }
-, fixSubPixelOffset: function() {
- this.doSubPixelOffsetFix = true
+ , fixSubPixelOffset: function() {
+ this.doSubPixelOffsetFix = true
- return this
+ return this
+ }
}
-}) \ No newline at end of file
+})