diff --git a/Makefile b/Makefile index 091887a3..e909f0f1 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ ZIP=zip # All files that will be compiled by the Closure compiler. JS_FILES=\ + svgedit.js \ contextmenu/jquery.contextmenu.js \ browser.js \ svgtransformlist.js \ diff --git a/editor/browser.js b/editor/browser.js index 4f3d76bb..d43458ba 100644 --- a/editor/browser.js +++ b/editor/browser.js @@ -10,18 +10,17 @@ // Dependencies: // 1) jQuery (for $.alert()) -var svgedit = svgedit || {}; - (function() { if (!svgedit.browser) { svgedit.browser = {}; } -var svgns = 'http://www.w3.org/2000/svg'; +// alias +var NS = svgedit.NS; var supportsSvg_ = (function() { - return !!document.createElementNS && !!document.createElementNS(svgns, 'svg').createSVGRect; + return !!document.createElementNS && !!document.createElementNS(NS.SVG, 'svg').createSVGRect; })(); svgedit.browser.supportsSvg = function() { return supportsSvg_; }; @@ -31,7 +30,7 @@ if(!svgedit.browser.supportsSvg()) { } var userAgent = navigator.userAgent; -var svg = document.createElementNS(svgns, 'svg'); +var svg = document.createElementNS(NS.SVG, 'svg'); // Note: Browser sniffing should only be used if no other detection method is possible var isOpera_ = !!window.opera; @@ -53,7 +52,7 @@ var supportsXpath_ = (function() { // segList functions (for FF1.5 and 2.0) var supportsPathReplaceItem_ = (function() { - var path = document.createElementNS(svgns, 'path'); + var path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 10,10'); var seglist = path.pathSegList; var seg = path.createSVGPathSegLinetoAbs(5,5); @@ -65,7 +64,7 @@ var supportsPathReplaceItem_ = (function() { })(); var supportsPathInsertItemBefore_ = (function() { - var path = document.createElementNS(svgns, 'path'); + var path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 10,10'); var seglist = path.pathSegList; var seg = path.createSVGPathSegLinetoAbs(5,5); @@ -78,12 +77,12 @@ var supportsPathInsertItemBefore_ = (function() { // text character positioning (for IE9) var supportsGoodTextCharPos_ = (function() { - var svgroot = document.createElementNS(svgns, 'svg'); - var svgcontent = document.createElementNS(svgns, 'svg'); + var svgroot = document.createElementNS(NS.SVG, 'svg'); + var svgcontent = document.createElementNS(NS.SVG, 'svg'); document.documentElement.appendChild(svgroot); svgcontent.setAttribute('x', 5); svgroot.appendChild(svgcontent); - var text = document.createElementNS(svgns, 'text'); + var text = document.createElementNS(NS.SVG, 'text'); text.textContent = 'a'; svgcontent.appendChild(text); var pos = text.getStartPositionOfChar(0).x; @@ -92,9 +91,9 @@ var supportsGoodTextCharPos_ = (function() { })(); var supportsPathBBox_ = (function() { - var svgcontent = document.createElementNS(svgns, 'svg'); + var svgcontent = document.createElementNS(NS.SVG, 'svg'); document.documentElement.appendChild(svgcontent); - var path = document.createElementNS(svgns, 'path'); + var path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 C0,0 10,10 10,0'); svgcontent.appendChild(path); var bbox = path.getBBox(); @@ -104,13 +103,13 @@ var supportsPathBBox_ = (function() { // Support for correct bbox sizing on groups with horizontal/vertical lines var supportsHVLineContainerBBox_ = (function() { - var svgcontent = document.createElementNS(svgns, 'svg'); + var svgcontent = document.createElementNS(NS.SVG, 'svg'); document.documentElement.appendChild(svgcontent); - var path = document.createElementNS(svgns, 'path'); + var path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 10,0'); - var path2 = document.createElementNS(svgns, 'path'); + var path2 = document.createElementNS(NS.SVG, 'path'); path2.setAttribute('d', 'M5,0 15,0'); - var g = document.createElementNS(svgns, 'g'); + var g = document.createElementNS(NS.SVG, 'g'); g.appendChild(path); g.appendChild(path2); svgcontent.appendChild(g); @@ -127,7 +126,7 @@ var supportsEditableText_ = (function() { var supportsGoodDecimals_ = (function() { // Correct decimals on clone attributes (Opera < 10.5/win/non-en) - var rect = document.createElementNS(svgns, 'rect'); + var rect = document.createElementNS(NS.SVG, 'rect'); rect.setAttribute('x', 0.1); var crect = rect.cloneNode(false); var retValue = (crect.getAttribute('x').indexOf(',') == -1); @@ -139,13 +138,13 @@ var supportsGoodDecimals_ = (function() { })(); var supportsNonScalingStroke_ = (function() { - var rect = document.createElementNS(svgns, 'rect'); + var rect = document.createElementNS(NS.SVG, 'rect'); rect.setAttribute('style', 'vector-effect:non-scaling-stroke'); return rect.style.vectorEffect === 'non-scaling-stroke'; })(); var supportsNativeSVGTransformLists_ = (function() { - var rect = document.createElementNS(svgns, 'rect'); + var rect = document.createElementNS(NS.SVG, 'rect'); var rxform = rect.transform.baseVal; var t1 = svg.createSVGTransform(); rxform.appendItem(t1); diff --git a/editor/draw.js b/editor/draw.js index e07e3cd6..45843f9c 100644 --- a/editor/draw.js +++ b/editor/draw.js @@ -11,17 +11,13 @@ // 2) browser.js // 3) svgutils.js -var svgedit = svgedit || {}; - (function() { if (!svgedit.draw) { svgedit.draw = {}; } - -var svg_ns = "http://www.w3.org/2000/svg"; -var se_ns = "http://svg-edit.googlecode.com"; -var xmlns_ns = "http://www.w3.org/2000/xmlns/"; +// alias +var NS = svgedit.NS; var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use'; var visElems_arr = visElems.split(','); @@ -80,7 +76,7 @@ svgedit.draw.randomizeIds = function(enableRandomization, current_drawing) { */ svgedit.draw.Drawing = function(svgElem, opt_idPrefix) { if (!svgElem || !svgElem.tagName || !svgElem.namespaceURI || - svgElem.tagName != 'svg' || svgElem.namespaceURI != svg_ns) { + svgElem.tagName != 'svg' || svgElem.namespaceURI != NS.SVG) { throw "Error: svgedit.draw.Drawing instance initialized without a element"; } @@ -128,7 +124,7 @@ svgedit.draw.Drawing = function(svgElem, opt_idPrefix) { * @type {!String} */ this.nonce_ = ""; - var n = this.svgElem_.getAttributeNS(se_ns, 'nonce'); + var n = this.svgElem_.getAttributeNS(NS.SE, 'nonce'); // If already set in the DOM, use the nonce throughout the document // else, if randomizeIds(true) has been called, create and set the nonce. if (!!n && randomize_ids != RandomizeModes.NEVER_RANDOMIZE) { @@ -156,8 +152,8 @@ svgedit.draw.Drawing.prototype.getNonce = function() { }; svgedit.draw.Drawing.prototype.setNonce = function(n) { - this.svgElem_.setAttributeNS(xmlns_ns, 'xmlns:se', se_ns); - this.svgElem_.setAttributeNS(se_ns, 'se:nonce', n); + this.svgElem_.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE); + this.svgElem_.setAttributeNS(NS.SE, 'se:nonce', n); this.nonce_ = n; }; @@ -358,7 +354,7 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { if (child.tagName == "g") { childgroups = true; var name = $("title", child).text(); - + // Hack for Opera 10.60 if(!name && svgedit.browser.isOpera() && child.querySelectorAll) { name = $(child.querySelectorAll('title')).text(); @@ -392,8 +388,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { // TODO(codedread): What about internationalization of "Layer"? while (layernames.indexOf(("Layer " + i)) >= 0) { i++; } var newname = "Layer " + i; - a_layer = svgdoc.createElementNS(svg_ns, "g"); - var layer_title = svgdoc.createElementNS(svg_ns, "title"); + a_layer = svgdoc.createElementNS(NS.SVG, "g"); + var layer_title = svgdoc.createElementNS(NS.SVG, "title"); layer_title.textContent = newname; a_layer.appendChild(layer_title); for (var j = 0; j < orphans.length; ++j) { @@ -419,8 +415,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { // of this drawing. svgedit.draw.Drawing.prototype.createLayer = function(name) { var svgdoc = this.svgElem_.ownerDocument; - var new_layer = svgdoc.createElementNS(svg_ns, "g"); - var layer_title = svgdoc.createElementNS(svg_ns, "title"); + var new_layer = svgdoc.createElementNS(NS.SVG, "g"); + var layer_title = svgdoc.createElementNS(NS.SVG, "title"); layer_title.textContent = name; new_layer.appendChild(layer_title); this.svgElem_.appendChild(new_layer); diff --git a/editor/extensions/ext-eyedropper.js b/editor/extensions/ext-eyedropper.js index 06d12833..230b5b07 100644 --- a/editor/extensions/ext-eyedropper.js +++ b/editor/extensions/ext-eyedropper.js @@ -14,8 +14,8 @@ // 4) svgcanvas.js svgEditor.addExtension("eyedropper", function(S) { - var svgcontent = S.svgcontent, - svgns = "http://www.w3.org/2000/svg", + var NS = svgedit.NS, + svgcontent = S.svgcontent, svgdoc = S.svgroot.parentNode.ownerDocument, svgCanvas = svgEditor.canvas, ChangeElementCommand = svgedit.history.ChangeElementCommand, @@ -27,7 +27,7 @@ svgEditor.addExtension("eyedropper", function(S) { strokeLinecap: 'butt', strokeLinejoin: 'miter', }; - + function getStyle(opts) { // if we are in eyedropper mode, we don't want to disable the eye-dropper tool var mode = svgCanvas.getMode(); diff --git a/editor/extensions/ext-foreignobject.js b/editor/extensions/ext-foreignobject.js index 9d401825..e098f58d 100644 --- a/editor/extensions/ext-foreignobject.js +++ b/editor/extensions/ext-foreignobject.js @@ -9,269 +9,257 @@ */ svgEditor.addExtension("foreignObject", function(S) { - var svgcontent = S.svgcontent, - addElem = S.addSvgElementFromJson, - selElems, - svgns = "http://www.w3.org/2000/svg", - xlinkns = "http://www.w3.org/1999/xlink", - xmlns = "http://www.w3.org/XML/1998/namespace", - xmlnsns = "http://www.w3.org/2000/xmlns/", - se_ns = "http://svg-edit.googlecode.com", - htmlns = "http://www.w3.org/1999/xhtml", - mathns = "http://www.w3.org/1998/Math/MathML", - editingforeign = false, - svgdoc = S.svgroot.parentNode.ownerDocument, - started, - newFO; - - - var properlySourceSizeTextArea = function(){ - // TODO: remove magic numbers here and get values from CSS - var height = $('#svg_source_container').height() - 80; - $('#svg_source_textarea').css('height', height); - }; + var NS = svgedit.NS, + svgcontent = S.svgcontent, + addElem = S.addSvgElementFromJson, + selElems, + editingforeign = false, + svgdoc = S.svgroot.parentNode.ownerDocument, + started, + newFO; - function showPanel(on) { - var fc_rules = $('#fc_rules'); - if(!fc_rules.length) { - fc_rules = $(' - - - - - - + + + + - - -

