Move getTransformList() into svgtransformlist.js, move getHref adn setHref into svgutils.js

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1837 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-11-05 14:43:12 +00:00
parent 985d061674
commit 16ea2a36a5
2 changed files with 55 additions and 52 deletions

View File

@ -207,7 +207,7 @@ var Utils = this.Utils = svgedit.Utilities;
// Function: snapToGrid
// round value to for snapping
// NOTE: This function did not move to svgutils.js since it depends on unit_types.
// NOTE: This function did not move to svgutils.js since it depends on unit_types and curConfig.
Utils.snapToGrid = function(value){
var stepSize = curConfig.snappingStep;
var unit = curConfig.baseUnit;
@ -1441,13 +1441,16 @@ var SelectorManager;
}());
// "Import" from svgtransformlist.js
var SVGEditTransformList = svgedit.SVGTransformList;
var svgTransformLists = {};
var SVGEditTransformList = svgedit.transformlist.SVGTransformList;
var svgTransformLists = svgedit.transformlist.transforms;
var getTransformList = this.getTransformList = svgedit.transformlist.getTransformList;
// "Import" from svgutils.js
var walkTree = this.walkTree = svgedit.Utilities.walkTree;
var walkTreePost = this.walkTreePost = svgedit.Utilities.walkTreePost;
var getUrlFromAttr = this.getUrlFromAttr = svgedit.Utilities.getUrlFromAttr;
var getHref = this.getHref = svgedit.Utilities.getHref;
var setHref = this.setHref = svgedit.Utilities.setHref;
// "Import" from math.js.
var transformPoint = svgedit.math.transformPoint;
@ -2536,40 +2539,6 @@ this.setRotationAngle = function(val, preventUndo) {
selector.updateGripCursors(val);
};
// Function: getTransformList
// Returns an object that behaves like a SVGTransformList for the given DOM element
//
// Parameters:
// elem - DOM element to get a transformlist from
var getTransformList = this.getTransformList = function(elem) {
if (isWebkit) {
var id = elem.id;
if(!id) {
// Get unique ID for temporary element
id = 'temp';
}
var t = svgTransformLists[id];
if (!t || id == 'temp') {
svgTransformLists[id] = new SVGEditTransformList(elem);
svgTransformLists[id]._init();
t = svgTransformLists[id];
}
return t;
}
else if (elem.transform) {
return elem.transform.baseVal;
}
else if (elem.gradientTransform) {
return elem.gradientTransform.baseVal;
}
else if (elem.patternTransform) {
return elem.patternTransform.baseVal;
}
return null;
};
// Function: recalculateAllSelectedDimensions
// Runs recalculateDimensions on the selected elements,
// adding the changes to a single batch command
@ -3448,7 +3417,7 @@ var recalculateDimensions = this.recalculateDimensions = function(selected) {
// Check if it has a gradient with userSpaceOnUse, in which case
// adjust it by recalculating the matrix transform.
// TODO: Make this work in Webkit using SVGEditTransformList
// TODO: Make this work in Webkit using svgedit.transformlist.SVGTransformList
if(!isWebkit) {
var fill = selected.getAttribute('fill');
if(fill && fill.indexOf('url(') === 0) {
@ -8954,19 +8923,6 @@ this.getTitle = function(elem) {
return '';
}
// Function: getHref
// Returns the given element's xlink:href value
var getHref = this.getHref = function(elem) {
return elem.getAttributeNS(xlinkns, "href");
}
// Function: setHref
// Sets the given element's xlink:href value
var setHref = this.setHref = function(elem, val) {
elem.setAttributeNS(xlinkns, "xlink:href", val);
}
// Function: setGroupTitle
// Sets the group/SVG's title content
// TODO: Combine this with setDocumentTitle

View File

@ -7,11 +7,17 @@
* Copyright(c) 2010 Jeff Schiller
*/
// Dependencies:
// 1) browwsersupport.js
(function() {
if (!window.svgedit) {
window.svgedit = {};
}
if (!svgedit.transformlist) {
svgedit.transformlist = {};
}
// Helper function.
function transformToString(xform) {
@ -42,6 +48,12 @@ function transformToString(xform) {
return text;
};
/**
* Map of SVGTransformList objects.
*/
svgedit.transformlist.listMap = {};
// **************************************************************************************
// SVGTransformList implementation for Webkit
// These methods do not currently raise any exceptions.
@ -62,7 +74,7 @@ function transformToString(xform) {
// NOT IMPLEMENTED: SVGTransform consolidate ( );
// }
// **************************************************************************************
svgedit.SVGTransformList = function(elem) {
svgedit.transformlist.SVGTransformList = function(elem) {
this._elem = elem || null;
this._xforms = [];
// TODO: how do we capture the undo-ability in the changed transform list?
@ -197,4 +209,39 @@ svgedit.SVGTransformList = function(elem) {
};
};
// Function: getTransformList
// Returns an object that behaves like a SVGTransformList for the given DOM element
//
// Parameters:
// elem - DOM element to get a transformlist from
svgedit.transformlist.getTransformList = function(elem) {
if (svgedit.BrowserSupport.isWebkit) {
var id = elem.id;
if(!id) {
// Get unique ID for temporary element
id = 'temp';
}
var t = svgedit.transformlist.listMap[id];
if (!t || id == 'temp') {
svgedit.transformlist.listMap[id] = new svgedit.transformlist.SVGTransformList(elem);
svgedit.transformlist.listMap[id]._init();
t = svgedit.transformlist.listMap[id];
}
return t;
}
else if (elem.transform) {
return elem.transform.baseVal;
}
else if (elem.gradientTransform) {
return elem.gradientTransform.baseVal;
}
else if (elem.patternTransform) {
return elem.patternTransform.baseVal;
}
return null;
};
})();