diff --git a/editor/browsersupport.js b/editor/browsersupport.js
index a8b3f1df..8da0a95f 100644
--- a/editor/browsersupport.js
+++ b/editor/browsersupport.js
@@ -1,5 +1,5 @@
/**
- * Browser Support module for SVG-edit
+ * Package: svgedit.browsersupport
*
* Licensed under the Apache License, Version 2
*
@@ -16,17 +16,17 @@ if (!window.svgedit) {
window.svgedit = {};
}
-if (!svgedit.BrowserSupport) {
- svgedit.BrowserSupport = {};
+if (!svgedit.browsersupport) {
+ svgedit.browsersupport = {};
}
var svgns = 'http://www.w3.org/2000/svg';
var userAgent = navigator.userAgent;
// Note: Browser sniffing should only be used if no other detection method is possible
-svgedit.BrowserSupport.isOpera = !!window.opera;
-svgedit.BrowserSupport.isWebkit = userAgent.indexOf("AppleWebKit") >= 0;
-svgedit.BrowserSupport.isGecko = userAgent.indexOf('Gecko/') >= 0;
+svgedit.browsersupport.isOpera = !!window.opera;
+svgedit.browsersupport.isWebkit = userAgent.indexOf("AppleWebKit") >= 0;
+svgedit.browsersupport.isGecko = userAgent.indexOf('Gecko/') >= 0;
// segList functions (for FF1.5 and 2.0)
function supportPathReplaceItem() {
@@ -71,7 +71,7 @@ function supportTextCharPos() {
function supportEditableText() {
// TODO: Find better way to check support for this
- return svgedit.BrowserSupport.isOpera;
+ return svgedit.browsersupport.isOpera;
}
function supportGoodDecimals() {
@@ -93,11 +93,11 @@ function supportNonScalingStroke() {
return rect.style.vectorEffect === 'non-scaling-stroke';
}
-svgedit.BrowserSupport.pathReplaceItem = supportPathReplaceItem();
-svgedit.BrowserSupport.pathInsertItemBefore = supportPathInsertItemBefore();
-svgedit.BrowserSupport.textCharPos = supportTextCharPos();
-svgedit.BrowserSupport.editableText = supportEditableText();
-svgedit.BrowserSupport.goodDecimals = supportGoodDecimals();
-svgedit.BrowserSupport.nonScalingStroke = supportNonScalingStroke();
+svgedit.browsersupport.pathReplaceItem = supportPathReplaceItem();
+svgedit.browsersupport.pathInsertItemBefore = supportPathInsertItemBefore();
+svgedit.browsersupport.textCharPos = supportTextCharPos();
+svgedit.browsersupport.editableText = supportEditableText();
+svgedit.browsersupport.goodDecimals = supportGoodDecimals();
+svgedit.browsersupport.nonScalingStroke = supportNonScalingStroke();
})();
\ No newline at end of file
diff --git a/editor/math.js b/editor/math.js
index b77f249c..08f253b3 100644
--- a/editor/math.js
+++ b/editor/math.js
@@ -1,5 +1,5 @@
/**
- * SVG-edit Math Utilities
+ * Package: svedit.math
*
* Licensed under the Apache License, Version 2
*
diff --git a/editor/svg-editor.html b/editor/svg-editor.html
index 25eb034e..153121ad 100644
--- a/editor/svg-editor.html
+++ b/editor/svg-editor.html
@@ -21,6 +21,7 @@
+
diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js
index f76a58c9..4dbbcea1 100644
--- a/editor/svgcanvas.js
+++ b/editor/svgcanvas.js
@@ -15,6 +15,7 @@
// 3) svgtransformlist.js
// 4) math.js
// 5) svgutils.js
+// 6) units.js
if(!window.console) {
window.console = {};
@@ -96,10 +97,49 @@ if(window.opera) {
// config - An object that contains configuration data
$.SvgCanvas = function(container, config)
{
-var support = svgedit.BrowserSupport,
- isOpera = support.isOpera,
- isWebkit = support.isWebkit,
- isGecko = support.isGecko,
+
+// import svgtransformlist.js
+var getTransformList = this.getTransformList = svgedit.transformlist.getTransformList;
+
+// import from math.js.
+var transformPoint = svgedit.math.transformPoint;
+var isIdentity = svgedit.math.isIdentity;
+var matrixMultiply = this.matrixMultiply = svgedit.math.matrixMultiply;
+var hasMatrixTransform = this.hasMatrixTransform = svgedit.math.hasMatrixTransform;
+var transformBox = this.transformBox = svgedit.math.transformBox;
+var transformListToTransform = this.transformListToTransform = svgedit.math.transformListToTransform;
+var snapToAngle = svgedit.math.snapToAngle;
+
+// import from units.js
+svgedit.units.init();
+var unit_types = svgedit.units.typeMap;
+
+// import from svgutils.js
+var getUrlFromAttr = this.getUrlFromAttr = svgedit.utilities.getUrlFromAttr;
+var getHref = this.getHref = svgedit.utilities.getHref;
+var setHref = this.setHref = svgedit.utilities.setHref;
+var getPathBBox = svgedit.utilities.getPathBBox;
+var getBBox = this.getBBox = svgedit.utilities.getBBox;
+var getRotationAngle = this.getRotationAngle = svgedit.utilities.getRotationAngle;
+
+// Function: snapToGrid
+// round value to for snapping
+// NOTE: This function did not move to svgutils.js since it depends on curConfig.
+svgedit.utilities.snapToGrid = function(value){
+ var stepSize = curConfig.snappingStep;
+ var unit = curConfig.baseUnit;
+ if(unit !== "px") {
+ stepSize *= svgedit.units.typeMap[unit];
+ }
+ value = Math.round(value/stepSize)*stepSize;
+ return value;
+};
+var snapToGrid = svgedit.utilities.snapToGrid;
+
+
+var isOpera = svgedit.browsersupport.isOpera,
+ isWebkit = svgedit.browsersupport.isWebkit,
+ isGecko = svgedit.browsersupport.isGecko,
// this defines which elements and attributes that we support
svgWhiteList = {
@@ -186,13 +226,10 @@ var support = svgedit.BrowserSupport,
show_outside_canvas: true,
dimensions: [640, 480]
};
-
var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use';
-
var ref_attrs = ["clip-path", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"];
-
// Update config with new one if given
if(config) {
$.extend(curConfig, config);
@@ -212,9 +249,6 @@ var canvas = this,
se_ns = "http://svg-edit.googlecode.com",
htmlns = "http://www.w3.org/1999/xhtml",
mathns = "http://www.w3.org/1998/Math/MathML",
-
- // Map of units, updated later based on px conversion.
- unit_types = {px: 1},
//nonce to uniquify id's
nonce = Math.floor(Math.random()*100001),
@@ -229,7 +263,7 @@ var canvas = this,
dimensions = curConfig.dimensions;
// Create Root SVG element. This is a container for the document being edited, not the document itself.
- var svgroot = svgdoc.importNode(svgedit.Utilities.text2xml(
+ var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
'