Unit Tests for contextmenu.js

-

-

-
    -
- - +}); + + + +

Unit Tests for contextmenu.js

+

+

+
    +
+ + diff --git a/test/coords_test.html b/test/coords_test.html index 22a54c09..1b8bc01f 100644 --- a/test/coords_test.html +++ b/test/coords_test.html @@ -1,14 +1,15 @@ - - - - - - - + + + + + + - - +}); + + +

Unit Tests for svgedit.coords

@@ -34,5 +34,5 @@ - + diff --git a/test/draw_test.html b/test/draw_test.html index f104a180..fd4788da 100644 --- a/test/draw_test.html +++ b/test/draw_test.html @@ -1,73 +1,71 @@ - - - - - - - + + + + + + - - -

Unit Tests for draw.js

-

-

-
    -
- - +}); + + + +

Unit Tests for draw.js

+

+

+
    +
+ + diff --git a/test/history_test.html b/test/history_test.html index 15bc3b1e..d1d2d3e3 100644 --- a/test/history_test.html +++ b/test/history_test.html @@ -1,12 +1,12 @@ - - - - - + + + - - -

Unit Tests for history.js

-

-

-
    -
- - - - +}); + + + +

Unit Tests for history.js

+

+

+
    +
+ + + diff --git a/test/math_test.html b/test/math_test.html index de31eb06..72fa9718 100644 --- a/test/math_test.html +++ b/test/math_test.html @@ -3,9 +3,10 @@ - - - + + + - - - + + + - - +}); + + +

