From 8dfec33b4fa79b89d89a07e3ae92c5d5c5f8ce73 Mon Sep 17 00:00:00 2001 From: wout Date: Mon, 17 Dec 2012 19:39:52 +0100 Subject: [PATCH] Code slimming --- Rakefile | 2 +- dist/svg.js | 70 +++++++++++++++-------------------- dist/svg.min.js | 4 +- src/{clip_path.js => clip.js} | 6 +-- src/container.js | 2 +- src/defs.js | 2 +- src/{document.js => doc.js} | 6 +-- src/element.js | 18 ++------- src/{group.js => g.js} | 8 ++-- src/object.js | 31 ---------------- src/shape.js | 24 ++++++------ src/svg.js | 2 +- 12 files changed, 60 insertions(+), 115 deletions(-) rename src/{clip_path.js => clip.js} (63%) rename src/{document.js => doc.js} (71%) rename src/{group.js => g.js} (64%) delete mode 100644 src/object.js diff --git a/Rakefile b/Rakefile index 7fdd118..3e8cfe4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ SVGJS_VERSION = '0.1' -DEFAULT_MODULES = %w[ svg utils container element document defs shape rect circle ellipse path image group clip_path ] +DEFAULT_MODULES = %w[ svg utils container element doc defs shape rect circle ellipse path image g clip ] KILO = 1024 # how many bytes in a "kilobyte" diff --git a/dist/svg.js b/dist/svg.js index feea266..f0b8cc8 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js 0.1 - svg utils container element document defs shape rect circle ellipse path image group clip_path - svgjs.com/license */ +/* svg.js 0.1 - svg utils container element doc defs shape rect circle ellipse path image g clip - svgjs.com/license */ (function() { this.SVG = { @@ -11,7 +11,7 @@ }; this.svg = function(e) { - return new SVG.Document(e); + return new SVG.Doc(e); }; SVG.Utils = { @@ -99,7 +99,7 @@ }, group: function() { - var e = new SVG.Group(); + var e = new SVG.G(); this.add(e); return e; @@ -212,32 +212,20 @@ }, // 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; @@ -275,7 +263,7 @@ }); - SVG.Document = function Document(e) { + SVG.Doc = function Doc(e) { this.constructor.call(this, SVG.create('svg')); this.attr('xmlns', SVG.ns); @@ -289,10 +277,10 @@ }; // inherit from SVG.Element - SVG.Document.prototype = new SVG.Element(); + SVG.Doc.prototype = new SVG.Element(); // include the container object - SVG.Utils.merge(SVG.Document, SVG.Container); + SVG.Utils.merge(SVG.Doc, SVG.Container); SVG.Defs = function Defs() { this.constructor.call(this, SVG.create('defs')); @@ -309,7 +297,7 @@ // define clippath clipPath: function() { - var e = new SVG.ClipPath(); + var e = new SVG.Clip(); this.add(e); return e; @@ -328,26 +316,26 @@ 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 }); @@ -476,18 +464,18 @@ }); - SVG.Group = function Group() { + SVG.G = function G() { this.constructor.call(this, SVG.create('g')); }; // inherit from SVG.Element - SVG.Group.prototype = new SVG.Element(); + SVG.G.prototype = new SVG.Element(); // include the container object - SVG.Utils.merge(SVG.Group, SVG.Container); + SVG.Utils.merge(SVG.G, SVG.Container); // Add group-specific functions - SVG.Utils.merge(SVG.Group, { + SVG.Utils.merge(SVG.G, { // group rotation rotate: function(d) { @@ -499,16 +487,16 @@ var clipID = 0; - SVG.ClipPath = function ClipPath() { + SVG.Clip = function Clip() { 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(); + SVG.Clip.prototype = new SVG.Element(); // include the container object - SVG.Utils.merge(SVG.ClipPath, SVG.Container); + SVG.Utils.merge(SVG.Clip, SVG.Container); }).call(this); diff --git a/dist/svg.min.js b/dist/svg.min.js index cc7eb88..c8f59e5 100644 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1,2 +1,2 @@ -/* svg.js 0.1 - svg utils container element document defs shape rect circle ellipse path image group clip_path - svgjs.com/license */ -(function(){this.SVG={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",create:function(e){return document.createElementNS(this.ns,e)}},this.svg=function(e){return new SVG.Document(e)},SVG.Utils={merge:function(e,t){for(var n in t)e.prototype[n]=t[n]}},SVG.Container={add:function(e){return this.addAt(e)},addAt:function(e,t){return this.contains(e)||(t=t==null?this.children().length:t,this.children().splice(t,0,e),this.node.insertBefore(e.node,this.node.childNodes[t+1]),e.parent=this),this},contains:function(e){return Array.prototype.indexOf.call(this.children(),e)>=0},children:function(){return this._children||[]},sendBack:function(e){var t=this.children().indexOf(e);if(t!==-1)return this.remove(e).addAt(e,t-1)},bringForward:function(e){var t=this.children().indexOf(e);if(t!==-1)return this.remove(e).addAt(e,t+1)},bringToFront:function(e){return this.contains(e)&&this.remove(e).add(e),this},sendToBottom:function(e){return this.contains(e)&&this.remove(e).addAt(e,0),this},remove:function(e){return this.removeAt(this.children().indexOf(e))},removeAt:function(e){if(0<=e&&e=0},children:function(){return this._children||[]},sendBack:function(e){var t=this.children().indexOf(e);if(t!==-1)return this.remove(e).addAt(e,t-1)},bringForward:function(e){var t=this.children().indexOf(e);if(t!==-1)return this.remove(e).addAt(e,t+1)},bringToFront:function(e){return this.contains(e)&&this.remove(e).add(e),this},sendToBottom:function(e){return this.contains(e)&&this.remove(e).addAt(e,0),this},remove:function(e){return this.removeAt(this.children().indexOf(e))},removeAt:function(e){if(0<=e&&e