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
This commit is contained in:
@@ -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),
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user