Fix some bugs with svgutils.js. Add a couple tiny tests to selector_test.html

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1880 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-12-02 17:14:24 +00:00
parent 8b19adc777
commit 3b1b46f874
3 changed files with 49 additions and 13 deletions

View File

@ -197,6 +197,10 @@ $.extend(all_properties.text, {
// Current shape style properties
var cur_shape = all_properties.shape;
// Array with all the currently selected elements
// default size of 1 until it needs to grow bigger
var selectedElements = new Array(1);
// Function: getElem
// Get a DOM element by ID within the SVG root element.
@ -347,6 +351,10 @@ svgedit.units.init({
var convertToNum = canvas.convertToNum = svgedit.units.convertToNum;
// import from svgutils.js
svgedit.utilities.init({
getSelectedElements: function() { return selectedElements; },
getSVGContent: function() { return svgcontent; }
});
var getUrlFromAttr = canvas.getUrlFromAttr = svgedit.utilities.getUrlFromAttr;
var getHref = canvas.getHref = svgedit.utilities.getHref;
var setHref = canvas.setHref = svgedit.utilities.setHref;
@ -541,10 +549,6 @@ var cur_text = all_properties.text,
// Current general properties
cur_properties = cur_shape,
// Array with all the currently selected elements
// default size of 1 until it needs to grow bigger
selectedElements = new Array(1),
// Array with selected elements' Bounding box object
selectedBBoxes = new Array(1),

View File

@ -23,17 +23,38 @@ if (!svgedit.utilities) {
svgedit.utilities = {};
}
/**
* @interface
*/
svgedit.utilities.FooInterface = function() {
};
svgedit.utilities.prototype.FooInterface.funky = function() {};
/**
* @constructor
* @implements {svgedit.utilities.FooInterface}
*/
svgedit.utilities.FooImplementor = function() {
};
// Constants
// String used to encode base64.
var KEYSTR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var XLINKNS = "http://www.w3.org/1999/xlink";
var KEYSTR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var SVGNS = 'http://www.w3.org/2000/svg';
var XLINKNS = 'http://www.w3.org/1999/xlink';
// 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_arr = visElems.split(',');
//var hidElems = 'clipPath,defs,desc,feGaussianBlur,filter,linearGradient,marker,mask,metadata,pattern,radialGradient,stop,switch,symbol,title,textPath';
var editorContext_ = null;
svgedit.utilities.init = function(editorContext) {
editorContext_ = editorContext;
};
// Function: svgedit.utilities.toXml
// Converts characters in a string to XML-friendly entities.
//
@ -61,7 +82,6 @@ svgedit.utilities.fromXml = function(str) {
return $('<p/>').html(str).text();
};
// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
@ -304,14 +324,14 @@ svgedit.utilities.setHref = function(elem, val) {
// Returns:
// The document's <defs> element, create it first if necessary
svgedit.utilities.findDefs = function(svgElement) {
var svgElement = svgDoc.documentElement;
var defs = svgElement.getElementsByTagNameNS(svgns, "defs");
var svgElement = editorContext_.getSVGContent().documentElement;
var defs = svgElement.getElementsByTagNameNS(SVGNS, "defs");
if (defs.length > 0) {
defs = defs[0];
}
else {
// first child is a comment, so call nextSibling
defs = svgElement.insertBefore( svgElement.ownerDocument.createElementNS(svgns, "defs" ), svgElement.firstChild.nextSibling);
defs = svgElement.insertBefore( svgElement.ownerDocument.createElementNS(SVGNS, "defs" ), svgElement.firstChild.nextSibling);
}
return defs;
};
@ -406,7 +426,7 @@ svgedit.utilities.getPathBBox = function(path) {
// Parameters:
// elem - Optional DOM element to get the BBox for
svgedit.utilities.getBBox = function(elem) {
var selected = elem || selectedElements[0];
var selected = elem || editorContext_.geSelectedElements()[0];
if (elem.nodeType != 1) return null;
var ret = null;
var elname = selected.nodeName;
@ -459,7 +479,7 @@ svgedit.utilities.getBBox = function(elem) {
// Returns:
// Float with the angle in degrees or radians
svgedit.utilities.getRotationAngle = function(elem, to_rad) {
var selected = elem || selectedElements[0];
var selected = elem || editorContext_.getSelectedElements()[0];
// find the rotation transform (if any) and set it
var tlist = svgedit.transformlist.getTransformList(selected);
if(!tlist) return 0; // <svg> elements have no tlist

View File

@ -63,7 +63,10 @@
})
);
sandbox.appendChild(svgroot);
}
function setUpWithInit() {
setUp();
svgedit.select.init(mockConfig, mockFactory);
}
@ -89,12 +92,20 @@
});
test('Test Selector DOM structure', function() {
expect(20);
expect(24);
setUp();
ok(svgroot);
ok(svgroot.hasChildNodes());
// Verify non-existence of Selector DOM nodes
equals(svgroot.childNodes.length, 1);
equals(svgroot.childNodes.item(0), svgcontent);
ok(!svgroot.querySelector('#selectorParentGroup'));
svgedit.select.init(mockConfig, mockFactory);
equals(svgroot.childNodes.length, 3);
// Verify existence of canvas background.
@ -108,6 +119,7 @@
// Verify existence of selectorParentGroup.
var spg = svgroot.childNodes.item(2);
ok(spg);
equals(svgroot.querySelector('#selectorParentGroup'), spg);
equals(spg.id, 'selectorParentGroup');
equals(spg.tagName, 'g');