diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bare.js | 45 | ||||
-rwxr-xr-x | src/element.js | 8 | ||||
-rwxr-xr-x | src/relative.js | 16 | ||||
-rwxr-xr-x | src/sugar.js | 12 | ||||
-rw-r--r-- | src/symbol.js | 17 | ||||
-rwxr-xr-x | src/text.js | 54 | ||||
-rw-r--r-- | src/transporter.js | 33 |
7 files changed, 88 insertions, 97 deletions
diff --git a/src/bare.js b/src/bare.js new file mode 100644 index 0000000..a0b1ee3 --- /dev/null +++ b/src/bare.js @@ -0,0 +1,45 @@ + +SVG.Bare = SVG.invent({ + // Initialize + create: function(element, inherit) { + // construct element + this.constructor.call(this, SVG.create(element)) + + // inherit custom methods + if (inherit) + for (var method in inherit.prototype) + if (typeof inherit.prototype[method] === 'function') + element[method] = inherit.prototype[method] + } + + // Inherit from +, inherit: SVG.Element + + // Add methods +, extend: { + // Insert some plain text + words: function(text) { + // remove contents + while (this.node.hasChildNodes()) + this.node.removeChild(this.node.lastChild) + + // create text node + this.node.appendChild(document.createTextNode(text)) + + return this + } + } +}) + + +SVG.extend(SVG.Parent, { + // Create an element that is not described by SVG.js + element: function(element, inherit) { + return this.put(new SVG.Bare(element, inherit)) + } + // Add symbol element +, symbol: function() { + return this.defs().element('symbol', SVG.Container) + } + +})
\ No newline at end of file diff --git a/src/element.js b/src/element.js index b319e00..8db2359 100755 --- a/src/element.js +++ b/src/element.js @@ -2,15 +2,15 @@ SVG.Element = SVG.invent({ // Initialize node create: function(node) { - // Make stroke value accessible dynamically + // make stroke value accessible dynamically this._stroke = SVG.defaults.attrs.stroke - // Create circular reference + // create circular reference if (this.node = node) { this.type = node.nodeName this.node.instance = this - // Store current attribute value + // store current attribute value this._stroke = node.getAttribute('stroke') || this._stroke } } @@ -185,7 +185,7 @@ SVG.Element = SVG.invent({ // act as a setter if svg is given if (svg && this instanceof SVG.Parent) { // dump raw svg - well.innerHTML = '<svg>' + svg + '</svg>' + well.innerHTML = '<svg>' + svg.replace(/\n/, '').replace(/<(\w+)([^<]+?)\/>/g, '<$1$2></$1>') + '</svg>' // transplant nodes for (var i = 0, il = well.firstChild.childNodes.length; i < il; i++) diff --git a/src/relative.js b/src/relative.js deleted file mode 100755 index 6bb11b7..0000000 --- a/src/relative.js +++ /dev/null @@ -1,16 +0,0 @@ -// -SVG.extend(SVG.Element, SVG.FX, { - // Relative move over x axis - dx: function(x) { - return this.x((this.target || this).x() + x) - } - // Relative move over y axis -, dy: function(y) { - return this.y((this.target || this).y() + y) - } - // Relative move over x and y axes -, dmove: function(x, y) { - return this.dx(x).dy(y) - } - -})
\ No newline at end of file diff --git a/src/sugar.js b/src/sugar.js index cc01c00..4b7b232 100755 --- a/src/sugar.js +++ b/src/sugar.js @@ -59,6 +59,18 @@ SVG.extend(SVG.Element, SVG.FX, { , opacity: function(value) { return this.attr('opacity', value) } + // Relative move over x axis +, dx: function(x) { + return this.x((this.target || this).x() + x) + } + // Relative move over y axis +, dy: function(y) { + return this.y((this.target || this).y() + y) + } + // Relative move over x and y axes +, dmove: function(x, y) { + return this.dx(x).dy(y) + } }) SVG.extend(SVG.Rect, SVG.Ellipse, SVG.Circle, SVG.Gradient, SVG.FX, { diff --git a/src/symbol.js b/src/symbol.js deleted file mode 100644 index e8907a3..0000000 --- a/src/symbol.js +++ /dev/null @@ -1,17 +0,0 @@ - -SVG.Symbol = SVG.invent({ - // Initialize node - create: 'symbol' - - // Inherit from -, inherit: SVG.Container - - // Add parent method -, construct: { - // Create a new symbol - symbol: function() { - return this.defs().put(new SVG.Symbol) - } - } - -})
\ No newline at end of file diff --git a/src/text.js b/src/text.js index d1aeda4..7970492 100755 --- a/src/text.js +++ b/src/text.js @@ -3,11 +3,11 @@ SVG.Text = SVG.invent({ create: function() { this.constructor.call(this, SVG.create('text')) - this._leading = new SVG.Number(1.3) /* store leading value for rebuilding */ - this._rebuild = true /* enable automatic updating of dy values */ - this._build = false /* disable build mode for adding multiple lines */ + this._leading = new SVG.Number(1.3) // store leading value for rebuilding + this._rebuild = true // enable automatic updating of dy values + this._build = false // disable build mode for adding multiple lines - /* set default font */ + // set default font this.attr('font-family', SVG.defaults.attrs['font-family']) } @@ -18,11 +18,11 @@ SVG.Text = SVG.invent({ , extend: { // Move over x-axis x: function(x) { - /* act as getter */ + // act as getter if (x == null) return this.attr('x') - /* move lines as well if no textPath is present */ + // move lines as well if no textPath is present if (!this.textPath) this.lines.each(function() { if (this.newLined) this.x(x) }) @@ -33,7 +33,7 @@ SVG.Text = SVG.invent({ var oy = this.attr('y') , o = typeof oy === 'number' ? oy - this.bbox().y : 0 - /* act as getter */ + // act as getter if (y == null) return typeof oy === 'number' ? oy - o : oy @@ -49,26 +49,26 @@ SVG.Text = SVG.invent({ } // Set the text content , text: function(text) { - /* act as getter */ + // act as getter if (typeof text === 'undefined') return this.content - /* remove existing content */ + // remove existing content this.clear().build(true) if (typeof text === 'function') { - /* call block */ + // call block text.call(this, this) } else { - /* store text and make sure text is not blank */ + // store text and make sure text is not blank text = (this.content = text).split('\n') - /* build new lines */ + // build new lines for (var i = 0, il = text.length; i < il; i++) this.tspan(text[i]).newLine() } - /* disable build mode and rebuild lines */ + // disable build mode and rebuild lines return this.build(false).rebuild() } // Set font size @@ -77,22 +77,22 @@ SVG.Text = SVG.invent({ } // Set / get leading , leading: function(value) { - /* act as getter */ + // act as getter if (value == null) return this._leading - /* act as setter */ + // act as setter this._leading = new SVG.Number(value) return this.rebuild() } // Rebuild appearance type , rebuild: function(rebuild) { - /* store new rebuild flag if given */ + // store new rebuild flag if given if (typeof rebuild == 'boolean') this._rebuild = rebuild - /* define position of all lines */ + // define position of all lines if (this._rebuild) { var self = this @@ -155,13 +155,13 @@ SVG.Tspan = SVG.invent({ } // Create new line , newLine: function() { - /* fetch text parent */ + // fetch text parent var t = this.doc(SVG.Text) - /* mark new line */ + // mark new line this.newLined = true - /* apply new hy¡n */ + // apply new hy¡n return this.dy(t._leading * t.attr('font-size')).attr('x', t.x()) } } @@ -171,11 +171,11 @@ SVG.Tspan = SVG.invent({ SVG.extend(SVG.Text, SVG.Tspan, { // Create plain text node plain: function(text) { - /* clear if build mode is disabled */ + // clear if build mode is disabled if (this._build === false) this.clear() - /* create text node */ + // create text node this.node.appendChild(document.createTextNode((this.content = text))) return this @@ -185,14 +185,14 @@ SVG.extend(SVG.Text, SVG.Tspan, { var node = (this.textPath || this).node , tspan = new SVG.Tspan - /* clear if build mode is disabled */ + // clear if build mode is disabled if (this._build === false) this.clear() - /* add new tspan and reference */ + // add new tspan and reference node.appendChild(tspan.node) - /* only first level tspans are considered to be "lines" */ + // only first level tspans are considered to be "lines" if (this instanceof SVG.Text) this.lines.add(tspan) @@ -202,11 +202,11 @@ SVG.extend(SVG.Text, SVG.Tspan, { , clear: function() { var node = (this.textPath || this).node - /* remove existing child nodes */ + // remove existing child nodes while (node.hasChildNodes()) node.removeChild(node.lastChild) - /* reset content references */ + // reset content references if (this instanceof SVG.Text) { delete this.lines this.lines = new SVG.Set diff --git a/src/transporter.js b/src/transporter.js deleted file mode 100644 index d2cf609..0000000 --- a/src/transporter.js +++ /dev/null @@ -1,33 +0,0 @@ -SVG.extend(SVG.Parent, SVG.Text, { - // Import svg SVG data - svg: function(svg) { - // create temporary div to receive svg content - var element = document.createElement('div') - - if (svg) { - // strip away newlines and properly close tags - svg = svg - .replace(/\n/, '') - .replace(/<(\w+)([^<]+?)\/>/g, '<$1$2></$1>') - - // ensure SVG wrapper for correct element type casting - element.innerHTML = '<svg>' + svg + '</svg>' - - // transplant content from well to target - for (var i = element.firstChild.childNodes.length - 1; i >= 0; i--) - if (element.firstChild.childNodes[i].nodeType == 1) - this.node.appendChild(element.firstChild.childNodes[i]) - - return this - - } else { - // clone element and its contents - var clone = this.node.cloneNode(true) - - // add target to clone - element.appendChild(clone) - - return element.innerHTML - } - } -})
\ No newline at end of file |