Made separate getVisibleElementsAndBBoxes() function

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1871 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-11-14 19:01:00 +00:00
parent 1918ddae7a
commit 82f57ab4ab
1 changed files with 32 additions and 12 deletions

View File

@ -1084,7 +1084,7 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
if(!curBBoxes.length) { if(!curBBoxes.length) {
// Cache all bboxes // Cache all bboxes
curBBoxes = getVisibleElements(parent, true); curBBoxes = getVisibleElementsAndBBoxes(parent);
} }
var resultList = null; var resultList = null;
@ -1279,28 +1279,48 @@ var getStrokedBBox = this.getStrokedBBox = function(elems) {
// //
// Parameters: // Parameters:
// parent - The parent DOM element to search within // parent - The parent DOM element to search within
// includeBBox - Boolean to indicate that an object should return with the element and its bbox
// //
// Returns: // Returns:
// An array with all "visible" elements, or if includeBBox is true, an array with // An array with all "visible" elements.
// objects that include: var getVisibleElements = this.getVisibleElements = function(parent) {
// * elem - The element
// * bbox - The element's BBox as retrieved from getStrokedBBox
var getVisibleElements = this.getVisibleElements = function(parent, includeBBox) {
if(!parent) parent = $(svgcontent).children(); // Prevent layers from being included if(!parent) parent = $(svgcontent).children(); // Prevent layers from being included
var contentElems = []; var contentElems = [];
$(parent).children().each(function(i, elem) { $(parent).children().each(function(i, elem) {
try { try {
var box = elem.getBBox(); if (elem.getBBox()) {
if (box) { contentElems.push(elem);
var item = includeBBox?{'elem':elem, 'bbox':getStrokedBBox([elem])}:elem;
contentElems.push(item);
} }
} catch(e) {} } catch(e) {}
}); });
return contentElems.reverse(); return contentElems.reverse();
} };
// Function: getVisibleElementsAndBBoxes
// Get all elements that have a BBox (excludes <defs>, <title>, 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 // Function: groupSvgElem
// Wrap an SVG element into a group element, mark the group as 'gsvg' // Wrap an SVG element into a group element, mark the group as 'gsvg'