From 8d54485ea492ad104bce723b9c7d3217ca24e654 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Fri, 28 Aug 2009 19:20:54 +0000 Subject: [PATCH] Fixed issue 139: After copying the SVG code from one window/file to another, object browser SHIFT+O/P function is lost git-svn-id: http://svg-edit.googlecode.com/svn/trunk@495 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 71 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index ec3c9ef8..620a1245 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -590,22 +590,7 @@ function SvgCanvas(c) if(!curBBoxes.length) { // Cache all bboxes - - var nodes = svgroot.childNodes; - var i = svgroot.childNodes.length; - - while (i--) { - // need to do this since the defs has no bbox and causes an exception - // to be thrown in Mozilla - try { - var box = canvas.getBBox(nodes[i]); - if (nodes[i].id != "selectorParentGroup" && box) { - curBBoxes.push({'elem':nodes[i], 'bbox':box}); - } - } catch(e) { - // do nothing, this element did not have a bbox - } - } + curBBoxes = canvas.getVisibleElements(true); } var resultList = null; @@ -1142,7 +1127,7 @@ function SvgCanvas(c) } ++j; } - + // now add each element consecutively var i = elemsToAdd.length; while (i--) { @@ -2724,30 +2709,44 @@ function SvgCanvas(c) } }; + this.getVisibleElements = function(includeBBox) { + var nodes = svgroot.childNodes; + var i = nodes.length; + var contentElems = []; + + while (i--) { + var elem = nodes[i]; + try { + var box = canvas.getBBox(elem); + if (elem.id != "selectorParentGroup" && box) { + var item = includeBBox?{'elem':elem, 'bbox':box}:elem; + contentElems.push(item); + } + } catch(e) {} + } + return contentElems; + } + this.cycleElement = function(next) { var cur_elem = selectedElements[0]; var elem = false; + var all_elems = this.getVisibleElements(); if (cur_elem == null) { - if(next) { - var elem = svgroot.firstChild; - if (elem.tagName == 'defs') { - elem = elem.nextSibling; - } - } else { - var elem = svgroot.lastChild; - var id = elem.getAttribute('id'); - if(!id || id.indexOf('svg_') != 0){ - elem = elem.previousSibling; - } - } + var num = next?all_elems.length-1:0; + elem = all_elems[num]; } else { - var type = next?'next':'previous'; - var elem = cur_elem[type + 'Sibling']; - if(!elem) return; - - var id = elem.getAttribute('id'); - if(!id || id.indexOf('svg_') != 0) { - return; + var i = all_elems.length; + while(i--) { + if(all_elems[i] == cur_elem) { + var num = next?i-1:i+1; + if(num >= all_elems.length || num < 0) { + elem = cur_elem; + break; + } else { + elem = all_elems[num]; + break; + } + } } } canvas.clearSelection();