Unit Tests for path.js

@@ -25,5 +24,5 @@ - + diff --git a/test/sanitize_test.html b/test/sanitize_test.html index 8bcff19a..f8a320eb 100644 --- a/test/sanitize_test.html +++ b/test/sanitize_test.html @@ -1,28 +1,28 @@ - - - - - - - + + + + + + - - + +

Unit Tests for sanitize.js

@@ -43,5 +43,5 @@ - + diff --git a/test/select_test.html b/test/select_test.html index e10a093f..64dcf93e 100644 --- a/test/select_test.html +++ b/test/select_test.html @@ -1,17 +1,18 @@ - - - - - - - - + + + + + + + - - -

Unit Tests for select.js

-

-

-
    -
-
- +}); + + + +

Unit Tests for select.js

+

+

+
    +
+
+ diff --git a/test/svgtransformlist_test.html b/test/svgtransformlist_test.html index df697cf7..3e80fa12 100644 --- a/test/svgtransformlist_test.html +++ b/test/svgtransformlist_test.html @@ -1,39 +1,38 @@ - - - - - - - - + + + + + - - -

Unit Tests for svgtransformlist.js

-

-

-
    -
- - +}); + + + +

Unit Tests for svgtransformlist.js

+

+

+
    +
+ + diff --git a/test/svgutils_test.html b/test/svgutils_test.html index b04a07fd..78e75103 100644 --- a/test/svgutils_test.html +++ b/test/svgutils_test.html @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + - - -

Unit Tests for svgutils.js

-

-

-
    -
- +}); + + + +

Unit Tests for svgutils.js

+

+

+
    +
+ diff --git a/test/test1.html b/test/test1.html index 33b297ba..e07b9569 100644 --- a/test/test1.html +++ b/test/test1.html @@ -1,25 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + +