Create jquery-svg module and empty test, update build. Add a couple tiny unit tests for recalculate.js
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2442 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
69
editor/jquery-svg.js
vendored
Normal file
69
editor/jquery-svg.js
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* jQuery module to work with SVG.
|
||||
*
|
||||
* Licensed under the MIT License
|
||||
*
|
||||
*/
|
||||
|
||||
// Dependencies:
|
||||
// 1) jquery
|
||||
|
||||
(function() {
|
||||
|
||||
// This fixes $(...).attr() to work as expected with SVG elements.
|
||||
// Does not currently use *AttributeNS() since we rarely need that.
|
||||
|
||||
// See http://api.jquery.com/attr/ for basic documentation of .attr()
|
||||
|
||||
// Additional functionality:
|
||||
// - When getting attributes, a string that's a number is return as type number.
|
||||
// - If an array is supplied as first parameter, multiple values are returned
|
||||
// as an object with values for each given attributes
|
||||
|
||||
var proxied = jQuery.fn.attr,
|
||||
// TODO use NS.SVG instead
|
||||
svgns = "http://www.w3.org/2000/svg";
|
||||
jQuery.fn.attr = function(key, value) {
|
||||
var len = this.length;
|
||||
if (!len) return proxied.apply(this, arguments);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var elem = this[i];
|
||||
// set/get SVG attribute
|
||||
if (elem.namespaceURI === svgns) {
|
||||
// Setting attribute
|
||||
if (value !== undefined) {
|
||||
elem.setAttribute(key, value);
|
||||
} else if ($.isArray(key)) {
|
||||
// Getting attributes from array
|
||||
var j = key.length, obj = {};
|
||||
|
||||
while (j--) {
|
||||
var aname = key[j];
|
||||
var attr = elem.getAttribute(aname);
|
||||
// This returns a number when appropriate
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
}
|
||||
obj[aname] = attr;
|
||||
}
|
||||
return obj;
|
||||
} else if (typeof key === "object") {
|
||||
// Setting attributes form object
|
||||
for (var v in key) {
|
||||
elem.setAttribute(v, key[v]);
|
||||
}
|
||||
// Getting attribute
|
||||
} else {
|
||||
var attr = elem.getAttribute(key);
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
} else {
|
||||
return proxied.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}());
|
||||
@@ -6,14 +6,16 @@
|
||||
*/
|
||||
|
||||
// Dependencies:
|
||||
// 1) svgedit.js
|
||||
// 2) browser.js
|
||||
// 3) math.js
|
||||
// 4) history.js
|
||||
// 5) units.js
|
||||
// 6) svgtransformlist.js
|
||||
// 7) svgutils.js
|
||||
// 8) coords.js
|
||||
// 1) jquery
|
||||
// 2) jquery-svg.js
|
||||
// 3) svgedit.js
|
||||
// 4) browser.js
|
||||
// 5) math.js
|
||||
// 6) history.js
|
||||
// 7) units.js
|
||||
// 8) svgtransformlist.js
|
||||
// 9) svgutils.js
|
||||
// 10) coords.js
|
||||
|
||||
var svgedit = svgedit || {};
|
||||
|
||||
@@ -52,7 +54,6 @@ svgedit.recalculate.updateClipPath = function(attr, tx, ty) {
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Function: svgedit.recalculate.recalculateDimensions
|
||||
// Decides the course of action based on the element's transform list
|
||||
//
|
||||
@@ -95,7 +96,9 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
|
||||
|
||||
// if this element had no transforms, we are done
|
||||
if (!tlist || tlist.numberOfItems == 0) {
|
||||
selected.removeAttribute("transform");
|
||||
// Chrome has a bug that requires clearing the attribute first.
|
||||
selected.setAttribute('transform', '');
|
||||
selected.removeAttribute('transform');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<script type="text/javascript" src="svgedit.compiled.js"></script>
|
||||
<!{else}-->
|
||||
<script type="text/javascript" src="svgedit.js"></script>
|
||||
<script type="text/javascript" src="jquery-svg.js"></script>
|
||||
<script type="text/javascript" src="contextmenu/jquery.contextMenu.js"></script>
|
||||
<script type="text/javascript" src="browser.js"></script>
|
||||
<script type="text/javascript" src="svgtransformlist.js"></script>
|
||||
|
||||
@@ -36,64 +36,6 @@ if (window.opera) {
|
||||
}
|
||||
|
||||
(function() {
|
||||
// This fixes $(...).attr() to work as expected with SVG elements.
|
||||
// Does not currently use *AttributeNS() since we rarely need that.
|
||||
|
||||
// See http://api.jquery.com/attr/ for basic documentation of .attr()
|
||||
|
||||
// Additional functionality:
|
||||
// - When getting attributes, a string that's a number is return as type number.
|
||||
// - If an array is supplied as first parameter, multiple values are returned
|
||||
// as an object with values for each given attributes
|
||||
|
||||
var proxied = jQuery.fn.attr,
|
||||
// TODO use NS.SVG instead
|
||||
svgns = "http://www.w3.org/2000/svg";
|
||||
jQuery.fn.attr = function(key, value) {
|
||||
var len = this.length;
|
||||
if (!len) return proxied.apply(this, arguments);
|
||||
for (var i=0; i<len; i++) {
|
||||
var elem = this[i];
|
||||
// set/get SVG attribute
|
||||
if (elem.namespaceURI === svgns) {
|
||||
// Setting attribute
|
||||
if (value !== undefined) {
|
||||
elem.setAttribute(key, value);
|
||||
} else if ($.isArray(key)) {
|
||||
// Getting attributes from array
|
||||
var j = key.length,
|
||||
obj = {};
|
||||
|
||||
while (j--) {
|
||||
var aname = key[j];
|
||||
var attr = elem.getAttribute(aname);
|
||||
// This returns a number when appropriate
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr)?attr:attr-0;
|
||||
}
|
||||
obj[aname] = attr;
|
||||
}
|
||||
return obj;
|
||||
} else if (typeof key === "object") {
|
||||
// Setting attributes form object
|
||||
for (var v in key) {
|
||||
elem.setAttribute(v, key[v]);
|
||||
}
|
||||
// Getting attribute
|
||||
} else {
|
||||
var attr = elem.getAttribute(key);
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr)?attr:attr-0;
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
} else {
|
||||
return proxied.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}());
|
||||
|
||||
// Class: SvgCanvas
|
||||
// The main SvgCanvas class that manages all SVG-related functions
|
||||
|
||||
Reference in New Issue
Block a user