From 82f57ab4abf8232dace13ecc75ac4d79164d40d3 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Sun, 14 Nov 2010 19:01:00 +0000 Subject: [PATCH] Made separate getVisibleElementsAndBBoxes() function git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1871 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index e3388d74..b79566a2 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1084,7 +1084,7 @@ var getIntersectionList = this.getIntersectionList = function(rect) { if(!curBBoxes.length) { // Cache all bboxes - curBBoxes = getVisibleElements(parent, true); + curBBoxes = getVisibleElementsAndBBoxes(parent); } var resultList = null; @@ -1279,28 +1279,48 @@ var getStrokedBBox = this.getStrokedBBox = function(elems) { // // Parameters: // parent - The parent DOM element to search within -// includeBBox - Boolean to indicate that an object should return with the element and its bbox // // Returns: -// An array with all "visible" elements, or if includeBBox is true, an array with -// objects that include: -// * elem - The element -// * bbox - The element's BBox as retrieved from getStrokedBBox -var getVisibleElements = this.getVisibleElements = function(parent, includeBBox) { +// An array with all "visible" elements. +var getVisibleElements = this.getVisibleElements = function(parent) { if(!parent) parent = $(svgcontent).children(); // Prevent layers from being included var contentElems = []; $(parent).children().each(function(i, elem) { try { - var box = elem.getBBox(); - if (box) { - var item = includeBBox?{'elem':elem, 'bbox':getStrokedBBox([elem])}:elem; - contentElems.push(item); + if (elem.getBBox()) { + contentElems.push(elem); } } catch(e) {} }); return contentElems.reverse(); -} +}; + +// Function: getVisibleElementsAndBBoxes +// Get all elements that have a BBox (excludes , , etc). +// Note that 0-opacity, off-screen etc elements are still considered "visible" +// for this function +// +// Parameters: +// parent - The parent DOM element to search within +// +// Returns: +// An array with objects that include: +// * elem - The element +// * bbox - The element's BBox as retrieved from getStrokedBBox +var getVisibleElementsAndBBoxes = this.getVisibleElementsAndBBoxes = function(parent) { + if(!parent) parent = $(svgcontent).children(); // Prevent layers from being included + + var contentElems = []; + $(parent).children().each(function(i, elem) { + try { + if (elem.getBBox()) { + contentElems.push({'elem':elem, 'bbox':getStrokedBBox([elem])}); + } + } catch(e) {} + }); + return contentElems.reverse(); +}; // Function: groupSvgElem // Wrap an SVG element into a group element, mark the group as 'gsvg'