From 8dfec33b4fa79b89d89a07e3ae92c5d5c5f8ce73 Mon Sep 17 00:00:00 2001 From: wout Date: Mon, 17 Dec 2012 19:39:52 +0100 Subject: Code slimming --- src/clip.js | 14 ++++++++++++++ src/clip_path.js | 14 -------------- src/container.js | 2 +- src/defs.js | 2 +- src/doc.js | 19 +++++++++++++++++++ src/document.js | 19 ------------------- src/element.js | 18 +++--------------- src/g.js | 21 +++++++++++++++++++++ src/group.js | 21 --------------------- src/object.js | 31 ------------------------------- src/shape.js | 24 ++++++++++++------------ src/svg.js | 2 +- 12 files changed, 72 insertions(+), 115 deletions(-) create mode 100644 src/clip.js delete mode 100644 src/clip_path.js create mode 100644 src/doc.js delete mode 100644 src/document.js create mode 100644 src/g.js delete mode 100644 src/group.js delete mode 100644 src/object.js (limited to 'src') diff --git a/src/clip.js b/src/clip.js new file mode 100644 index 0000000..80d78d0 --- /dev/null +++ b/src/clip.js @@ -0,0 +1,14 @@ +// initialize id sequence +var clipID = 0; + +SVG.Clip = function Clip() { + this.constructor.call(this, SVG.create('clipPath')); + this.id = '_' + (clipID++); + this.attr('id', this.id); +}; + +// inherit from SVG.Element +SVG.Clip.prototype = new SVG.Element(); + +// include the container object +SVG.Utils.merge(SVG.Clip, SVG.Container); \ No newline at end of file diff --git a/src/clip_path.js b/src/clip_path.js deleted file mode 100644 index 57bff82..0000000 --- a/src/clip_path.js +++ /dev/null @@ -1,14 +0,0 @@ -// initialize id sequence -var clipID = 0; - -SVG.ClipPath = function ClipPath() { - this.constructor.call(this, SVG.create('clipPath')); - this.id = '_' + (clipID++); - this.attr('id', this.id); -}; - -// inherit from SVG.Element -SVG.ClipPath.prototype = new SVG.Element(); - -// include the container object -SVG.Utils.merge(SVG.ClipPath, SVG.Container); \ No newline at end of file diff --git a/src/container.js b/src/container.js index cc2fd4f..9d8b5af 100644 --- a/src/container.js +++ b/src/container.js @@ -75,7 +75,7 @@ SVG.Container = { }, group: function() { - var e = new SVG.Group(); + var e = new SVG.G(); this.add(e); return e; diff --git a/src/defs.js b/src/defs.js index 4c252a5..4ba7c8c 100644 --- a/src/defs.js +++ b/src/defs.js @@ -14,7 +14,7 @@ SVG.Utils.merge(SVG.Defs, { // define clippath clipPath: function() { - var e = new SVG.ClipPath(); + var e = new SVG.Clip(); this.add(e); return e; diff --git a/src/doc.js b/src/doc.js new file mode 100644 index 0000000..41b157f --- /dev/null +++ b/src/doc.js @@ -0,0 +1,19 @@ + +SVG.Doc = function Doc(e) { + this.constructor.call(this, SVG.create('svg')); + + this.attr('xmlns', SVG.ns); + this.attr('version', '1.1'); + this.attr('xlink', SVG.xlink, SVG.ns); + + if (typeof e == 'string') + e = document.getElementById(e); + + e.appendChild(this.node); +}; + +// inherit from SVG.Element +SVG.Doc.prototype = new SVG.Element(); + +// include the container object +SVG.Utils.merge(SVG.Doc, SVG.Container); \ No newline at end of file diff --git a/src/document.js b/src/document.js deleted file mode 100644 index 32780c1..0000000 --- a/src/document.js +++ /dev/null @@ -1,19 +0,0 @@ - -SVG.Document = function Document(e) { - this.constructor.call(this, SVG.create('svg')); - - this.attr('xmlns', SVG.ns); - this.attr('version', '1.1'); - this.attr('xlink', SVG.xlink, SVG.ns); - - if (typeof e == 'string') - e = document.getElementById(e); - - e.appendChild(this.node); -}; - -// inherit from SVG.Element -SVG.Document.prototype = new SVG.Element(); - -// include the container object -SVG.Utils.merge(SVG.Document, SVG.Container); \ No newline at end of file diff --git a/src/element.js b/src/element.js index 7926e1f..9536a79 100644 --- a/src/element.js +++ b/src/element.js @@ -42,32 +42,20 @@ SVG.Utils.merge(SVG.Element, { }, // remove element - destroy: function() { + remove: function() { return this.parent != null ? this.parent.remove(this) : void 0; }, // get parent document parentDoc: function() { - return this._parent(SVG.Document); + return this._parent(SVG.Doc); }, // get parent svg wrapper parentSVG: function() { return this.parentDoc(); }, - - //_D // set svg element attribute - //_D setAttribute: function(a, v, ns) { - //_D this.attrs[a] = v; - //_D - //_D if (ns != null) - //_D this.node.setAttributeNS(ns, a, v); - //_D else - //_D this.node.setAttribute(a, v); - //_D - //_D return this; - //_D }, - + // set svg element attribute attr: function(v) { var a = arguments; diff --git a/src/g.js b/src/g.js new file mode 100644 index 0000000..cd6de15 --- /dev/null +++ b/src/g.js @@ -0,0 +1,21 @@ + +SVG.G = function G() { + this.constructor.call(this, SVG.create('g')); +}; + +// inherit from SVG.Element +SVG.G.prototype = new SVG.Element(); + +// include the container object +SVG.Utils.merge(SVG.G, SVG.Container); + +// Add group-specific functions +SVG.Utils.merge(SVG.G, { + + // group rotation + rotate: function(d) { + this.attr('transform', 'rotate(' + d + ')'); + return this; + } + +}); \ No newline at end of file diff --git a/src/group.js b/src/group.js deleted file mode 100644 index 2236c09..0000000 --- a/src/group.js +++ /dev/null @@ -1,21 +0,0 @@ - -SVG.Group = function Group() { - this.constructor.call(this, SVG.create('g')); -}; - -// inherit from SVG.Element -SVG.Group.prototype = new SVG.Element(); - -// include the container object -SVG.Utils.merge(SVG.Group, SVG.Container); - -// Add group-specific functions -SVG.Utils.merge(SVG.Group, { - - // group rotation - rotate: function(d) { - this.attr('transform', 'rotate(' + d + ')'); - return this; - } - -}); \ No newline at end of file diff --git a/src/object.js b/src/object.js deleted file mode 100644 index 1ec7ecc..0000000 --- a/src/object.js +++ /dev/null @@ -1,31 +0,0 @@ - -//SVG.Object = function Object() {}; -// -//Object.prototype.include = function(module) { -// -// for (var key in module) -// this.prototype[key] = module[key]; -// -// if (module.included != null) -// module.included.apply(this); -// -// return this; -//}; - -//SVG.Object = function Object() {}; -// -//SVG.Object.moduleKeywords = ['included', 'extended']; -// -//SVG.Object.include = function(module) { -// var key, value, _ref; -// for (key in module) { -// value = module[key]; -// if (Array.prototype.indexOf.call(this.moduleKeywords, key) < 0) { -// this.prototype[key] = value; -// } -// } -// if ((_ref = module.included) != null) { -// _ref.apply(this); -// } -// return this; -//}; \ No newline at end of file diff --git a/src/shape.js b/src/shape.js index a57b9f2..1a32a00 100644 --- a/src/shape.js +++ b/src/shape.js @@ -10,26 +10,26 @@ SVG.Shape.prototype = new SVG.Element(); SVG.Utils.merge(SVG.Shape, { // set fill color and opacity - fill: function(fill) { - if (fill.color != null) - this.attr('fill', fill.color); + fill: function(f) { + if (f.color != null) + this.attr('fill', f.color); - if (fill.opacity != null) - this.attr('fill-opacity', fill.opacity); + if (f.opacity != null) + this.attr('fill-opacity', f.opacity); return this; }, // set stroke color and opacity - stroke: function(stroke) { - if (stroke.color != null) - this.attr('stroke', stroke.color); + stroke: function(s) { + if (s.color) + this.attr('stroke', s.color); - if (stroke.width != null) - this.attr('stroke-width', stroke.width); + if (s.width != null) + this.attr('stroke-width', s.width); - if (stroke.opacity != null) - this.attr('stroke-opacity', stroke.opacity); + if (s.opacity != null) + this.attr('stroke-opacity', s.opacity); if (this.attrs['fill-opacity'] == null) this.fill({ opacity: 0 }); diff --git a/src/svg.js b/src/svg.js index b042f12..331d756 100644 --- a/src/svg.js +++ b/src/svg.js @@ -9,5 +9,5 @@ this.SVG = { }; this.svg = function(e) { - return new SVG.Document(e); + return new SVG.Doc(e); }; \ No newline at end of file -- cgit v1.2.3