From e4fb8522a2c57069b2523f16de92d5eb7e6dd85e Mon Sep 17 00:00:00 2001 From: wout Date: Sat, 29 Jun 2013 15:16:58 +0100 Subject: IMplemented element, bumped to v0.23 --- src/element.js | 8 ++++---- src/gradient.js | 4 ++++ src/instance.js | 28 ---------------------------- src/pattern.js | 4 ++++ src/use.js | 28 ++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 32 deletions(-) delete mode 100644 src/instance.js create mode 100644 src/use.js (limited to 'src') diff --git a/src/element.js b/src/element.js index 60fbb39..3337df8 100644 --- a/src/element.js +++ b/src/element.js @@ -146,10 +146,6 @@ SVG.extend(SVG.Element, { return this.style(v) } else { - /* process gradient or pattern fill */ - if (typeof v.fill === 'function') - v = v.fill() - /* treat x differently on text elements */ if (a == 'x' && Array.isArray(this.lines)) for (n = this.lines.length - 1; n >= 0; n--) @@ -363,6 +359,10 @@ SVG.extend(SVG.Element, { , visible: function() { return this.style('display') != 'none' } + // Return id on string conversion +, toString: function() { + return this.attr('id') + } // Private: find svg parent by instance , _parent: function(parent) { var element = this diff --git a/src/gradient.js b/src/gradient.js index 2f6e30a..c5c51d1 100644 --- a/src/gradient.js +++ b/src/gradient.js @@ -46,6 +46,10 @@ SVG.extend(SVG.Gradient, { , fill: function() { return 'url(#' + this.attr('id') + ')' } + // Alias string convertion to fill +, toString: function() { + return this.fill() + } }) diff --git a/src/instance.js b/src/instance.js deleted file mode 100644 index 086a019..0000000 --- a/src/instance.js +++ /dev/null @@ -1,28 +0,0 @@ -SVG.Use = function() { - this.constructor.call(this, SVG.create('use')) -} - -// Inherit from SVG.Shape -SVG.Use.prototype = new SVG.Element - -// -SVG.extend(SVG.Use, { - - // (re)load image - load: function(url) { - return (url ? this.attr('xlink:href', (this.src = url), SVG.xlink) : this) - } - -}) - -// -SVG.extend(SVG.Container, { - // Create a use element - use: function(element) { - if (element instanceof SVG.Element) - element = element.id - - return this.put(new SVG.Use().) - } - -}) \ No newline at end of file diff --git a/src/pattern.js b/src/pattern.js index dc57e77..4807049 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -11,6 +11,10 @@ SVG.extend(SVG.Pattern, { fill: function() { return 'url(#' + this.attr('id') + ')' } + // Alias string convertion to fill +, toString: function() { + return this.fill() + } }) diff --git a/src/use.js b/src/use.js new file mode 100644 index 0000000..d507998 --- /dev/null +++ b/src/use.js @@ -0,0 +1,28 @@ +SVG.Use = function() { + this.constructor.call(this, SVG.create('use')) +} + +// Inherit from SVG.Shape +SVG.Use.prototype = new SVG.Element + +// +SVG.extend(SVG.Use, { + // Use element as a reference + element: function(element) { + /* store target element */ + this.target = element + + /* set lined element */ + return this.attr('xlink:href', '#' + element, SVG.xlink) + } + +}) + +// +SVG.extend(SVG.Container, { + // Create a use element + use: function(element) { + return this.put(new SVG.Use).element(element) + } + +}) \ No newline at end of file -- cgit v1.2.3