Minor optimizations, fixed issue 706: Revision 1774 Spooges icons on Firefox 4.0b
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1777 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -253,7 +253,7 @@
|
|||||||
$.svgIcons(curConfig.imgPath + 'svg_edit_icons.svg', {
|
$.svgIcons(curConfig.imgPath + 'svg_edit_icons.svg', {
|
||||||
w:24, h:24,
|
w:24, h:24,
|
||||||
id_match: false,
|
id_match: false,
|
||||||
no_img: (!!window.opera), // Opera gives odd behavior w/images
|
no_img: !isWebkit, // Opera & Firefox 4 gives odd behavior w/images
|
||||||
fallback_path: curConfig.imgPath,
|
fallback_path: curConfig.imgPath,
|
||||||
fallback:{
|
fallback:{
|
||||||
'new_image':'clear.png',
|
'new_image':'clear.png',
|
||||||
@@ -458,10 +458,10 @@
|
|||||||
"#ffaaaa", "#ffd4aa", "#ffffaa", "#d4ffaa",
|
"#ffaaaa", "#ffd4aa", "#ffffaa", "#d4ffaa",
|
||||||
"#aaffaa", "#aaffd4", "#aaffff", "#aad4ff",
|
"#aaffaa", "#aaffd4", "#aaffff", "#aad4ff",
|
||||||
"#aaaaff", "#d4aaff", "#ffaaff", "#ffaad4",
|
"#aaaaff", "#d4aaff", "#ffaaff", "#ffaad4",
|
||||||
];
|
],
|
||||||
|
isMac = (navigator.platform.indexOf("Mac") >= 0),
|
||||||
isMac = (navigator.platform.indexOf("Mac") >= 0);
|
isWebkit = (navigator.userAgent.indexOf("AppleWebKit") >= 0),
|
||||||
modKey = (isMac ? "meta+" : "ctrl+"); // ⌘
|
modKey = (isMac ? "meta+" : "ctrl+"), // ⌘
|
||||||
path = svgCanvas.pathActions,
|
path = svgCanvas.pathActions,
|
||||||
undoMgr = svgCanvas.undoMgr,
|
undoMgr = svgCanvas.undoMgr,
|
||||||
Utils = svgCanvas.Utils,
|
Utils = svgCanvas.Utils,
|
||||||
@@ -474,7 +474,7 @@
|
|||||||
tool_scale = 1,
|
tool_scale = 1,
|
||||||
zoomInIcon = 'crosshair',
|
zoomInIcon = 'crosshair',
|
||||||
zoomOutIcon = 'crosshair',
|
zoomOutIcon = 'crosshair',
|
||||||
ui_context = 'toolbars';
|
ui_context = 'toolbars'; alert(isWebkit);
|
||||||
|
|
||||||
// This sets up alternative dialog boxes. They mostly work the same way as
|
// This sets up alternative dialog boxes. They mostly work the same way as
|
||||||
// their UI counterparts, expect instead of returning the result, a callback
|
// their UI counterparts, expect instead of returning the result, a callback
|
||||||
|
|||||||
@@ -7870,7 +7870,7 @@ var svgToString = this.svgToString = function(elem, indent) {
|
|||||||
|
|
||||||
for (var i=0; i<indent; i++) out.push(" ");
|
for (var i=0; i<indent; i++) out.push(" ");
|
||||||
out.push("<"); out.push(elem.nodeName);
|
out.push("<"); out.push(elem.nodeName);
|
||||||
if(elem.id == 'svgcontent') {
|
if(elem.id === 'svgcontent') {
|
||||||
// Process root element separately
|
// Process root element separately
|
||||||
var res = getResolution();
|
var res = getResolution();
|
||||||
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
|
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
|
||||||
@@ -7890,6 +7890,7 @@ var svgToString = this.svgToString = function(elem, indent) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var i = attrs.length;
|
var i = attrs.length;
|
||||||
|
var attr_names = ['width','height','xmlns','x','y','viewBox','id','overflow'];
|
||||||
while (i--) {
|
while (i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
var attrVal = toXml(attr.nodeValue);
|
var attrVal = toXml(attr.nodeValue);
|
||||||
@@ -7898,8 +7899,7 @@ var svgToString = this.svgToString = function(elem, indent) {
|
|||||||
if(attr.nodeName.indexOf('xmlns:') === 0) continue;
|
if(attr.nodeName.indexOf('xmlns:') === 0) continue;
|
||||||
|
|
||||||
// only serialize attributes we don't use internally
|
// only serialize attributes we don't use internally
|
||||||
if (attrVal != "" &&
|
if (attrVal != "" && attr_names.indexOf(attr.localName) >= 0)
|
||||||
['width','height','xmlns','x','y','viewBox','id','overflow'].indexOf(attr.localName) == -1)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!attr.namespaceURI || nsMap[attr.namespaceURI]) {
|
if(!attr.namespaceURI || nsMap[attr.namespaceURI]) {
|
||||||
@@ -7910,11 +7910,12 @@ var svgToString = this.svgToString = function(elem, indent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var moz_attrs = ['-moz-math-font-style', '_moz-math-font-style'];
|
||||||
for (var i=attrs.length-1; i>=0; i--) {
|
for (var i=attrs.length-1; i>=0; i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
var attrVal = toXml(attr.nodeValue);
|
var attrVal = toXml(attr.nodeValue);
|
||||||
//remove bogus attributes added by Gecko
|
//remove bogus attributes added by Gecko
|
||||||
if (['-moz-math-font-style', '_moz-math-font-style'].indexOf(attr.localName) >= 0) continue;
|
if (moz_attrs.indexOf(attr.localName) >= 0) continue;
|
||||||
if (attrVal != "") {
|
if (attrVal != "") {
|
||||||
if(attrVal.indexOf('pointer-events') === 0) continue;
|
if(attrVal.indexOf('pointer-events') === 0) continue;
|
||||||
if(attr.localName === "class" && attrVal.indexOf('se_') === 0) continue;
|
if(attr.localName === "class" && attrVal.indexOf('se_') === 0) continue;
|
||||||
@@ -8122,6 +8123,9 @@ this.randomizeIds = function() {
|
|||||||
// g - The parent element of the tree to give unique IDs
|
// g - The parent element of the tree to give unique IDs
|
||||||
var uniquifyElems = this.uniquifyElems = function(g) {
|
var uniquifyElems = this.uniquifyElems = function(g) {
|
||||||
var ids = {};
|
var ids = {};
|
||||||
|
var ref_attrs = ["clip-path", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"];
|
||||||
|
var ref_elems = ["filter", "linearGradient", "pattern", "radialGradient", "textPath", "use"];
|
||||||
|
|
||||||
walkTree(g, function(n) {
|
walkTree(g, function(n) {
|
||||||
// if it's an element node
|
// if it's an element node
|
||||||
if (n.nodeType == 1) {
|
if (n.nodeType == 1) {
|
||||||
@@ -8137,7 +8141,7 @@ var uniquifyElems = this.uniquifyElems = function(g) {
|
|||||||
|
|
||||||
// now search for all attributes on this element that might refer
|
// now search for all attributes on this element that might refer
|
||||||
// to other elements
|
// to other elements
|
||||||
$.each(["clip-path", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"],function(i,attr) {
|
$.each(ref_attrs,function(i,attr) {
|
||||||
var attrnode = n.getAttributeNode(attr);
|
var attrnode = n.getAttributeNode(attr);
|
||||||
if (attrnode) {
|
if (attrnode) {
|
||||||
// the incoming file has been sanitized, so we should be able to safely just strip off the leading #
|
// the incoming file has been sanitized, so we should be able to safely just strip off the leading #
|
||||||
@@ -8156,9 +8160,7 @@ var uniquifyElems = this.uniquifyElems = function(g) {
|
|||||||
// check xlink:href now
|
// check xlink:href now
|
||||||
var href = getHref(n);
|
var href = getHref(n);
|
||||||
// TODO: what if an <image> or <a> element refers to an element internally?
|
// TODO: what if an <image> or <a> element refers to an element internally?
|
||||||
if(href &&
|
if(href && ref_elems.indexOf(n.nodeName) >= 0)
|
||||||
["filter", "linearGradient", "pattern",
|
|
||||||
"radialGradient", "textPath", "use"].indexOf(n.nodeName) >= 0)
|
|
||||||
{
|
{
|
||||||
var refid = href.substr(1);
|
var refid = href.substr(1);
|
||||||
if (!(refid in ids)) {
|
if (!(refid in ids)) {
|
||||||
@@ -10417,6 +10419,9 @@ var changeSelectedAttributeNoUndo = function(attr, newValue, elems) {
|
|||||||
}
|
}
|
||||||
var elems = elems || selectedElements;
|
var elems = elems || selectedElements;
|
||||||
var i = elems.length;
|
var i = elems.length;
|
||||||
|
var no_xy_elems = ['g', 'polyline', 'path'];
|
||||||
|
var good_g_attrs = ['transform', 'opacity', 'filter'];
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var elem = elems[i];
|
var elem = elems[i];
|
||||||
if (elem == null) continue;
|
if (elem == null) continue;
|
||||||
@@ -10427,19 +10432,19 @@ var changeSelectedAttributeNoUndo = function(attr, newValue, elems) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set x,y vals on elements that don't have them
|
// Set x,y vals on elements that don't have them
|
||||||
if((attr == 'x' || attr == 'y') && ['g', 'polyline', 'path'].indexOf(elem.tagName) >= 0) {
|
if((attr === 'x' || attr === 'y') && no_xy_elems.indexOf(elem.tagName) >= 0) {
|
||||||
var bbox = getStrokedBBox([elem]);
|
var bbox = getStrokedBBox([elem]);
|
||||||
var diff_x = attr == 'x' ? newValue - bbox.x : 0;
|
var diff_x = attr === 'x' ? newValue - bbox.x : 0;
|
||||||
var diff_y = attr == 'y' ? newValue - bbox.y : 0;
|
var diff_y = attr === 'y' ? newValue - bbox.y : 0;
|
||||||
canvas.moveSelectedElements(diff_x*current_zoom, diff_y*current_zoom, true);
|
canvas.moveSelectedElements(diff_x*current_zoom, diff_y*current_zoom, true);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only allow the transform/opacity attribute to change on <g> elements, slightly hacky
|
// only allow the transform/opacity/filter attribute to change on <g> elements, slightly hacky
|
||||||
if (elem.tagName == "g" && ['transform', 'opacity', 'filter'].indexOf(attr) >= 0);
|
if (elem.tagName === "g" && good_g_attrs.indexOf(attr) >= 0);
|
||||||
var oldval = attr == "#text" ? elem.textContent : elem.getAttribute(attr);
|
var oldval = attr === "#text" ? elem.textContent : elem.getAttribute(attr);
|
||||||
if (oldval == null) oldval = "";
|
if (oldval == null) oldval = "";
|
||||||
if (oldval != String(newValue)) {
|
if (oldval !== String(newValue)) {
|
||||||
if (attr == "#text") {
|
if (attr == "#text") {
|
||||||
var old_w = getBBox(elem).width;
|
var old_w = getBBox(elem).width;
|
||||||
elem.textContent = newValue;
|
elem.textContent = newValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user