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. # All files that will be compiled by the Closure compiler.
JS_FILES=\ JS_FILES=\
svgedit.js \
contextmenu/jquery.contextmenu.js \ contextmenu/jquery.contextmenu.js \
browser.js \ browser.js \
svgtransformlist.js \ svgtransformlist.js \

View File

@ -10,18 +10,17 @@
// Dependencies: // Dependencies:
// 1) jQuery (for $.alert()) // 1) jQuery (for $.alert())
var svgedit = svgedit || {};
(function() { (function() {
if (!svgedit.browser) { if (!svgedit.browser) {
svgedit.browser = {}; svgedit.browser = {};
} }
var svgns = 'http://www.w3.org/2000/svg'; // alias
var NS = svgedit.NS;
var supportsSvg_ = (function() { 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_; }; svgedit.browser.supportsSvg = function() { return supportsSvg_; };
@ -31,7 +30,7 @@ if(!svgedit.browser.supportsSvg()) {
} }
var userAgent = navigator.userAgent; 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 // Note: Browser sniffing should only be used if no other detection method is possible
var isOpera_ = !!window.opera; var isOpera_ = !!window.opera;
@ -53,7 +52,7 @@ var supportsXpath_ = (function() {
// segList functions (for FF1.5 and 2.0) // segList functions (for FF1.5 and 2.0)
var supportsPathReplaceItem_ = (function() { var supportsPathReplaceItem_ = (function() {
var path = document.createElementNS(svgns, 'path'); var path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,10'); path.setAttribute('d', 'M0,0 10,10');
var seglist = path.pathSegList; var seglist = path.pathSegList;
var seg = path.createSVGPathSegLinetoAbs(5,5); var seg = path.createSVGPathSegLinetoAbs(5,5);
@ -65,7 +64,7 @@ var supportsPathReplaceItem_ = (function() {
})(); })();
var supportsPathInsertItemBefore_ = (function() { var supportsPathInsertItemBefore_ = (function() {
var path = document.createElementNS(svgns, 'path'); var path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,10'); path.setAttribute('d', 'M0,0 10,10');
var seglist = path.pathSegList; var seglist = path.pathSegList;
var seg = path.createSVGPathSegLinetoAbs(5,5); var seg = path.createSVGPathSegLinetoAbs(5,5);
@ -78,12 +77,12 @@ var supportsPathInsertItemBefore_ = (function() {
// text character positioning (for IE9) // text character positioning (for IE9)
var supportsGoodTextCharPos_ = (function() { var supportsGoodTextCharPos_ = (function() {
var svgroot = document.createElementNS(svgns, 'svg'); var svgroot = document.createElementNS(NS.SVG, 'svg');
var svgcontent = document.createElementNS(svgns, 'svg'); var svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.appendChild(svgroot); document.documentElement.appendChild(svgroot);
svgcontent.setAttribute('x', 5); svgcontent.setAttribute('x', 5);
svgroot.appendChild(svgcontent); svgroot.appendChild(svgcontent);
var text = document.createElementNS(svgns, 'text'); var text = document.createElementNS(NS.SVG, 'text');
text.textContent = 'a'; text.textContent = 'a';
svgcontent.appendChild(text); svgcontent.appendChild(text);
var pos = text.getStartPositionOfChar(0).x; var pos = text.getStartPositionOfChar(0).x;
@ -92,9 +91,9 @@ var supportsGoodTextCharPos_ = (function() {
})(); })();
var supportsPathBBox_ = (function() { var supportsPathBBox_ = (function() {
var svgcontent = document.createElementNS(svgns, 'svg'); var svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.appendChild(svgcontent); 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'); path.setAttribute('d', 'M0,0 C0,0 10,10 10,0');
svgcontent.appendChild(path); svgcontent.appendChild(path);
var bbox = path.getBBox(); var bbox = path.getBBox();
@ -104,13 +103,13 @@ var supportsPathBBox_ = (function() {
// Support for correct bbox sizing on groups with horizontal/vertical lines // Support for correct bbox sizing on groups with horizontal/vertical lines
var supportsHVLineContainerBBox_ = (function() { var supportsHVLineContainerBBox_ = (function() {
var svgcontent = document.createElementNS(svgns, 'svg'); var svgcontent = document.createElementNS(NS.SVG, 'svg');
document.documentElement.appendChild(svgcontent); document.documentElement.appendChild(svgcontent);
var path = document.createElementNS(svgns, 'path'); var path = document.createElementNS(NS.SVG, 'path');
path.setAttribute('d', 'M0,0 10,0'); 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'); 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(path);
g.appendChild(path2); g.appendChild(path2);
svgcontent.appendChild(g); svgcontent.appendChild(g);
@ -127,7 +126,7 @@ var supportsEditableText_ = (function() {
var supportsGoodDecimals_ = (function() { var supportsGoodDecimals_ = (function() {
// Correct decimals on clone attributes (Opera < 10.5/win/non-en) // 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); rect.setAttribute('x', 0.1);
var crect = rect.cloneNode(false); var crect = rect.cloneNode(false);
var retValue = (crect.getAttribute('x').indexOf(',') == -1); var retValue = (crect.getAttribute('x').indexOf(',') == -1);
@ -139,13 +138,13 @@ var supportsGoodDecimals_ = (function() {
})(); })();
var supportsNonScalingStroke_ = (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'); rect.setAttribute('style', 'vector-effect:non-scaling-stroke');
return rect.style.vectorEffect === 'non-scaling-stroke'; return rect.style.vectorEffect === 'non-scaling-stroke';
})(); })();
var supportsNativeSVGTransformLists_ = (function() { var supportsNativeSVGTransformLists_ = (function() {
var rect = document.createElementNS(svgns, 'rect'); var rect = document.createElementNS(NS.SVG, 'rect');
var rxform = rect.transform.baseVal; var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform(); var t1 = svg.createSVGTransform();
rxform.appendItem(t1); rxform.appendItem(t1);

View File

@ -11,17 +11,13 @@
// 2) browser.js // 2) browser.js
// 3) svgutils.js // 3) svgutils.js
var svgedit = svgedit || {};
(function() { (function() {
if (!svgedit.draw) { if (!svgedit.draw) {
svgedit.draw = {}; svgedit.draw = {};
} }
// alias
var svg_ns = "http://www.w3.org/2000/svg"; var NS = svgedit.NS;
var se_ns = "http://svg-edit.googlecode.com";
var xmlns_ns = "http://www.w3.org/2000/xmlns/";
var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use'; var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use';
var visElems_arr = visElems.split(','); var visElems_arr = visElems.split(',');
@ -80,7 +76,7 @@ svgedit.draw.randomizeIds = function(enableRandomization, current_drawing) {
*/ */
svgedit.draw.Drawing = function(svgElem, opt_idPrefix) { svgedit.draw.Drawing = function(svgElem, opt_idPrefix) {
if (!svgElem || !svgElem.tagName || !svgElem.namespaceURI || 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"; throw "Error: svgedit.draw.Drawing instance initialized without a <svg> element";
} }
@ -128,7 +124,7 @@ svgedit.draw.Drawing = function(svgElem, opt_idPrefix) {
* @type {!String} * @type {!String}
*/ */
this.nonce_ = ""; 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 // If already set in the DOM, use the nonce throughout the document
// else, if randomizeIds(true) has been called, create and set the nonce. // else, if randomizeIds(true) has been called, create and set the nonce.
if (!!n && randomize_ids != RandomizeModes.NEVER_RANDOMIZE) { if (!!n && randomize_ids != RandomizeModes.NEVER_RANDOMIZE) {
@ -156,8 +152,8 @@ svgedit.draw.Drawing.prototype.getNonce = function() {
}; };
svgedit.draw.Drawing.prototype.setNonce = function(n) { svgedit.draw.Drawing.prototype.setNonce = function(n) {
this.svgElem_.setAttributeNS(xmlns_ns, 'xmlns:se', se_ns); this.svgElem_.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
this.svgElem_.setAttributeNS(se_ns, 'se:nonce', n); this.svgElem_.setAttributeNS(NS.SE, 'se:nonce', n);
this.nonce_ = n; this.nonce_ = n;
}; };
@ -358,7 +354,7 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
if (child.tagName == "g") { if (child.tagName == "g") {
childgroups = true; childgroups = true;
var name = $("title", child).text(); var name = $("title", child).text();
// Hack for Opera 10.60 // Hack for Opera 10.60
if(!name && svgedit.browser.isOpera() && child.querySelectorAll) { if(!name && svgedit.browser.isOpera() && child.querySelectorAll) {
name = $(child.querySelectorAll('title')).text(); name = $(child.querySelectorAll('title')).text();
@ -392,8 +388,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
// TODO(codedread): What about internationalization of "Layer"? // TODO(codedread): What about internationalization of "Layer"?
while (layernames.indexOf(("Layer " + i)) >= 0) { i++; } while (layernames.indexOf(("Layer " + i)) >= 0) { i++; }
var newname = "Layer " + i; var newname = "Layer " + i;
a_layer = svgdoc.createElementNS(svg_ns, "g"); a_layer = svgdoc.createElementNS(NS.SVG, "g");
var layer_title = svgdoc.createElementNS(svg_ns, "title"); var layer_title = svgdoc.createElementNS(NS.SVG, "title");
layer_title.textContent = newname; layer_title.textContent = newname;
a_layer.appendChild(layer_title); a_layer.appendChild(layer_title);
for (var j = 0; j < orphans.length; ++j) { for (var j = 0; j < orphans.length; ++j) {
@ -419,8 +415,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
// of this drawing. // of this drawing.
svgedit.draw.Drawing.prototype.createLayer = function(name) { svgedit.draw.Drawing.prototype.createLayer = function(name) {
var svgdoc = this.svgElem_.ownerDocument; var svgdoc = this.svgElem_.ownerDocument;
var new_layer = svgdoc.createElementNS(svg_ns, "g"); var new_layer = svgdoc.createElementNS(NS.SVG, "g");
var layer_title = svgdoc.createElementNS(svg_ns, "title"); var layer_title = svgdoc.createElementNS(NS.SVG, "title");
layer_title.textContent = name; layer_title.textContent = name;
new_layer.appendChild(layer_title); new_layer.appendChild(layer_title);
this.svgElem_.appendChild(new_layer); this.svgElem_.appendChild(new_layer);

View File

@ -14,8 +14,8 @@
// 4) svgcanvas.js // 4) svgcanvas.js
svgEditor.addExtension("eyedropper", function(S) { svgEditor.addExtension("eyedropper", function(S) {
var svgcontent = S.svgcontent, var NS = svgedit.NS,
svgns = "http://www.w3.org/2000/svg", svgcontent = S.svgcontent,
svgdoc = S.svgroot.parentNode.ownerDocument, svgdoc = S.svgroot.parentNode.ownerDocument,
svgCanvas = svgEditor.canvas, svgCanvas = svgEditor.canvas,
ChangeElementCommand = svgedit.history.ChangeElementCommand, ChangeElementCommand = svgedit.history.ChangeElementCommand,
@ -27,7 +27,7 @@ svgEditor.addExtension("eyedropper", function(S) {
strokeLinecap: 'butt', strokeLinecap: 'butt',
strokeLinejoin: 'miter', strokeLinejoin: 'miter',
}; };
function getStyle(opts) { function getStyle(opts) {
// if we are in eyedropper mode, we don't want to disable the eye-dropper tool // if we are in eyedropper mode, we don't want to disable the eye-dropper tool
var mode = svgCanvas.getMode(); var mode = svgCanvas.getMode();

View File

@ -9,269 +9,257 @@
*/ */
svgEditor.addExtension("foreignObject", function(S) { svgEditor.addExtension("foreignObject", function(S) {
var svgcontent = S.svgcontent, var NS = svgedit.NS,
addElem = S.addSvgElementFromJson, svgcontent = S.svgcontent,
selElems, addElem = S.addSvgElementFromJson,
svgns = "http://www.w3.org/2000/svg", selElems,
xlinkns = "http://www.w3.org/1999/xlink", editingforeign = false,
xmlns = "http://www.w3.org/XML/1998/namespace", svgdoc = S.svgroot.parentNode.ownerDocument,
xmlnsns = "http://www.w3.org/2000/xmlns/", started,
se_ns = "http://svg-edit.googlecode.com", newFO;
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);
};
function showPanel(on) { var properlySourceSizeTextArea = function(){
var fc_rules = $('#fc_rules'); // TODO: remove magic numbers here and get values from CSS
if(!fc_rules.length) { var height = $('#svg_source_container').height() - 80;
fc_rules = $('<style id="fc_rules"><\/style>').appendTo('head'); $('#svg_source_textarea').css('height', height);
} };
fc_rules.text(!on?"":" #tool_topath { display: none !important; }");
$('#foreignObject_panel').toggle(on); 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) { return true;
$('#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;
};
function showForeignEditor() { function showForeignEditor() {
var elt = selElems[0]; var elt = selElems[0];
if (!elt || editingforeign) return; if (!elt || editingforeign) return;
editingforeign = true; editingforeign = true;
toggleSourceButtons(true); toggleSourceButtons(true);
elt.removeAttribute('fill'); elt.removeAttribute('fill');
var str = S.svgToString(elt, 0); var str = S.svgToString(elt, 0);
$('#svg_source_textarea').val(str); $('#svg_source_textarea').val(str);
$('#svg_source_editor').fadeIn(); $('#svg_source_editor').fadeIn();
properlySourceSizeTextArea(); properlySourceSizeTextArea();
$('#svg_source_textarea').focus(); $('#svg_source_textarea').focus();
} }
function setAttr(attr, val) { function setAttr(attr, val) {
svgCanvas.changeSelectedAttribute(attr, val); svgCanvas.changeSelectedAttribute(attr, val);
S.call("changed", selElems); S.call("changed", selElems);
} }
return {
return { name: "foreignObject",
name: "foreignObject", svgicons: "extensions/foreignobject-icons.xml",
svgicons: "extensions/foreignobject-icons.xml", buttons: [{
buttons: [{ id: "tool_foreign",
id: "tool_foreign", type: "mode",
type: "mode", title: "Foreign Object Tool",
title: "Foreign Object Tool", events: {
events: { 'click': function() {
'click': function() { svgCanvas.setMode('foreign')
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);
}
} }
} }
},{
id: "edit_foreign",
], type: "context",
callback: function() { panel: "foreignObject_panel",
$('#foreignObject_panel').hide(); title: "Edit ForeignObject Content",
events: {
var endChanges = function() { 'click': function() {
$('#svg_source_editor').hide(); showForeignEditor();
editingforeign = false;
$('#svg_source_textarea').blur();
toggleSourceButtons(false);
} }
}
}],
// TODO: Needs to be done after orig icon loads context_tools: [{
setTimeout(function() { type: "input",
// Create source save/cancel buttons panel: "foreignObject_panel",
var save = $('#tool_source_save').clone() title: "Change foreignObject's width",
.hide().attr('id', 'foreign_save').unbind() id: "foreign_width",
.appendTo("#tool_source_back").click(function() { label: "w",
size: 3,
if (!editingforeign) return; 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) { callback: function() {
if(!ok) return false; $('#foreignObject_panel').hide();
endChanges();
}); var endChanges = function() {
} else { $('#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(); 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 { } 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 { } else {
showPanel(false); 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() { svgEditor.addExtension('view_grid', function() {
var svgdoc = document.getElementById('svgcanvas').ownerDocument, var NS = svgedit.NS,
svgns = 'http://www.w3.org/2000/svg', svgdoc = document.getElementById('svgcanvas').ownerDocument,
showGrid = false, showGrid = false,
assignAttributes = svgCanvas.assignAttributes, assignAttributes = svgCanvas.assignAttributes,
hcanvas = document.createElement('canvas'), hcanvas = document.createElement('canvas'),
@ -25,7 +25,7 @@ svgEditor.addExtension('view_grid', function() {
$(hcanvas).hide().appendTo('body'); $(hcanvas).hide().appendTo('body');
var canvasGrid = svgdoc.createElementNS(svgns, 'svg'); var canvasGrid = svgdoc.createElementNS(NS.SVG, 'svg');
assignAttributes(canvasGrid, { assignAttributes(canvasGrid, {
'id': 'canvasGrid', 'id': 'canvasGrid',
'width': '100%', 'width': '100%',
@ -38,7 +38,7 @@ svgEditor.addExtension('view_grid', function() {
canvBG.append(canvasGrid); canvBG.append(canvasGrid);
// grid-pattern // grid-pattern
var gridPattern = svgdoc.createElementNS(svgns, 'pattern'); var gridPattern = svgdoc.createElementNS(NS.SVG, 'pattern');
assignAttributes(gridPattern, { assignAttributes(gridPattern, {
'id': 'gridpattern', 'id': 'gridpattern',
'patternUnits': 'userSpaceOnUse', 'patternUnits': 'userSpaceOnUse',
@ -48,7 +48,7 @@ svgEditor.addExtension('view_grid', function() {
'height': 100 'height': 100
}); });
var gridimg = svgdoc.createElementNS(svgns, 'image'); var gridimg = svgdoc.createElementNS(NS.SVG, 'image');
assignAttributes(gridimg, { assignAttributes(gridimg, {
'x': 0, 'x': 0,
'y': 0, 'y': 0,
@ -59,7 +59,7 @@ svgEditor.addExtension('view_grid', function() {
$('#svgroot defs').append(gridPattern); $('#svgroot defs').append(gridPattern);
// grid-box // grid-box
var gridBox = svgdoc.createElementNS(svgns, 'rect'); var gridBox = svgdoc.createElementNS(NS.SVG, 'rect');
assignAttributes(gridBox, { assignAttributes(gridBox, {
'width': '100%', 'width': '100%',
'height': '100%', 'height': '100%',

View File

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

View File

@ -8,7 +8,11 @@
*/ */
svgEditor.addExtension("polygon", function(S){ 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 ccZoom;
var wEl, hEl; var wEl, hEl;
@ -175,7 +179,7 @@ svgEditor.addExtension("polygon", function(S){
points += x + ',' + y + ' '; points += x + ',' + y + ' ';
} }
//var poly = newFO.createElementNS(svgns, 'polygon'); //var poly = newFO.createElementNS(NS.SVG, 'polygon');
newFO.setAttributeNS(null, 'points', points); newFO.setAttributeNS(null, 'points', points);
newFO.setAttributeNS(null, 'fill', fill); newFO.setAttributeNS(null, 'fill', fill);
newFO.setAttributeNS(null, 'stroke', strokecolor); newFO.setAttributeNS(null, 'stroke', strokecolor);

View File

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

View File

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

View File

@ -10,8 +10,6 @@
// Dependencies: // Dependencies:
// None. // None.
var svgedit = svgedit || {};
(function() { (function() {
if (!svgedit.math) { if (!svgedit.math) {
@ -22,7 +20,7 @@ if (!svgedit.math) {
var NEAR_ZERO = 1e-14; var NEAR_ZERO = 1e-14;
// Throw away SVGSVGElement used for creating matrices/transforms. // 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 // Function: svgedit.math.transformPoint
// A (hopefully) quicker function to transform a point by a matrix // A (hopefully) quicker function to transform a point by a matrix

View File

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

View File

@ -12,40 +12,14 @@
// 2) browser.js // 2) browser.js
// 3) svgutils.js // 3) svgutils.js
var svgedit = svgedit || {};
(function() { (function() {
if (!svgedit.sanitize) { if (!svgedit.sanitize) {
svgedit.sanitize = {}; svgedit.sanitize = {};
} }
// Namespace constants var NS = svgedit.NS,
var svgns = 'http://www.w3.org/2000/svg', REVERSE_NS = svgedit.getReverseNS();
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;
});
// this defines which elements and attributes that we support // this defines which elements and attributes that we support
var svgWhiteList_ = { 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"], "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"], "clipPath": ["class", "clipPathUnits", "id"],
"defs": [], "defs": [],
"style" : ["type"], "style" : ["type"],
"desc": [], "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"], "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"], "feGaussianBlur": ["class", "color-interpolation-filters", "id", "requiredFeatures", "stdDeviation"],
@ -82,7 +56,7 @@ var svgWhiteList_ = {
"title": [], "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"], "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"], "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 // MathML Elements
"annotation": ["encoding"], "annotation": ["encoding"],
"annotation-xml": ["encoding"], "annotation-xml": ["encoding"],
@ -124,9 +98,9 @@ $.each(svgWhiteList_, function(elt, atts){
$.each(atts, function(i, att){ $.each(atts, function(i, att){
if (att.indexOf(':') >= 0) { if (att.indexOf(':') >= 0) {
var v = att.split(':'); var v = att.split(':');
attNS[v[1]] = nsRevMap_[v[0]]; attNS[v[1]] = NS[(v[0]).toUpperCase()];
} else { } else {
attNS[att] = att == 'xmlns' ? xmlnsns : null; attNS[att] = att == 'xmlns' ? NS.XMLNS : null;
} }
}); });
svgWhiteListNS_[elt] = attNS; svgWhiteListNS_[elt] = attNS;
@ -177,15 +151,15 @@ svgedit.sanitize.sanitizeSvg = function(node) {
var attrNsURI = attr.namespaceURI; var attrNsURI = attr.namespaceURI;
// Check that an attribute with the correct localName in the correct namespace is on // 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 // our whitelist or is a namespace declaration for one of our allowed namespaces
if (!(allowedAttrsNS.hasOwnProperty(attrLocalName) && attrNsURI == allowedAttrsNS[attrLocalName] && attrNsURI != xmlnsns) && if (!(allowedAttrsNS.hasOwnProperty(attrLocalName) && attrNsURI == allowedAttrsNS[attrLocalName] && attrNsURI != NS.XMLNS) &&
!(attrNsURI == xmlnsns && nsMap_[attr.nodeValue]) ) !(attrNsURI == NS.XMLNS && REVERSE_NS[attr.nodeValue]) )
{ {
// TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist. // TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist.
// Bypassing the whitelist to allow se: prefixes. // Bypassing the whitelist to allow se: prefixes.
// Is there a more appropriate way to do this? // Is there a more appropriate way to do this?
if(attrName.indexOf('se:') == 0) { if(attrName.indexOf('se:') == 0) {
se_attrs.push([attrName, attr.nodeValue]); se_attrs.push([attrName, attr.nodeValue]);
} }
node.removeAttributeNS(attrNsURI, attrLocalName); node.removeAttributeNS(attrNsURI, attrLocalName);
} }
@ -218,7 +192,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
} }
$.each(se_attrs, function(i, attr) { $.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 // 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] != '#') { if (href[0] != '#') {
// remove the attribute (but keep the element) // remove the attribute (but keep the element)
svgedit.utilities.setHref(node, ''); svgedit.utilities.setHref(node, '');
node.removeAttributeNS(xlinkns, 'href'); node.removeAttributeNS(NS.XLINK, 'href');
} }
} }

View File

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

View File

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

View File

@ -3529,7 +3529,7 @@
testEl.removeAttribute('style'); testEl.removeAttribute('style');
var svgdocbox = paintBox.fill.rect.ownerDocument; var svgdocbox = paintBox.fill.rect.ownerDocument;
// Use this to test support for blur element. Seems to work to test support in Webkit // 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') { if (typeof blurTest.stdDeviationX === 'undefined') {
$('#tool_blur').hide(); $('#tool_blur').hide();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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