From a439a8fea50c53e6c85fccffb1173f7f70897cc4 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Thu, 28 Oct 2010 16:04:35 +0000 Subject: [PATCH] Fixed icons in Opera which were broken due to jQuery 1.4.3 git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1832 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 8 ++--- editor/svgicons/jquery.svgicons.js | 49 +++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 92206035..b1bdeccd 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -3198,7 +3198,7 @@ var buttonsNeedingStroke = [ '#tool_fhpath', '#tool_line' ]; var buttonsNeedingFillAndStroke = [ '#tools_rect .tool_button', '#tools_ellipse .tool_button', '#tool_text', '#tool_path']; if (bNoStroke) { - for (index in buttonsNeedingStroke) { + for (var index in buttonsNeedingStroke) { var button = buttonsNeedingStroke[index]; if ($(button).hasClass('tool_button_current')) { clickSelect(); @@ -3207,14 +3207,14 @@ } } else { - for (index in buttonsNeedingStroke) { + for (var index in buttonsNeedingStroke) { var button = buttonsNeedingStroke[index]; $(button).removeClass('disabled'); } } if (bNoStroke && bNoFill) { - for (index in buttonsNeedingFillAndStroke) { + for (var index in buttonsNeedingFillAndStroke) { var button = buttonsNeedingFillAndStroke[index]; if ($(button).hasClass('tool_button_current')) { clickSelect(); @@ -3223,7 +3223,7 @@ } } else { - for (index in buttonsNeedingFillAndStroke) { + for (var index in buttonsNeedingFillAndStroke) { var button = buttonsNeedingFillAndStroke[index]; $(button).removeClass('disabled'); } diff --git a/editor/svgicons/jquery.svgicons.js b/editor/svgicons/jquery.svgicons.js index b3ffb14d..7471f242 100644 --- a/editor/svgicons/jquery.svgicons.js +++ b/editor/svgicons/jquery.svgicons.js @@ -357,25 +357,52 @@ $(function() { var defs = svg_el.find('defs'); if(!defs.length) return svg_el; - defs.find('[id]').each(function(i) { + if(isOpera) { + var id_elems = defs.find('*').filter(function() { + return !!this.id; + }); + } else { + var id_elems = defs.find('[id]'); + } + + var all_elems = svg_el[0].getElementsByTagName('*'), len = all_elems.length; + + id_elems.each(function(i) { var id = this.id; var no_dupes = ($(svgdoc).find('#' + id).length <= 1); if(isOpera) no_dupes = false; // Opera didn't clone svg_el, so not reliable // if(!force && no_dupes) return; var new_id = 'x' + id + svg_num + i; this.id = new_id; + + var old_val = 'url(#' + id + ')'; + var new_val = 'url(#' + new_id + ')'; + + // Selector method, possibly faster but fails in Opera / jQuery 1.4.3 +// svg_el.find('[fill="url(#' + id + ')"]').each(function() { +// this.setAttribute('fill', 'url(#' + new_id + ')'); +// }).end().find('[stroke="url(#' + id + ')"]').each(function() { +// this.setAttribute('stroke', 'url(#' + new_id + ')'); +// }).end().find('use').each(function() { +// if(this.getAttribute('xlink:href') == '#' + id) { +// this.setAttributeNS(xlinkns,'href','#' + new_id); +// } +// }).end().find('[filter="url(#' + id + ')"]').each(function() { +// this.setAttribute('filter', 'url(#' + new_id + ')'); +// }); - svg_el.find('[fill="url(#' + id + ')"]').each(function() { - this.setAttribute('fill', 'url(#' + new_id + ')'); - }).end().find('[stroke="url(#' + id + ')"]').each(function() { - this.setAttribute('stroke', 'url(#' + new_id + ')'); - }).end().find('use').each(function() { - if(this.getAttribute('xlink:href') == '#' + id) { - this.setAttributeNS(xlinkns,'href','#' + new_id); + for(var i = 0; i < len; i++) { + var elem = all_elems[i]; + if(elem.getAttribute('fill') === old_val) { + elem.setAttribute('fill', new_val); } - }).end().find('[filter="url(#' + id + ')"]').each(function() { - this.setAttribute('filter', 'url(#' + new_id + ')'); - }); + if(elem.getAttribute('stroke') === old_val) { + elem.setAttribute('stroke', new_val); + } + if(elem.getAttribute('filter') === old_val) { + elem.setAttribute('filter', new_val); + } + } }); return svg_el; }