created svgedit main object, moved all namespaces handling in the same place

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2411 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Bruno Heridet 2013-02-16 15:02:26 +00:00
parent 5d5abbd2b0
commit f9b8aa624c
34 changed files with 788 additions and 843 deletions

View File

@ -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 \

View File

@ -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);

View File

@ -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 <svg> 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);

View File

@ -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();

View File

@ -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 = $('<style id="fc_rules"><\/style>').appendTo('head');
}
fc_rules.text(!on?"":" #tool_topath { display: none !important; }");
$('#foreignObject_panel').toggle(on);
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);
};
function showPanel(on) {
var fc_rules = $('#fc_rules');
if(!fc_rules.length) {
fc_rules = $('<style id="fc_rules"><\/style>').appendTo('head');
}
fc_rules.text(!on?"":" #tool_topath { display: none !important; }");
$('#foreignObject_panel').toggle(on);
}
function toggleSourceButtons(on) {
$('#tool_source_save, #tool_source_cancel').toggle(!on);
$('#foreign_save, #foreign_cancel').toggle(on);
}
// Function: setForeignString(xmlString, elt)
// This function sets the content of element elt to the input XML.
//
// Parameters:
// xmlString - The XML text.
// elt - the parent element to append to
//
// Returns:
// This function returns false if the set was unsuccessful, true otherwise.
function setForeignString(xmlString) {
var elt = selElems[0];
try {
// convert string into XML document
var newDoc = Utils.text2xml('<svg xmlns="' + NS.SVG + '" xmlns:xlink="' + NS.XLINK + '">' + xmlString + '</svg>');
// run it through our sanitizer to remove anything we do not support
S.sanitizeSvg(newDoc.documentElement);
elt.parentNode.replaceChild(svgdoc.importNode(newDoc.documentElement.firstChild, true), elt);
S.call("changed", [elt]);
svgCanvas.clearSelection();
} catch(e) {
console.log(e);
return false;
}
function toggleSourceButtons(on) {
$('#tool_source_save, #tool_source_cancel').toggle(!on);
$('#foreign_save, #foreign_cancel').toggle(on);
}
// Function: setForeignString(xmlString, elt)
// This function sets the content of element elt to the input XML.
//
// Parameters:
// xmlString - The XML text.
// elt - the parent element to append to
//
// Returns:
// This function returns false if the set was unsuccessful, true otherwise.
function setForeignString(xmlString) {
var elt = selElems[0];
try {
// convert string into XML document
var newDoc = Utils.text2xml('<svg xmlns="'+svgns+'" xmlns:xlink="'+xlinkns+'">'+xmlString+'</svg>');
// run it through our sanitizer to remove anything we do not support
S.sanitizeSvg(newDoc.documentElement);
elt.parentNode.replaceChild(svgdoc.importNode(newDoc.documentElement.firstChild, true), elt);
S.call("changed", [elt]);
svgCanvas.clearSelection();
} catch(e) {
console.log(e);
return false;
}
return true;
};
return true;
}
function showForeignEditor() {
var elt = selElems[0];
if (!elt || editingforeign) return;
editingforeign = true;
toggleSourceButtons(true);
elt.removeAttribute('fill');
function showForeignEditor() {
var elt = selElems[0];
if (!elt || editingforeign) return;
editingforeign = true;
toggleSourceButtons(true);
elt.removeAttribute('fill');
var str = S.svgToString(elt, 0);
$('#svg_source_textarea').val(str);
$('#svg_source_editor').fadeIn();
properlySourceSizeTextArea();
$('#svg_source_textarea').focus();
}
function setAttr(attr, val) {
svgCanvas.changeSelectedAttribute(attr, val);
S.call("changed", selElems);
}
return {
name: "foreignObject",
svgicons: "extensions/foreignobject-icons.xml",
buttons: [{
id: "tool_foreign",
type: "mode",
title: "Foreign Object Tool",
events: {
'click': function() {
svgCanvas.setMode('foreign')
}
}
},{
id: "edit_foreign",
type: "context",
panel: "foreignObject_panel",
title: "Edit ForeignObject Content",
events: {
'click': function() {
showForeignEditor();
}
}
}],
context_tools: [{
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's width",
id: "foreign_width",
label: "w",
size: 3,
events: {
change: function() {
setAttr('width', this.value);
}
}
},{
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's height",
id: "foreign_height",
label: "h",
events: {
change: function() {
setAttr('height', this.value);
}
}
}, {
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's font size",
id: "foreign_font_size",
label: "font-size",
size: 2,
defval: 16,
events: {
change: function() {
setAttr('font-size', this.value);
}
var str = S.svgToString(elt, 0);
$('#svg_source_textarea').val(str);
$('#svg_source_editor').fadeIn();
properlySourceSizeTextArea();
$('#svg_source_textarea').focus();
}
function setAttr(attr, val) {
svgCanvas.changeSelectedAttribute(attr, val);
S.call("changed", selElems);
}
return {
name: "foreignObject",
svgicons: "extensions/foreignobject-icons.xml",
buttons: [{
id: "tool_foreign",
type: "mode",
title: "Foreign Object Tool",
events: {
'click': function() {
svgCanvas.setMode('foreign')
}
}
],
callback: function() {
$('#foreignObject_panel').hide();
var endChanges = function() {
$('#svg_source_editor').hide();
editingforeign = false;
$('#svg_source_textarea').blur();
toggleSourceButtons(false);
},{
id: "edit_foreign",
type: "context",
panel: "foreignObject_panel",
title: "Edit ForeignObject Content",
events: {
'click': function() {
showForeignEditor();
}
}
}],
// TODO: Needs to be done after orig icon loads
setTimeout(function() {
// Create source save/cancel buttons
var save = $('#tool_source_save').clone()
.hide().attr('id', 'foreign_save').unbind()
.appendTo("#tool_source_back").click(function() {
if (!editingforeign) return;
context_tools: [{
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's width",
id: "foreign_width",
label: "w",
size: 3,
events: {
change: function() {
setAttr('width', this.value);
}
}
},{
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's height",
id: "foreign_height",
label: "h",
events: {
change: function() {
setAttr('height', this.value);
}
}
}, {
type: "input",
panel: "foreignObject_panel",
title: "Change foreignObject's font size",
id: "foreign_font_size",
label: "font-size",
size: 2,
defval: 16,
events: {
change: function() {
setAttr('font-size', this.value);
}
}
}
if (!setForeignString($('#svg_source_textarea').val())) {
$.confirm("Errors found. Revert to original?", function(ok) {
if(!ok) return false;
endChanges();
});
} else {
],
callback: function() {
$('#foreignObject_panel').hide();
var endChanges = function() {
$('#svg_source_editor').hide();
editingforeign = false;
$('#svg_source_textarea').blur();
toggleSourceButtons(false);
}
// TODO: Needs to be done after orig icon loads
setTimeout(function() {
// Create source save/cancel buttons
var save = $('#tool_source_save').clone()
.hide().attr('id', 'foreign_save').unbind()
.appendTo("#tool_source_back").click(function() {
if (!editingforeign) return;
if (!setForeignString($('#svg_source_textarea').val())) {
$.confirm("Errors found. Revert to original?", function(ok) {
if(!ok) return false;
endChanges();
}
// setSelectMode();
});
var cancel = $('#tool_source_cancel').clone()
.hide().attr('id', 'foreign_cancel').unbind()
.appendTo("#tool_source_back").click(function() {
endChanges();
});
}, 3000);
},
mouseDown: function(opts) {
var e = opts.event;
if(svgCanvas.getMode() == "foreign") {
started = true;
newFO = S.addSvgElementFromJson({
"element": "foreignObject",
"attr": {
"x": opts.start_x,
"y": opts.start_y,
"id": S.getNextId(),
"font-size": 16, //cur_text.font_size,
"width": "48",
"height": "20",
"style": "pointer-events:inherit"
}
});
var m = svgdoc.createElementNS(mathns, 'math');
m.setAttributeNS(xmlnsns, 'xmlns', mathns);
m.setAttribute('display', 'inline');
var mi = svgdoc.createElementNS(mathns, 'mi');
mi.setAttribute('mathvariant', 'normal');
mi.textContent = "\u03A6";
var mo = svgdoc.createElementNS(mathns, 'mo');
mo.textContent = "\u222A";
var mi2 = svgdoc.createElementNS(mathns, 'mi');
mi2.textContent = "\u2133";
m.appendChild(mi);
m.appendChild(mo);
m.appendChild(mi2);
newFO.appendChild(m);
return {
started: true
}
}
},
mouseUp: function(opts) {
var e = opts.event;
if(svgCanvas.getMode() == "foreign" && started) {
var attrs = $(newFO).attr(["width", "height"]);
keep = (attrs.width != 0 || attrs.height != 0);
svgCanvas.addToSelection([newFO], true);
return {
keep: keep,
element: newFO
}
}
},
selectedChanged: function(opts) {
// Use this to update the current selected elements
selElems = opts.elems;
var i = selElems.length;
while(i--) {
var elem = selElems[i];
if(elem && elem.tagName == "foreignObject") {
if(opts.selectedElement && !opts.multiselected) {
$('#foreign_font_size').val(elem.getAttribute("font-size"));
$('#foreign_width').val(elem.getAttribute("width"));
$('#foreign_height').val(elem.getAttribute("height"));
showPanel(true);
});
} else {
showPanel(false);
endChanges();
}
// setSelectMode();
});
var cancel = $('#tool_source_cancel').clone()
.hide().attr('id', 'foreign_cancel').unbind()
.appendTo("#tool_source_back").click(function() {
endChanges();
});
}, 3000);
},
mouseDown: function(opts) {
var e = opts.event;
if(svgCanvas.getMode() == "foreign") {
started = true;
newFO = S.addSvgElementFromJson({
"element": "foreignObject",
"attr": {
"x": opts.start_x,
"y": opts.start_y,
"id": S.getNextId(),
"font-size": 16, //cur_text.font_size,
"width": "48",
"height": "20",
"style": "pointer-events:inherit"
}
});
var m = svgdoc.createElementNS(NS.MATH, 'math');
m.setAttributeNS(NS.XMLNS, 'xmlns', NS.MATH);
m.setAttribute('display', 'inline');
var mi = svgdoc.createElementNS(NS.MATH, 'mi');
mi.setAttribute('mathvariant', 'normal');
mi.textContent = "\u03A6";
var mo = svgdoc.createElementNS(NS.MATH, 'mo');
mo.textContent = "\u222A";
var mi2 = svgdoc.createElementNS(NS.MATH, 'mi');
mi2.textContent = "\u2133";
m.appendChild(mi);
m.appendChild(mo);
m.appendChild(mi2);
newFO.appendChild(m);
return {
started: true
}
}
},
mouseUp: function(opts) {
var e = opts.event;
if(svgCanvas.getMode() == "foreign" && started) {
var attrs = $(newFO).attr(["width", "height"]);
keep = (attrs.width != 0 || attrs.height != 0);
svgCanvas.addToSelection([newFO], true);
return {
keep: keep,
element: newFO
}
}
},
selectedChanged: function(opts) {
// Use this to update the current selected elements
selElems = opts.elems;
var i = selElems.length;
while(i--) {
var elem = selElems[i];
if(elem && elem.tagName == "foreignObject") {
if(opts.selectedElement && !opts.multiselected) {
$('#foreign_font_size').val(elem.getAttribute("font-size"));
$('#foreign_width').val(elem.getAttribute("width"));
$('#foreign_height').val(elem.getAttribute("height"));
showPanel(true);
} else {
showPanel(false);
}
} else {
showPanel(false);
}
},
elementChanged: function(opts) {
var elem = opts.elems[0];
}
};
},
elementChanged: function(opts) {
var elem = opts.elems[0];
}
};
});

View File

@ -14,8 +14,8 @@
svgEditor.addExtension('view_grid', function() {
var svgdoc = document.getElementById('svgcanvas').ownerDocument,
svgns = 'http://www.w3.org/2000/svg',
var NS = svgedit.NS,
svgdoc = document.getElementById('svgcanvas').ownerDocument,
showGrid = false,
assignAttributes = svgCanvas.assignAttributes,
hcanvas = document.createElement('canvas'),
@ -25,7 +25,7 @@ svgEditor.addExtension('view_grid', function() {
$(hcanvas).hide().appendTo('body');
var canvasGrid = svgdoc.createElementNS(svgns, 'svg');
var canvasGrid = svgdoc.createElementNS(NS.SVG, 'svg');
assignAttributes(canvasGrid, {
'id': 'canvasGrid',
'width': '100%',
@ -38,7 +38,7 @@ svgEditor.addExtension('view_grid', function() {
canvBG.append(canvasGrid);
// grid-pattern
var gridPattern = svgdoc.createElementNS(svgns, 'pattern');
var gridPattern = svgdoc.createElementNS(NS.SVG, 'pattern');
assignAttributes(gridPattern, {
'id': 'gridpattern',
'patternUnits': 'userSpaceOnUse',
@ -48,7 +48,7 @@ svgEditor.addExtension('view_grid', function() {
'height': 100
});
var gridimg = svgdoc.createElementNS(svgns, 'image');
var gridimg = svgdoc.createElementNS(NS.SVG, 'image');
assignAttributes(gridimg, {
'x': 0,
'y': 0,
@ -59,7 +59,7 @@ svgEditor.addExtension('view_grid', function() {
$('#svgroot defs').append(gridPattern);
// grid-box
var gridBox = svgdoc.createElementNS(svgns, 'rect');
var gridBox = svgdoc.createElementNS(NS.SVG, 'rect');
assignAttributes(gridBox, {
'width': '100%',
'height': '100%',

View File

@ -10,7 +10,7 @@
svgEditor.addExtension("imagelib", function() {
var uiStrings = svgEditor.uiStrings;
$.extend(uiStrings, {
imagelib: {
select_lib: 'Select an image library',
@ -25,20 +25,18 @@ svgEditor.addExtension("imagelib", function() {
name: 'Demo library (local)',
url: 'extensions/imagelib/index.html',
description: 'Demonstration library for SVG-edit on this server'
},
},
{
name: 'IAN Symbol Libraries',
url: 'http://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php',
description: 'Free library of illustrations'
}
];
var xlinkns = "http://www.w3.org/1999/xlink";
function closeBrowser() {
$('#imgbrowse_holder').hide();
}
function importImage(url) {
var newImage = svgCanvas.addSvgElementFromJson({
"element": "image",

View File

@ -8,7 +8,11 @@
*/
svgEditor.addExtension("polygon", 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", editingitex = false, svgdoc = S.svgroot.parentNode.ownerDocument, started, newFO, edg = 0, newFOG, newFOGParent, newDef, newImageName, newMaskID, undoCommand = "Not image", modeChangeG;
var NS = svgedit.NS,
svgcontent = S.svgcontent,
addElem = S.addSvgElementFromJson,
selElems,
editingitex = false, svgdoc = S.svgroot.parentNode.ownerDocument, started, newFO, edg = 0, newFOG, newFOGParent, newDef, newImageName, newMaskID, undoCommand = "Not image", modeChangeG;
var ccZoom;
var wEl, hEl;
@ -175,7 +179,7 @@ svgEditor.addExtension("polygon", function(S){
points += x + ',' + y + ' ';
}
//var poly = newFO.createElementNS(svgns, 'polygon');
//var poly = newFO.createElementNS(NS.SVG, 'polygon');
newFO.setAttributeNS(null, 'points', points);
newFO.setAttributeNS(null, 'fill', fill);
newFO.setAttributeNS(null, 'stroke', strokecolor);

View File

@ -9,14 +9,9 @@
svgEditor.addExtension('star', function(S){
var svgcontent = S.svgcontent,
var NS = svgedit.NS,
svgcontent = S.svgcontent,
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',
editingitex = false,
svgdoc = S.svgroot.parentNode.ownerDocument,
started,

View File

@ -11,8 +11,6 @@
// 2) svgtransformlist.js
// 3) svgutils.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.history) {
@ -20,8 +18,6 @@ if (!svgedit.history) {
}
// Group: Undo/Redo history management
svgedit.history.HistoryEventTypes = {
BEFORE_APPLY: 'before_apply',
AFTER_APPLY: 'after_apply',

View File

@ -10,8 +10,6 @@
// Dependencies:
// None.
var svgedit = svgedit || {};
(function() {
if (!svgedit.math) {
@ -22,7 +20,7 @@ if (!svgedit.math) {
var NEAR_ZERO = 1e-14;
// Throw away SVGSVGElement used for creating matrices/transforms.
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
// Function: svgedit.math.transformPoint
// A (hopefully) quicker function to transform a point by a matrix

View File

@ -13,16 +13,13 @@
// 3) math.js
// 4) svgutils.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.path) {
svgedit.path = {};
}
var svgns = 'http://www.w3.org/2000/svg';
var NS = svgedit.NS;
var uiStrings = {
'pathNodeTooltip': 'Drag node to move it. Double-click node to change segment type',
'pathCtrlPtTooltip': 'Drag control point to adjust curve properties'
@ -143,7 +140,7 @@ svgedit.path.addPointGrip = function(index, x, y) {
var pointGrip = svgedit.utilities.getElem('pathpointgrip_'+index);
// create it
if (!pointGrip) {
pointGrip = document.createElementNS(svgns, 'circle');
pointGrip = document.createElementNS(NS.SVG, 'circle');
svgedit.utilities.assignAttributes(pointGrip, {
'id': 'pathpointgrip_' + index,
'display': 'none',
@ -177,7 +174,7 @@ svgedit.path.getGripContainer = function() {
var c = svgedit.utilities.getElem('pathpointgrip_container');
if (!c) {
var parent = svgedit.utilities.getElem('selectorParentGroup');
c = parent.appendChild(document.createElementNS(svgns, 'g'));
c = parent.appendChild(document.createElementNS(NS.SVG, 'g'));
c.id = 'pathpointgrip_container';
}
return c;
@ -187,7 +184,7 @@ svgedit.path.addCtrlGrip = function(id) {
var pointGrip = svgedit.utilities.getElem('ctrlpointgrip_'+id);
if (pointGrip) return pointGrip;
pointGrip = document.createElementNS(svgns, 'circle');
pointGrip = document.createElementNS(NS.SVG, 'circle');
svgedit.utilities.assignAttributes(pointGrip, {
'id': 'ctrlpointgrip_' + id,
'display': 'none',
@ -207,7 +204,7 @@ svgedit.path.getCtrlLine = function(id) {
var ctrlLine = svgedit.utilities.getElem('ctrlLine_'+id);
if (ctrlLine) return ctrlLine;
ctrlLine = document.createElementNS(svgns, 'line');
ctrlLine = document.createElementNS(NS.SVG, 'line');
svgedit.utilities.assignAttributes(ctrlLine, {
'id': 'ctrlLine_'+id,
'stroke': '#555',
@ -310,7 +307,7 @@ svgedit.path.getSegSelector = function(seg, update) {
if (!segLine) {
var pointGripContainer = svgedit.path.getGripContainer();
// create segline
segLine = document.createElementNS(svgns, 'path');
segLine = document.createElementNS(NS.SVG, 'path');
svgedit.utilities.assignAttributes(segLine, {
'id': 'segline_' + index,
'display': 'none',

View File

@ -12,40 +12,14 @@
// 2) browser.js
// 3) svgutils.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.sanitize) {
svgedit.sanitize = {};
}
// Namespace constants
var 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/', // see http://www.w3.org/TR/REC-xml-names/#xmlReserved
htmlns = 'http://www.w3.org/1999/xhtml',
mathns = 'http://www.w3.org/1998/Math/MathML',
se_ns = 'http://svg-edit.googlecode.com';
// map namespace URIs to prefixes
var nsMap_ = {};
nsMap_[xlinkns] = 'xlink';
nsMap_[xmlns] = 'xml';
nsMap_[xmlnsns] = 'xmlns';
nsMap_[htmlns] = 'xhtml';
nsMap_[mathns] = 'mathml';
nsMap_[se_ns] = 'se';
// temporarily expose these
svgedit.sanitize.getNSMap = function() { return nsMap_; }
// map prefixes to namespace URIs (reverse of nsMap_)
var nsRevMap_ = {};
$.each(nsMap_, function(key, value){
nsRevMap_[value] = key;
});
var NS = svgedit.NS,
REVERSE_NS = svgedit.getReverseNS();
// this defines which elements and attributes that we support
var svgWhiteList_ = {
@ -54,7 +28,7 @@ var svgWhiteList_ = {
"circle": ["class", "clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "mask", "opacity", "r", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
"clipPath": ["class", "clipPathUnits", "id"],
"defs": [],
"style" : ["type"],
"style" : ["type"],
"desc": [],
"ellipse": ["class", "clip-path", "clip-rule", "cx", "cy", "fill", "fill-opacity", "fill-rule", "filter", "id", "mask", "opacity", "requiredFeatures", "rx", "ry", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform"],
"feGaussianBlur": ["class", "color-interpolation-filters", "id", "requiredFeatures", "stdDeviation"],
@ -82,7 +56,7 @@ var svgWhiteList_ = {
"title": [],
"tspan": ["class", "clip-path", "clip-rule", "dx", "dy", "fill", "fill-opacity", "fill-rule", "filter", "font-family", "font-size", "font-style", "font-weight", "id", "mask", "opacity", "requiredFeatures", "rotate", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "text-anchor", "textLength", "transform", "x", "xml:space", "y"],
"use": ["class", "clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "height", "id", "mask", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "transform", "width", "x", "xlink:href", "y"],
// MathML Elements
"annotation": ["encoding"],
"annotation-xml": ["encoding"],
@ -124,9 +98,9 @@ $.each(svgWhiteList_, function(elt, atts){
$.each(atts, function(i, att){
if (att.indexOf(':') >= 0) {
var v = att.split(':');
attNS[v[1]] = nsRevMap_[v[0]];
attNS[v[1]] = NS[(v[0]).toUpperCase()];
} else {
attNS[att] = att == 'xmlns' ? xmlnsns : null;
attNS[att] = att == 'xmlns' ? NS.XMLNS : null;
}
});
svgWhiteListNS_[elt] = attNS;
@ -177,15 +151,15 @@ svgedit.sanitize.sanitizeSvg = function(node) {
var attrNsURI = attr.namespaceURI;
// Check that an attribute with the correct localName in the correct namespace is on
// our whitelist or is a namespace declaration for one of our allowed namespaces
if (!(allowedAttrsNS.hasOwnProperty(attrLocalName) && attrNsURI == allowedAttrsNS[attrLocalName] && attrNsURI != xmlnsns) &&
!(attrNsURI == xmlnsns && nsMap_[attr.nodeValue]) )
if (!(allowedAttrsNS.hasOwnProperty(attrLocalName) && attrNsURI == allowedAttrsNS[attrLocalName] && attrNsURI != NS.XMLNS) &&
!(attrNsURI == NS.XMLNS && REVERSE_NS[attr.nodeValue]) )
{
// TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist.
// Bypassing the whitelist to allow se: prefixes.
// Is there a more appropriate way to do this?
if(attrName.indexOf('se:') == 0) {
se_attrs.push([attrName, attr.nodeValue]);
}
}
node.removeAttributeNS(attrNsURI, attrLocalName);
}
@ -218,7 +192,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
}
$.each(se_attrs, function(i, attr) {
node.setAttributeNS(se_ns, attr[0], attr[1]);
node.setAttributeNS(NS.SE, attr[0], attr[1]);
});
// for some elements that have a xlink:href, ensure the URI refers to a local element
@ -232,7 +206,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
if (href[0] != '#') {
// remove the attribute (but keep the element)
svgedit.utilities.setHref(node, '');
node.removeAttributeNS(xlinkns, 'href');
node.removeAttributeNS(NS.XLINK, 'href');
}
}

View File

@ -13,8 +13,6 @@
// 3) math.js
// 4) svgutils.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.select) {

View File

@ -28,6 +28,7 @@
<!--{if svg_edit_release}>
<script type="text/javascript" src="svgedit.compiled.js"></script>
<!{else}-->
<script type="text/javascript" src="svgedit.js"></script>
<script type="text/javascript" src="contextmenu/jquery.contextMenu.js"></script>
<script type="text/javascript" src="browser.js"></script>
<script type="text/javascript" src="svgtransformlist.js"></script>

View File

@ -3529,7 +3529,7 @@
testEl.removeAttribute('style');
var svgdocbox = paintBox.fill.rect.ownerDocument;
// Use this to test support for blur element. Seems to work to test support in Webkit
var blurTest = svgdocbox.createElementNS('http://www.w3.org/2000/svg', 'feGaussianBlur');
var blurTest = svgdocbox.createElementNS(svgedit.NS.SVG, 'feGaussianBlur');
if (typeof blurTest.stdDeviationX === 'undefined') {
$('#tool_blur').hide();
}

View File

@ -45,6 +45,7 @@ if (window.opera) {
// as an object with values for each given attributes
var proxied = jQuery.fn.attr,
// TODO use NS.SVG instead
svgns = "http://www.w3.org/2000/svg";
jQuery.fn.attr = function(key, value) {
var len = this.length;
@ -100,14 +101,8 @@ if (window.opera) {
// config - An object that contains configuration data
$.SvgCanvas = function(container, config)
{
// Namespace constants
var 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/", // see http://www.w3.org/TR/REC-xml-names/#xmlReserved
se_ns = "http://svg-edit.googlecode.com",
htmlns = "http://www.w3.org/1999/xhtml",
mathns = "http://www.w3.org/1998/Math/MathML";
// Alias Namespace constants
var NS = svgedit.NS;
// Default configuration options
var curConfig = {
@ -132,7 +127,7 @@ var svgdoc = container.ownerDocument;
// This is a container for the document being edited, not the document itself.
var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
'<svg id="svgroot" xmlns="' + svgns + '" xlinkns="' + xlinkns + '" ' +
'<svg id="svgroot" xmlns="' + NS.SVG + '" xlinkns="' + NS.XLINK + '" ' +
'width="' + dimensions[0] + '" height="' + dimensions[1] + '" x="' + dimensions[0] + '" y="' + dimensions[1] + '" overflow="visible">' +
'<defs>' +
'<filter id="canvashadow" filterUnits="objectBoundingBox">' +
@ -148,7 +143,7 @@ var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
container.appendChild(svgroot);
// The actual element that represents the final output SVG element
var svgcontent = svgdoc.createElementNS(svgns, "svg");
var svgcontent = svgdoc.createElementNS(NS.SVG, "svg");
// This function resets the svgcontent element while keeping it in the DOM.
var clearSvgContentElement = canvas.clearSvgContentElement = function() {
@ -162,9 +157,9 @@ var clearSvgContentElement = canvas.clearSvgContentElement = function() {
x: dimensions[0],
y: dimensions[1],
overflow: curConfig.show_outside_canvas ? 'visible' : 'hidden',
xmlns: svgns,
"xmlns:se": se_ns,
"xmlns:xlink": xlinkns
xmlns: NS.SVG,
"xmlns:se": NS.SE,
"xmlns:xlink": NS.XLINK
}).appendTo(svgroot);
// TODO: make this string optional and set by the client
@ -254,7 +249,7 @@ var addSvgElementFromJson = this.addSvgElementFromJson = function(data) {
shape = null;
}
if (!shape) {
shape = svgdoc.createElementNS(svgns, data.element);
shape = svgdoc.createElementNS(NS.SVG, data.element);
if (current_layer) {
(current_group || current_layer).appendChild(shape);
}
@ -323,7 +318,7 @@ var assignAttributes = canvas.assignAttributes = svgedit.utilities.assignAttribu
var cleanupElement = this.cleanupElement = svgedit.utilities.cleanupElement;
// import from sanitize.js
var nsMap = svgedit.sanitize.getNSMap();
var nsMap = svgedit.getReverseNS();
var sanitizeSvg = canvas.sanitizeSvg = svgedit.sanitize.sanitizeSvg;
// import from history.js
@ -439,7 +434,7 @@ var ref_attrs = ["clip-path", "fill", "filter", "marker-end", "marker-mid", "mar
var elData = $.data;
// Animation element to change the opacity of any newly created element
var opac_ani = document.createElementNS(svgns, 'animate');
var opac_ani = document.createElementNS(NS.SVG, 'animate');
$(opac_ani).attr({
attributeName: 'opacity',
begin: 'indefinite',
@ -473,7 +468,7 @@ var restoreRefElems = function(elem) {
(function() {
// TODO For Issue 208: this is a start on a thumbnail
// var svgthumb = svgdoc.createElementNS(svgns, "use");
// var svgthumb = svgdoc.createElementNS(NS.SVG, "use");
// svgthumb.setAttribute('width', '100');
// svgthumb.setAttribute('height', '100');
// svgedit.utilities.setHref(svgthumb, '#svgcontent');
@ -681,7 +676,7 @@ getStrokedBBox = this.getStrokedBBox = function(elems) {
if (!good_bb) {
// Must use clone else FF freaks out
var clone = elem.cloneNode(true);
var g = document.createElementNS(svgns, "g");
var g = document.createElementNS(NS.SVG, "g");
var parent = elem.parentNode;
parent.appendChild(g);
g.appendChild(clone);
@ -841,7 +836,7 @@ var getVisibleElementsAndBBoxes = this.getVisibleElementsAndBBoxes = function(pa
// Parameters:
// elem - SVG element to wrap
var groupSvgElem = this.groupSvgElem = function(elem) {
var g = document.createElementNS(svgns, "g");
var g = document.createElementNS(NS.SVG, "g");
elem.parentNode.replaceChild(g, elem);
$(g).append(elem).data('gsvg', elem)[0].id = getNextId();
};
@ -946,7 +941,7 @@ this.prepareSvg = function(newDoc) {
this.sanitizeSvg(newDoc.documentElement);
// convert paths into absolute commands
var paths = newDoc.getElementsByTagNameNS(svgns, "path");
var paths = newDoc.getElementsByTagNameNS(NS.SVG, "path");
for (var i = 0, len = paths.length; i < len; ++i) {
var path = paths[i];
path.setAttribute('d', pathActions.convertPath(path));
@ -1672,7 +1667,7 @@ var recalculateDimensions = this.recalculateDimensions = function(selected) {
// TODO: If any <use> have this group as a parent and are
// referencing this child, then we need to impose a reverse
// scale on it so that when it won't get double-translated
// var uses = selected.getElementsByTagNameNS(svgns, "use");
// var uses = selected.getElementsByTagNameNS(NS.SVG, "use");
// var href = "#"+child.id;
// var u = uses.length;
// while (u--) {
@ -1752,7 +1747,7 @@ var recalculateDimensions = this.recalculateDimensions = function(selected) {
// If any <use> have this group as a parent and are
// referencing this child, then impose a reverse translate on it
// so that when it won't get double-translated
var uses = selected.getElementsByTagNameNS(svgns, "use");
var uses = selected.getElementsByTagNameNS(NS.SVG, "use");
var href = "#"+child.id;
var u = uses.length;
while (u--) {
@ -2276,7 +2271,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
// for foreign content, go up until we find the foreignObject
// WebKit browsers set the mouse target to the svgcanvas div
if ([mathns, htmlns].indexOf(mouse_target.namespaceURI) >= 0 &&
if ([NS.MATH, NS.HTML].indexOf(mouse_target.namespaceURI) >= 0 &&
mouse_target.id != "svgcanvas")
{
while (mouse_target.nodeName != "foreignObject") {
@ -3614,7 +3609,7 @@ var textActions = canvas.textActions = function() {
}
cursor = svgedit.utilities.getElem("text_cursor");
if (!cursor) {
cursor = document.createElementNS(svgns, "line");
cursor = document.createElementNS(NS.SVG, "line");
assignAttributes(cursor, {
'id': "text_cursor",
'stroke': "#333",
@ -3658,7 +3653,7 @@ var textActions = canvas.textActions = function() {
selblock = svgedit.utilities.getElem("text_selectblock");
if (!selblock) {
selblock = document.createElementNS(svgns, "path");
selblock = document.createElementNS(NS.SVG, "path");
assignAttributes(selblock, {
'id': "text_selectblock",
'fill': "green",
@ -4118,7 +4113,7 @@ var pathActions = canvas.pathActions = function() {
}
if (!stretchy) {
stretchy = document.createElementNS(svgns, "path");
stretchy = document.createElementNS(NS.SVG, "path");
assignAttributes(stretchy, {
'id': "path_stretch_line",
'stroke': "#22C",
@ -5067,7 +5062,7 @@ var pathActions = canvas.pathActions = function() {
// Returns:
// The amount of elements that were removed
var removeUnusedDefElems = this.removeUnusedDefElems = function() {
var defs = svgcontent.getElementsByTagNameNS(svgns, "defs");
var defs = svgcontent.getElementsByTagNameNS(NS.SVG, "defs");
if (!defs || !defs.length) return 0;
// if (!defs.firstChild) return;
@ -5077,7 +5072,7 @@ var removeUnusedDefElems = this.removeUnusedDefElems = function() {
var attrs = ['fill', 'stroke', 'filter', 'marker-start', 'marker-mid', 'marker-end'];
var alen = attrs.length;
var all_els = svgcontent.getElementsByTagNameNS(svgns, '*');
var all_els = svgcontent.getElementsByTagNameNS(NS.SVG, '*');
var all_len = all_els.length;
for (var i=0; i<all_len; i++) {
@ -5203,7 +5198,7 @@ this.svgToString = function(elem, indent) {
// var unit_m = svgedit.units.getTypeMap()[unit];
// res.w = svgedit.units.shortFloat(res.w / unit_m)
// res.h = svgedit.units.shortFloat(res.h / unit_m)
// vb = ' viewBox="' + [0, 0, res.w, res.h].join(' ') + '"';
// vb = ' viewBox="' + [0, 0, res.w, res.h].join(' ') + '"';
// res.w += unit;
// res.h += unit;
// }
@ -5213,7 +5208,7 @@ this.svgToString = function(elem, indent) {
res.h = svgedit.units.convertUnit(res.h, unit) + unit;
}
out.push(' width="' + res.w + '" height="' + res.h + '"' + vb + ' xmlns="'+svgns+'"');
out.push(' width="' + res.w + '" height="' + res.h + '"' + vb + ' xmlns="'+NS.SVG+'"');
var nsuris = {};
@ -5282,7 +5277,7 @@ this.svgToString = function(elem, indent) {
// map various namespaces to our fixed namespace prefixes
// (the default xmlns attribute itself does not get a prefix)
if (!attr.namespaceURI || attr.namespaceURI == svgns || nsMap[attr.namespaceURI]) {
if (!attr.namespaceURI || attr.namespaceURI == NS.SVG || nsMap[attr.namespaceURI]) {
out.push(attr.nodeName); out.push("=\"");
out.push(attrVal); out.push("\"");
}
@ -5695,7 +5690,7 @@ var convertToGroup = this.convertToGroup = function(elem) {
// See if other elements reference this symbol
var has_more = $(svgcontent).find('use:data(symbol)').length;
var g = svgdoc.createElementNS(svgns, "g");
var g = svgdoc.createElementNS(NS.SVG, "g");
var childs = elem.childNodes;
for (var i = 0; i < childs.length; i++) {
@ -5829,7 +5824,7 @@ this.setSvgString = function(xmlString) {
if (m) {
var url = decodeURIComponent(m[1]);
$(new Image()).load(function() {
image.setAttributeNS(xlinkns, 'xlink:href', url);
image.setAttributeNS(NS.XLINK, 'xlink:href', url);
}).attr('src', url);
}
}
@ -6029,7 +6024,7 @@ this.importSvgString = function(xmlString) {
// Hack to make recalculateDimensions understand how to scale
ts = "translate(0) " + ts + " translate(0)";
var symbol = svgdoc.createElementNS(svgns, "symbol");
var symbol = svgdoc.createElementNS(NS.SVG, "symbol");
var defs = svgedit.utilities.findDefs();
if (svgedit.browser.isGecko()) {
@ -6060,7 +6055,7 @@ this.importSvgString = function(xmlString) {
batchCmd.addSubCommand(new InsertElementCommand(symbol));
}
var use_el = svgdoc.createElementNS(svgns, "use");
var use_el = svgdoc.createElementNS(NS.SVG, "use");
use_el.id = getNextId();
setHref(use_el, "#" + symbol.id);
@ -6124,8 +6119,8 @@ this.createLayer = function(name) {
// name - The given name
this.cloneLayer = function(name) {
var batchCmd = new BatchCommand("Duplicate Layer");
var new_layer = svgdoc.createElementNS(svgns, "g");
var layer_title = svgdoc.createElementNS(svgns, "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);
var current_layer = getCurrentDrawing().getCurrentLayer();
@ -6575,7 +6570,7 @@ this.setGroupTitle = function(val) {
title.textContent = val;
} else {
// Add title element
title = svgdoc.createElementNS(svgns, "title");
title = svgdoc.createElementNS(NS.SVG, "title");
title.textContent = val;
$(elem).prepend(title);
batchCmd.addSubCommand(new InsertElementCommand(title));
@ -6609,7 +6604,7 @@ this.setDocumentTitle = function(newtitle) {
}
}
if (!doc_title) {
doc_title = svgdoc.createElementNS(svgns, "title");
doc_title = svgdoc.createElementNS(NS.SVG, "title");
svgcontent.insertBefore(doc_title, svgcontent.firstChild);
}
@ -6630,9 +6625,9 @@ this.setDocumentTitle = function(newtitle) {
// add - Boolean to indicate whether or not to add the namespace value
this.getEditorNS = function(add) {
if (add) {
svgcontent.setAttribute('xmlns:se', se_ns);
svgcontent.setAttribute('xmlns:se', NS.SE);
}
return se_ns;
return NS.SE;
};
// Function: setResolution
@ -6904,8 +6899,8 @@ var findDuplicateGradient = function(grad) {
}
// else could be a duplicate, iterate through stops
var stops = grad.getElementsByTagNameNS(svgns, "stop");
var ostops = og.getElementsByTagNameNS(svgns, "stop");
var stops = grad.getElementsByTagNameNS(NS.SVG, "stop");
var ostops = og.getElementsByTagNameNS(NS.SVG, "stop");
if (stops.length != ostops.length) {
continue;
@ -8700,7 +8695,7 @@ this.setBackground = function(color, url) {
border.setAttribute('fill', color);
if (url) {
if (!bg_img) {
bg_img = svgdoc.createElementNS(svgns, "image");
bg_img = svgdoc.createElementNS(NS.SVG, "image");
assignAttributes(bg_img, {
'id': 'background_image',
'width': '100%',

27
editor/svgedit.js Normal file
View File

@ -0,0 +1,27 @@
/**
*
* Licensed under the MIT License
* main object, loaded first so other modules have the garanty of its existence
*/
svgedit = {
// common namepaces constants in alpha order
NS: {
HTML: 'http://www.w3.org/1999/xhtml',
MATH: 'http://www.w3.org/1998/Math/MathML',
SE: 'http://svg-edit.googlecode.com',
SVG: 'http://www.w3.org/2000/svg',
XLINK: 'http://www.w3.org/1999/xlink',
XML: 'http://www.w3.org/XML/1998/namespace',
XMLNS: 'http://www.w3.org/2000/xmlns/' // see http://www.w3.org/TR/REC-xml-names/#xmlReserved
}
};
// return the svgedit.NS with key values switched and lowercase
svgedit.getReverseNS = function() {
var reverseNS = {};
$.each(this.NS, function(name, URI) {
reverseNS[URI] = name.toLowerCase();
});
return reverseNS;
};

View File

@ -10,15 +10,13 @@
// Dependencies:
// 1) browser.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.transformlist) {
svgedit.transformlist = {};
}
var svgroot = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var svgroot = document.createElementNS(svgedit.NS.SVG, 'svg');
// Helper function.
function transformToString(xform) {

View File

@ -12,8 +12,6 @@
// 2) browser.js
// 3) svgtransformlist.js
var svgedit = svgedit || {};
(function() {
if (!svgedit.utilities) {
@ -24,9 +22,7 @@ if (!svgedit.utilities) {
// String used to encode base64.
var KEYSTR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var SVGNS = 'http://www.w3.org/2000/svg';
var XLINKNS = 'http://www.w3.org/1999/xlink';
var XMLNS = 'http://www.w3.org/XML/1998/namespace';
var NS = svgedit.NS;
// Much faster than running getBBox() every time
var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use';
@ -298,13 +294,13 @@ svgedit.utilities.getUrlFromAttr = function(attrVal) {
// Function: svgedit.utilities.getHref
// Returns the given element's xlink:href value
svgedit.utilities.getHref = function(elem) {
return elem.getAttributeNS(XLINKNS, 'href');
return elem.getAttributeNS(NS.XLINK, 'href');
}
// Function: svgedit.utilities.setHref
// Sets the given element's xlink:href value
svgedit.utilities.setHref = function(elem, val) {
elem.setAttributeNS(XLINKNS, 'xlink:href', val);
elem.setAttributeNS(NS.XLINK, 'xlink:href', val);
}
// Function: findDefs
@ -313,11 +309,11 @@ svgedit.utilities.setHref = function(elem, val) {
// The document's <defs> element, create it first if necessary
svgedit.utilities.findDefs = function() {
var svgElement = editorContext_.getSVGContent();
var defs = svgElement.getElementsByTagNameNS(SVGNS, 'defs');
var defs = svgElement.getElementsByTagNameNS(NS.SVG, 'defs');
if (defs.length > 0) {
defs = defs[0];
} else {
defs = svgElement.ownerDocument.createElementNS(SVGNS, 'defs');
defs = svgElement.ownerDocument.createElementNS(NS.SVG, 'defs');
if (svgElement.firstChild) {
// first child is a comment, so call nextSibling
svgElement.insertBefore(defs, svgElement.firstChild.nextSibling);
@ -582,7 +578,7 @@ if (svgedit.browser.supportsSelectors()) {
return domdoc_.evaluate(
'svg:svg[@id="svgroot"]//svg:*[@id="'+id+'"]',
domcontainer_,
function() { return 'http://www.w3.org/2000/svg'; },
function() { return svgedit.NS.SVG; },
9,
null).singleNodeValue;
};
@ -608,8 +604,8 @@ svgedit.utilities.assignAttributes = function(node, attrs, suspendLength, unitCh
if (!svgedit.browser.isOpera()) svgroot_.suspendRedraw(suspendLength);
for (var i in attrs) {
var ns = (i.substr(0,4) === 'xml:' ? XMLNS :
i.substr(0,6) === 'xlink:' ? XLINKNS : null);
var ns = (i.substr(0,4) === 'xml:' ? NS.XML :
i.substr(0,6) === 'xlink:' ? NS.XLINK : null);
if(ns) {
node.setAttributeNS(ns, i, attrs[i]);

View File

@ -1,30 +1,27 @@
// http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript/
function touchHandler(event) {
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type="mousedown"; break;
case "touchmove": type="mousemove"; break;
case "touchend": type="mouseup"; break;
default: return;
}
var touches = event.changedTouches,
first = touches[0],
type = "";
switch (event.type) {
case "touchstart": type = "mousedown"; break;
case "touchmove": type = "mousemove"; break;
case "touchend": type = "mouseup"; break;
default: return;
}
//initMouseEvent(type, canBubble, cancelable, view, clickCount,
// screenX, screenY, clientX, clientY, ctrlKey,
// altKey, shiftKey, metaKey, button, relatedTarget);
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
if(touches.length < 2) {
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
// initMouseEvent(type, canBubble, cancelable, view, clickCount,
// screenX, screenY, clientX, clientY, ctrlKey,
// altKey, shiftKey, metaKey, button, relatedTarget);
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
if (touches.length < 2) {
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
}

View File

@ -10,14 +10,13 @@
// Dependencies:
// 1) jQuery
var svgedit = svgedit || {};
(function() {
if (!svgedit.units) {
svgedit.units = {};
}
var NS = svgedit.NS;
var wAttrs = ['x', 'x1', 'cx', 'rx', 'width'];
var hAttrs = ['y', 'y1', 'cy', 'ry', 'height'];
var unitAttrs = ['r', 'radius'].concat(wAttrs, hAttrs);
@ -62,12 +61,10 @@ var typeMap_ = {};
svgedit.units.init = function(elementContainer) {
elementContainer_ = elementContainer;
var svgns = 'http://www.w3.org/2000/svg';
// Get correct em/ex values by creating a temporary SVG.
var svg = document.createElementNS(svgns, 'svg');
var svg = document.createElementNS(NS.SVG, 'svg');
document.body.appendChild(svg);
var rect = document.createElementNS(svgns, 'rect');
var rect = document.createElementNS(NS.SVG, 'rect');
rect.setAttribute('width', '1em');
rect.setAttribute('height', '1ex');
rect.setAttribute('x', '1in');

View File

@ -1,19 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script>
// Mock for browser.js
window.svgedit = {};
window.svgEditor = {ready:function(){}};
</script>
<script type='text/javascript' src='../editor/contextmenu.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script>
// Mock for browser.js
window.svgEditor = {ready:function(){}};
</script>
<script src='../editor/contextmenu.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
@ -22,62 +21,62 @@
function tearDown(){
svgedit.contextmenu.resetCustomMenus();
}
module('svgedit.contextmenu');
test('Test svgedit.contextmenu package', function() {
expect(4);
ok(svgedit.contextmenu,"contextmenu registered correctly");
ok(svgedit.contextmenu.add,"contextmenu.add registered correctly");
ok(svgedit.contextmenu.hasCustomHandler,"contextmenu hasCustomHandler registered correctly");
ok(svgedit.contextmenu.getCustomHandler,"contextmenu getCustomHandler registered correctly");
});
test('Test svgedit.contextmenu does not add invalid menu item', function() {
expect(3);
svgedit.contextmenu.add({id:"justanid"});
ok(!svgedit.contextmenu.hasCustomHandler("justanid"),"menu item with just an id is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel"});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with just an id and label is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel",action:'notafunction'});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with action that is not a function is invalid");
});
test('Test svgedit.contextmenu adds valid menu item', function() {
expect(2);
var validItem = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
svgedit.contextmenu.add(validItem);
ok(svgedit.contextmenu.hasCustomHandler("valid"),"Valid menu item is added.");
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem.action,"Valid menu action is added.");
tearDown();
});
test('Test svgedit.contextmenu rejects valid duplicate menu item id', function() {
expect(1);
var validItem1 = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
var validItem2 = {id:"valid",label:"anicelabel",action:function(){alert('testingtwice')}};
svgedit.contextmenu.add(validItem1);
svgedit.contextmenu.add(validItem2);
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem1.action,"duplicate menu item is rejected.");
tearDown();
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for contextmenu.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for contextmenu.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,14 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/browser.js'></script>
<script type='text/javascript' src='../editor/svgutils.js'></script>
<script type='text/javascript' src='../editor/sanitize.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/sanitize.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
@ -16,17 +17,16 @@
}
};
var svgns = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(svgns, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
// TODO: Since recalculateDimensions() and surrounding code is
// probably the largest, most complicated and strange piece of
// code in SVG-edit, we need to write a whole lot of unit tests
// for it here.
});
</script>
</head>
<body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgedit.coords</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
@ -34,5 +34,5 @@
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
</body>
</body>
</html>

View File

@ -1,73 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/browser.js'></script>
<script type='text/javascript' src='../editor/svgutils.js'></script>
<script type='text/javascript' src='../editor/draw.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/draw.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var SVGNS = 'http://www.w3.org/2000/svg';
var SENS = "http://svg-edit.googlecode.com";
var XMLNSNS = "http://www.w3.org/2000/xmlns/";
var NS = svgedit.NS;
var NONCE = 'foo';
var LAYER1 = 'Layer 1';
var LAYER2 = 'Layer 2';
var LAYER3 = 'Layer 3';
var svg = document.createElementNS(SVGNS, 'svg');
var svg = document.createElementNS(NS.SVG, 'svg');
// Set up <svg> with nonce.
var svg_n = document.createElementNS(SVGNS, 'svg');
svg_n.setAttributeNS(XMLNSNS, 'xmlns:se', SENS);
svg_n.setAttributeNS(SENS, 'se:nonce', NONCE);
var svg_n = document.createElementNS(NS.SVG, 'svg');
svg_n.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
svg_n.setAttributeNS(NS.SE, 'se:nonce', NONCE);
var setupSvgWith3Layers = function(svgElem) {
var layer1 = document.createElementNS(SVGNS, 'g');
var layer1_title = document.createElementNS(SVGNS, 'title');
var layer1 = document.createElementNS(NS.SVG, 'g');
var layer1_title = document.createElementNS(NS.SVG, 'title');
layer1_title.appendChild(document.createTextNode(LAYER1));
layer1.appendChild(layer1_title);
svgElem.appendChild(layer1);
var layer2 = document.createElementNS(SVGNS, 'g');
var layer2_title = document.createElementNS(SVGNS, 'title');
var layer2 = document.createElementNS(NS.SVG, 'g');
var layer2_title = document.createElementNS(NS.SVG, 'title');
layer2_title.appendChild(document.createTextNode(LAYER2));
layer2.appendChild(layer2_title);
svgElem.appendChild(layer2);
var layer3 = document.createElementNS(SVGNS, 'g');
var layer3_title = document.createElementNS(SVGNS, 'title');
var layer3 = document.createElementNS(NS.SVG, 'g');
var layer3_title = document.createElementNS(NS.SVG, 'title');
layer3_title.appendChild(document.createTextNode(LAYER3));
layer3.appendChild(layer3_title);
svgElem.appendChild(layer3);
};
var cleanupSvg = function(svgElem) {
while(svgElem.firstChild) {svgElem.removeChild(svgElem.firstChild);}
};
test('Test draw module', function() {
expect(4);
ok(svgedit.draw);
equals(typeof svgedit.draw, typeof {});
ok(svgedit.draw.Drawing);
equals(typeof svgedit.draw.Drawing, typeof function(){});
});
test('Test document creation', function() {
expect(3);
try {
var doc = new svgedit.draw.Drawing();
ok(false, 'Created drawing without a valid <svg> element');
@ -92,21 +90,21 @@
doc = new svgedit.draw.Drawing(svg_n);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(SENS, 'nonce'), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
doc.clearNonce();
ok(!doc.getNonce());
ok(!doc.getSvgElem().getAttributeNS(SENS, 'se:nonce'));
ok(!doc.getSvgElem().getAttributeNS(NS.SE, 'se:nonce'));
doc.setNonce(NONCE);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(SENS, 'nonce'), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
});
test('Test getId() and getNextId() without nonce', function() {
expect(7);
var elem2 = document.createElementNS(SVGNS, 'circle');
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = 'svg_2';
svg.appendChild(elem2);
@ -122,7 +120,6 @@
equals(doc.getNextId(), "svg_4");
equals(doc.getId(), "svg_4");
// clean out svg document
cleanupSvg(svg);
});
@ -149,10 +146,10 @@
test('Test getId() and getNextId() with nonce', function() {
expect(7);
var prefix = "svg_" + NONCE;
var elem2 = document.createElementNS(SVGNS, 'circle');
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = prefix+'_2';
svg_n.appendChild(elem2);
@ -192,7 +189,7 @@
cleanupSvg(svg_n);
});
test('Test releaseId()', function() {
expect(6);
@ -205,14 +202,14 @@
ok(result);
equals(doc.getNextId(), firstId);
equals(doc.getNextId(), "svg_3");
ok(!doc.releaseId("bad-id"));
ok(doc.releaseId(firstId));
ok(!doc.releaseId(firstId));
cleanupSvg(svg);
});
test('Test getNumLayers', function() {
expect(3);
var drawing = new svgedit.draw.Drawing(svg);
@ -221,7 +218,7 @@
setupSvgWith3Layers(svg);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
cleanupSvg(svg);
@ -233,7 +230,7 @@
setupSvgWith3Layers(svg);
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
equals(typeof drawing.hasLayer, typeof function() {});
ok(!drawing.hasLayer('invalid-layer'));
@ -243,12 +240,11 @@
cleanupSvg(svg);
});
test('Test identifyLayers() with empty document', function() {
expect(9);
var drawing = new svgedit.draw.Drawing(svg);
// By default, an empty document gets an empty group created.
drawing.identifyLayers();
@ -269,17 +265,17 @@
cleanupSvg(svg);
});
test('Test identifyLayers() with some layers', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
equals(svg.childNodes.length, 3);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
@ -290,19 +286,19 @@
test('Test identifyLayers() with some layers and orphans', function() {
expect(10);
setupSvgWith3Layers(svg);
var orphan1 = document.createElementNS(SVGNS, 'rect');
var orphan2 = document.createElementNS(SVGNS, 'rect');
var orphan1 = document.createElementNS(NS.SVG, 'rect');
var orphan2 = document.createElementNS(NS.SVG, 'rect');
svg.appendChild(orphan1);
svg.appendChild(orphan2);
equals(svg.childNodes.length, 5);
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 4);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
@ -320,12 +316,12 @@
test('Test getLayerName()', function() {
expect(4);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
equals(drawing.getLayerName(0), LAYER1);
equals(drawing.getLayerName(1), LAYER2);
@ -336,7 +332,7 @@
test('Test getCurrentLayer()', function() {
expect(4);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
@ -349,14 +345,14 @@
test('Test setCurrentLayer() and getCurrentLayerName()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setCurrentLayer);
equals(typeof drawing.setCurrentLayer, typeof function(){});
drawing.setCurrentLayer(LAYER2);
equals(drawing.getCurrentLayerName(LAYER2), LAYER2);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
@ -367,50 +363,50 @@
cleanupSvg(svg);
});
test('Test createLayer()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.createLayer);
equals(typeof drawing.createLayer, typeof function(){});
var NEW_LAYER_NAME = 'Layer A';
var layer_g = drawing.createLayer(NEW_LAYER_NAME);
equals(4, drawing.getNumLayers());
equals(layer_g, drawing.getCurrentLayer());
equals(NEW_LAYER_NAME, drawing.getCurrentLayerName());
equals(NEW_LAYER_NAME, drawing.getLayerName(3));
cleanupSvg(svg);
});
test('Test getLayerVisibility()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerVisibility);
equals(typeof drawing.getLayerVisibility, typeof function(){});
ok(drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(drawing.getLayerVisibility(LAYER3));
cleanupSvg(svg);
});
test('Test setLayerVisibility()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setLayerVisibility);
equals(typeof drawing.setLayerVisibility, typeof function(){});
@ -421,36 +417,36 @@
ok(!drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(!drawing.getLayerVisibility(LAYER3));
drawing.setLayerVisibility(LAYER3, 'test-string');
ok(!drawing.getLayerVisibility(LAYER3));
ok(!drawing.getLayerVisibility(LAYER3));
cleanupSvg(svg);
});
test('Test getLayerOpacity()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerOpacity);
equals(typeof drawing.getLayerOpacity, typeof function(){});
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
cleanupSvg(svg);
});
test('Test setLayerOpacity()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setLayerOpacity);
equals(typeof drawing.setLayerOpacity, typeof function(){});
@ -465,30 +461,30 @@
drawing.setLayerOpacity(LAYER3, 100);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
cleanupSvg(svg);
});
test('Test deleteCurrentLayer()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
drawing.setCurrentLayer(LAYER2);
var curLayer = drawing.getCurrentLayer();
equals(curLayer, drawing.all_layers[1][1]);
var deletedLayer = drawing.deleteCurrentLayer();
equals(curLayer, deletedLayer);
equals(2, drawing.getNumLayers());
equals(LAYER1, drawing.all_layers[0][0]);
equals(LAYER3, drawing.all_layers[1][0]);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
});
test('Test svgedit.draw.randomizeIds()', function() {
expect(9);
@ -496,7 +492,7 @@
// if there is a nonce.
var drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
@ -515,25 +511,25 @@
// but that their se:nonce attribute is left alone.
svgedit.draw.randomizeIds(false, drawing);
ok(!drawing.getNonce());
ok(!!drawing.getSvgElem().getAttributeNS(SENS, 'nonce'));
ok(!!drawing.getSvgElem().getAttributeNS(NS.SE, 'nonce'));
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!drawing.getNonce());
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for draw.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for draw.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
</body>
</html>

View File

@ -1,12 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/history.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/history.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// TODO(codedread): Write tests for handling history events.
// Mocked out methods.
@ -17,15 +17,15 @@
svgedit.utilities.setHref = function(elem, val) {};
svgedit.utilities.getRotationAngle = function(elem) { return 0; };
// log function
QUnit.log = function(result, message) {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svgns = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(svgns, 'svg');
var NS = svgedit.NS;
var svg = document.createElementNS(NS.SVG, 'svg');
var undoMgr = null;
var divparent = document.getElementById('divparent');
var div1 = document.getElementById('div1');
@ -54,7 +54,7 @@
test('Test svgedit.history package', function() {
expect(13);
ok(svgedit.history);
ok(svgedit.history.MoveElementCommand);
ok(svgedit.history.InsertElementCommand);
@ -69,11 +69,11 @@
equals(typeof svgedit.history.BatchCommand, typeof function(){});
equals(typeof svgedit.history.UndoManager, typeof function(){});
});
test('Test UndoManager methods', function() {
expect(14);
setUp();
ok(undoMgr);
ok(undoMgr.addCommandToHistory);
ok(undoMgr.getUndoStackSize);
@ -89,13 +89,13 @@
equals(typeof undoMgr.resetUndoStack, typeof function(){});
equals(typeof undoMgr.getNextUndoCommandText, typeof function(){});
equals(typeof undoMgr.getNextRedoCommandText, typeof function(){});
tearDown();
});
test('Test UndoManager.addCommandToHistory() function', function() {
expect(3);
setUp();
equals(undoMgr.getUndoStackSize(), 0);
@ -106,10 +106,10 @@
tearDown();
});
test('Test UndoManager.getUndoStackSize() and getRedoStackSize() functions', function() {
expect(18);
setUp();
undoMgr.addCommandToHistory(new MockCommand());
@ -118,7 +118,7 @@
equals(undoMgr.getUndoStackSize(), 3);
equals(undoMgr.getRedoStackSize(), 0);
undoMgr.undo();
equals(undoMgr.getUndoStackSize(), 2);
equals(undoMgr.getRedoStackSize(), 1);
@ -150,28 +150,28 @@
undoMgr.redo();
equals(undoMgr.getUndoStackSize(), 3);
equals(undoMgr.getRedoStackSize(), 0);
tearDown();
});
test('Test UndoManager.resetUndoStackSize() function', function() {
expect(4);
setUp();
undoMgr.addCommandToHistory(new MockCommand());
undoMgr.addCommandToHistory(new MockCommand());
undoMgr.addCommandToHistory(new MockCommand());
undoMgr.undo();
equals(undoMgr.getUndoStackSize(), 2);
equals(undoMgr.getRedoStackSize(), 1);
undoMgr.resetUndoStack();
equals(undoMgr.getUndoStackSize(), 0);
equals(undoMgr.getRedoStackSize(), 0);
tearDown();
});
@ -277,7 +277,7 @@
undoMgr.undo();
undoMgr.undo();
equals(lastCalled, 'cmd2.unapply');
undoMgr.undo();
equals(lastCalled, 'cmd1.unapply');
lastCalled = null;
@ -287,7 +287,7 @@
undoMgr.redo();
equals(lastCalled, 'cmd1.apply');
undoMgr.redo();
equals(lastCalled, 'cmd2.apply');
@ -480,7 +480,7 @@
ok(!div1.textContent);
// TODO(codedread): Refactor this #href stuff in history.js and svgcanvas.js
var rect = document.createElementNS(svgns, 'rect');
var rect = document.createElementNS(NS.SVG, 'rect');
var justCalled = null;
var gethrefvalue = null;
var sethrefvalue = null;
@ -510,10 +510,10 @@
change.apply();
equals(justCalled, 'setHref');
var line = document.createElementNS(svgns,'line');
var line = document.createElementNS(NS.SVG,'line');
line.setAttributeNS(null, 'class', 'newClass');
change = new svgedit.history.ChangeElementCommand(line,{class:'oldClass'});
ok(change.unapply);
ok(change.apply);
equals(typeof change.unapply, typeof function(){});
@ -524,7 +524,7 @@
change.apply();
equals(line.getAttributeNS(null, 'class'), 'newClass');
tearDown();
});
@ -568,24 +568,22 @@
tearDown();
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for history.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='divparent' style='visibility:hidden'>
<div id='div1'></div>
<div id='div2'></div>
<div id='div3'></div>
</div>
<div id='div4' style='visibility:hidden'>
<div id='div5'></div>
</div>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for history.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='divparent' style='visibility:hidden'>
<div id='div1'></div>
<div id='div2'></div>
<div id='div3'></div>
</div>
<div id='div4' style='visibility:hidden'>
<div id='div5'></div>
</div>
</body>
</html>

View File

@ -3,9 +3,10 @@
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/math.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
<script src='../editor/svgedit.js'></script>
<script src='../editor/math.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
@ -14,8 +15,7 @@ $(function() {
}
};
var svgns = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(svgns, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
module('svgedit.math');

View File

@ -1,23 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/path.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/path.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
});
</script>
</head>
<body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for path.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
@ -25,5 +24,5 @@
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
</body>
</body>
</html>

View File

@ -1,28 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/browser.js'></script>
<script type='text/javascript' src='../editor/svgutils.js'></script>
<script type='text/javascript' src='../editor/sanitize.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/sanitize.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svgns = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(svgns, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
test('Test sanitizeSvg() strips ws from style attr', function() {
expect(2);
var rect = document.createElementNS(svgns, 'rect');
var rect = document.createElementNS(svgedit.NS.SVG, 'rect');
rect.setAttribute('style', 'stroke: blue ; stroke-width : 40;');
// sanitizeSvg() requires the node to have a parent and a document.
svg.appendChild(rect);
@ -34,8 +34,8 @@
});
</script>
</head>
<body>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for sanitize.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
@ -43,5 +43,5 @@
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
</body>
</body>
</html>

View File

@ -1,17 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/browser.js'></script>
<script type='text/javascript' src='../editor/math.js'></script>
<script type='text/javascript' src='../editor/svgutils.js'></script>
<script type='text/javascript' src='../editor/select.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/math.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/select.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
@ -19,7 +20,6 @@
module('svgedit.select');
var svgns = 'http://www.w3.org/2000/svg';
var sandbox = document.getElementById('sandbox');
var svgroot;
var svgcontent;
@ -29,7 +29,7 @@
};
var mockFactory = {
createSVGElement: function(jsonMap) {
var elem = document.createElementNS(svgns, jsonMap['element']);
var elem = document.createElementNS(svgedit.NS.SVG, jsonMap['element']);
for (var attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
@ -39,7 +39,7 @@
svgContent: function() { return svgcontent; }
};
function setUp() {
function setUp() {
svgroot = mockFactory.createSVGElement({
'element': 'svg',
'attr': {'id': 'svgroot'}
@ -138,15 +138,15 @@
tearDown();
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for select.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='sandbox'></div>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for select.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='sandbox'></div>
</body>
</html>

View File

@ -1,39 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script>
// Mock for browser.js
window.svgedit = {};
svgedit.browser = {};
svgedit.browser.supportsNativeTransformLists = function() { return false;}
</script>
<script type='text/javascript' src='../editor/svgtransformlist.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script>
// Mock for browser.js
svgedit.browser = {};
svgedit.browser.supportsNativeTransformLists = function() { return false;}
</script>
<script src='../editor/svgtransformlist.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svgns = 'http://www.w3.org/2000/svg';
var NS = svgedit.NS;
var svgroot = document.getElementById('svgroot');
var svgcontent, rect, circle;
var NEAR_ZERO = 5e-6; // 0.000005, Firefox fails at higher levels of precision.
function almostEquals(a, b, msg) {
msg = msg || (a + ' did not equal ' + b);
ok(Math.abs(a - b) < NEAR_ZERO, msg);
}
function checkOutOfBoundsException(obj, fn, arg1) {
var caughtException = false;
try {
obj[fn](arg1);
obj[fn](arg1);
}
catch(e) {
if (e.code == 1) {
@ -44,13 +43,13 @@
}
function setUp() {
svgcontent = svgroot.appendChild(document.createElementNS(svgns, 'svg'));
rect = svgcontent.appendChild(document.createElementNS(svgns, 'rect'));
svgcontent = svgroot.appendChild(document.createElementNS(NS.SVG, 'svg'));
rect = svgcontent.appendChild(document.createElementNS(NS.SVG, 'rect'));
rect.id = 'r';
circle = svgcontent.appendChild(document.createElementNS(svgns, 'circle'));
circle = svgcontent.appendChild(document.createElementNS(NS.SVG, 'circle'));
circle.id = 'c';
}
function tearDown() {
svgedit.transformlist.resetListMap();
while (svgroot.hasChildNodes()) {
@ -62,7 +61,7 @@
test('Test svgedit.transformlist package', function() {
expect(2);
ok(svgedit.transformlist);
ok(svgedit.transformlist.getTransformList);
});
@ -70,37 +69,37 @@
test('Test svgedit.transformlist.getTransformList() function', function() {
expect(4);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform);
ok(cxform);
equals(typeof rxform, typeof {});
equals(typeof cxform, typeof {});
tearDown();
});
test('Test SVGTransformList.numberOfItems property', function() {
expect(2);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
equals(typeof rxform.numberOfItems, typeof 0);
equals(rxform.numberOfItems, 0);
tearDown();
});
test('Test SVGTransformList.initialize()', function() {
expect(6);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t = svgcontent.createSVGTransform();
ok(t);
ok(rxform.initialize);
@ -115,21 +114,21 @@
// This also fails in Firefox native.
// equals(rxform.numberOfItems, 0, 'Did not remove transform from list before initializing another transformlist');
equals(cxform.numberOfItems, 1);
tearDown();
});
test('Test SVGTransformList.appendItem() and getItem()', function() {
expect(12);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
ok(rxform.appendItem);
ok(rxform.getItem);
equals(typeof rxform.appendItem, typeof function(){});
@ -138,7 +137,7 @@
rxform.appendItem(t1);
rxform.appendItem(t2);
rxform.appendItem(t3);
equals(rxform.numberOfItems, 3);
var rxf = rxform.getItem(0);
equals(rxf, t1);
@ -147,7 +146,6 @@
checkOutOfBoundsException(rxform, 'getItem', -1);
checkOutOfBoundsException(rxform, 'getItem', 3);
cxform.appendItem(t1);
// These also fail in Firefox native.
// equals(rxform.numberOfItems, 2, 'Did not remove a transform from a list before appending it to a new transformlist');
@ -156,52 +154,51 @@
equals(cxform.numberOfItems, 1);
equals(cxform.getItem(0), t1);
tearDown();
});
test('Test SVGTransformList.removeItem()', function() {
expect(7);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform();
ok(rxform.removeItem);
equals(typeof rxform.removeItem, typeof function(){});
rxform.appendItem(t1);
rxform.appendItem(t2);
var removedTransform = rxform.removeItem(0);
equals(rxform.numberOfItems, 1);
equals(removedTransform, t1);
equals(rxform.getItem(0), t2);
checkOutOfBoundsException(rxform, 'removeItem', -1);
checkOutOfBoundsException(rxform, 'removeItem', 1);
tearDown();
});
test('Test SVGTransformList.replaceItem()', function() {
expect(8);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.replaceItem);
equals(typeof rxform.replaceItem, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.replaceItem(t3, 0);
equals(rxform.numberOfItems, 2);
equals(newItem, t3);
@ -209,7 +206,7 @@
equals(rxform.getItem(1), t2);
// Fails in Firefox native
// equals(cxform.numberOfItems, 0);
// test replaceItem within a list
rxform.appendItem(t1);
rxform.replaceItem(t1, 0);
@ -217,28 +214,28 @@
// equals(rxform.numberOfItems, 2);
equals(rxform.getItem(0), t1);
equals(rxform.getItem(1), t2);
tearDown();
});
test('Test SVGTransformList.insertItemBefore()', function() {
expect(10);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.insertItemBefore);
equals(typeof rxform.insertItemBefore, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.insertItemBefore(t3, 0);
equals(rxform.numberOfItems, 3);
equals(newItem, t3);
@ -373,15 +370,15 @@
var t_ = svgcontent.createSVGMatrix();
t_.e = 100; t_.f = 200;
var result = t_.multiply(r).multiply(t);
almostEquals(m.e, result.e);
almostEquals(m.f, result.f);
tearDown();
});
test('Test SVGTransformList.init() for matrix(1, 2, 3, 4, 5, 6)', function() {
expect(8);
setUp();
@ -404,15 +401,15 @@
tearDown();
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgtransformlist.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgtransformlist.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,30 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<!-- svgutils.js depends on these two... mock out? -->
<script type='text/javascript' src='../editor/browser.js'></script>
<script type='text/javascript' src='../editor/svgtransformlist.js'></script>
<script type='text/javascript' src='../editor/svgutils.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
$(function() {
// log function
QUnit.log = function(result, message) {
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<!-- svgutils.js depends on these two... mock out? -->
<script src='../editor/browser.js'></script>
<script src='../editor/svgtransformlist.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svgns = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(svgns, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
module('svgedit.utilities');
test('Test svgedit.utilities package', function() {
expect(3);
ok(svgedit.utilities);
ok(svgedit.utilities.toXml);
equals(typeof svgedit.utilities.toXml, typeof function(){});
@ -33,7 +33,7 @@
test('Test svgedit.utilities.toXml() function', function() {
expect(6);
var toXml = svgedit.utilities.toXml;
equals(toXml('a'), 'a');
equals(toXml('ABC_'), 'ABC_');
equals(toXml('PB&J'), 'PB&amp;J');
@ -76,7 +76,7 @@
test('Test svgedit.utilities.convertToXMLReferences() function', function() {
expect(1);
var convert = svgedit.utilities.convertToXMLReferences;
equals(convert('ABC'), 'ABC');
// equals(convert('ÀBC'), '&#192;BC');
@ -91,7 +91,7 @@
rect.y = 2;
rect.width = 3;
rect.height = 4;
var obj = bboxToObj(rect);
equals(typeof obj, typeof {});
equals(obj.x, 1);
@ -100,10 +100,9 @@
equals(obj.height, 4);
});
test("Test getUrlFromAttr", function() {
expect(4);
equal(svgedit.utilities.getUrlFromAttr("url(#foo)"), "#foo");
equal(svgedit.utilities.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
equal(svgedit.utilities.getUrlFromAttr("url('#foo')"), "#foo");
@ -113,7 +112,7 @@
test("Test getPathBBox", function() {
if(svgedit.browser.supportsPathBBox()) return;
var doc = svgedit.utilities.text2xml('<svg></svg>');
var path = doc.createElementNS(svgns, 'path');
var path = doc.createElementNS(svgedit.NS.SVG, 'path');
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
var bb = svgedit.utilities.getPathBBox(path);
equals(typeof bb, 'object', 'BBox returned object');
@ -121,14 +120,14 @@
ok(bb.y && !isNaN(bb.y));
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
</body>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
</body>
</html>

View File

@ -1,25 +1,26 @@
<html>
<head>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css"/>
<script src="../editor/jquery.js"></script>
<script type="text/javascript" src="../editor/jquerybbq/jquery.bbq.min.js"></script>
<script type="text/javascript" src="../editor/jquery-ui/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="../editor/svgicons/jquery.svgicons.js"></script>
<script type="text/javascript" src="../editor/browser.js"></script>
<script type="text/javascript" src="../editor/svgtransformlist.js"></script>
<script type="text/javascript" src="../editor/math.js"></script>
<script type="text/javascript" src="../editor/units.js"></script>
<script type="text/javascript" src="../editor/svgutils.js"></script>
<script type="text/javascript" src="../editor/sanitize.js"></script>
<script type="text/javascript" src="../editor/history.js"></script>
<script type="text/javascript" src="../editor/select.js"></script>
<script type="text/javascript" src="../editor/draw.js"></script>
<script type="text/javascript" src="../editor/path.js"></script>
<script type="text/javascript" src="../editor/svgcanvas.js"></script>
<script type="text/javascript" src="../editor/svg-editor.js"></script>
<script type="text/javascript" src="../editor/locale/locale.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript">
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css"/>
<script src="../editor/jquery.js"></script>
<script src="../editor/jquerybbq/jquery.bbq.min.js"></script>
<script src="../editor/jquery-ui/jquery-ui-1.8.custom.min.js"></script>
<script src="../editor/svgicons/jquery.svgicons.js"></script>
<script src="../editor/browser.js"></script>
<script src="../editor/svgtransformlist.js"></script>
<script src="../editor/math.js"></script>
<script src="../editor/units.js"></script>
<script src="../editor/svgutils.js"></script>
<script src="../editor/sanitize.js"></script>
<script src="../editor/history.js"></script>
<script src="../editor/select.js"></script>
<script src="../editor/draw.js"></script>
<script src="../editor/path.js"></script>
<script src="../editor/svgcanvas.js"></script>
<script src="../editor/svg-editor.js"></script>
<script src="../editor/locale/locale.js"></script>
<script src="qunit/qunit.js"></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
@ -27,7 +28,7 @@
window.console.log(result +' :: '+ message);
}
};
// helper functions
var isIdentity = function(m) {
return (m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && m.e == 0 && m.f == 0);

View File

@ -2,10 +2,11 @@
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/units.js'></script>
<script type='text/javascript' src='qunit/qunit.js'></script>
<script type='text/javascript'>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/units.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {