From 3a637498c88dd05bb43577f3b1e2827d7e25370c Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Tue, 5 Oct 2010 18:50:21 +0000 Subject: [PATCH] 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 --- editor/svg-editor.js | 12 ++++++------ editor/svgcanvas.js | 35 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 09a71e61..8147944d 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -253,7 +253,7 @@ $.svgIcons(curConfig.imgPath + 'svg_edit_icons.svg', { w:24, h:24, 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:{ 'new_image':'clear.png', @@ -458,10 +458,10 @@ "#ffaaaa", "#ffd4aa", "#ffffaa", "#d4ffaa", "#aaffaa", "#aaffd4", "#aaffff", "#aad4ff", "#aaaaff", "#d4aaff", "#ffaaff", "#ffaad4", - ]; - - isMac = (navigator.platform.indexOf("Mac") >= 0); - modKey = (isMac ? "meta+" : "ctrl+"); // ⌘ + ], + isMac = (navigator.platform.indexOf("Mac") >= 0), + isWebkit = (navigator.userAgent.indexOf("AppleWebKit") >= 0), + modKey = (isMac ? "meta+" : "ctrl+"), // ⌘ path = svgCanvas.pathActions, undoMgr = svgCanvas.undoMgr, Utils = svgCanvas.Utils, @@ -474,7 +474,7 @@ tool_scale = 1, zoomInIcon = 'crosshair', zoomOutIcon = 'crosshair', - ui_context = 'toolbars'; + ui_context = 'toolbars'; alert(isWebkit); // This sets up alternative dialog boxes. They mostly work the same way as // their UI counterparts, expect instead of returning the result, a callback diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index cf152cf4..ccb8882e 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -7870,7 +7870,7 @@ var svgToString = this.svgToString = function(elem, indent) { for (var i=0; i= 0) { if(!attr.namespaceURI || nsMap[attr.namespaceURI]) { @@ -7910,11 +7910,12 @@ var svgToString = this.svgToString = function(elem, indent) { } } } else { + var moz_attrs = ['-moz-math-font-style', '_moz-math-font-style']; for (var i=attrs.length-1; i>=0; i--) { attr = attrs.item(i); var attrVal = toXml(attr.nodeValue); //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.indexOf('pointer-events') === 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 var uniquifyElems = this.uniquifyElems = function(g) { 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) { // if it's an element node 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 // 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); if (attrnode) { // 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 var href = getHref(n); // TODO: what if an or element refers to an element internally? - if(href && - ["filter", "linearGradient", "pattern", - "radialGradient", "textPath", "use"].indexOf(n.nodeName) >= 0) + if(href && ref_elems.indexOf(n.nodeName) >= 0) { var refid = href.substr(1); if (!(refid in ids)) { @@ -10417,6 +10419,9 @@ var changeSelectedAttributeNoUndo = function(attr, newValue, elems) { } var elems = elems || selectedElements; var i = elems.length; + var no_xy_elems = ['g', 'polyline', 'path']; + var good_g_attrs = ['transform', 'opacity', 'filter']; + while (i--) { var elem = elems[i]; 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 - 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 diff_x = attr == 'x' ? newValue - bbox.x : 0; - var diff_y = attr == 'y' ? newValue - bbox.y : 0; + var diff_x = attr === 'x' ? newValue - bbox.x : 0; + var diff_y = attr === 'y' ? newValue - bbox.y : 0; canvas.moveSelectedElements(diff_x*current_zoom, diff_y*current_zoom, true); continue; } - // only allow the transform/opacity attribute to change on elements, slightly hacky - if (elem.tagName == "g" && ['transform', 'opacity', 'filter'].indexOf(attr) >= 0); - var oldval = attr == "#text" ? elem.textContent : elem.getAttribute(attr); + // only allow the transform/opacity/filter attribute to change on elements, slightly hacky + if (elem.tagName === "g" && good_g_attrs.indexOf(attr) >= 0); + var oldval = attr === "#text" ? elem.textContent : elem.getAttribute(attr); if (oldval == null) oldval = ""; - if (oldval != String(newValue)) { + if (oldval !== String(newValue)) { if (attr == "#text") { var old_w = getBBox(elem).width; elem.textContent = newValue;