git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2641 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-01-31 00:39:35 +00:00
parent afa427a4a2
commit 0df050aeb4
1 changed files with 161 additions and 152 deletions

View File

@ -1,3 +1,5 @@
/*globals $*/
/*jslint vars: true, eqeq: true */
/* /*
* svgcanvas.js * svgcanvas.js
* *
@ -310,9 +312,9 @@ canvas.undoMgr = new svgedit.history.UndoManager({
canvas.identifyLayers(); canvas.identifyLayers();
} }
if (cmdType == InsertElementCommand.type()) { if (cmdType == InsertElementCommand.type()) {
if (isApply) restoreRefElems(cmd.elem); if (isApply) {restoreRefElems(cmd.elem);}
} else { } else {
if (!isApply) restoreRefElems(cmd.elem); if (!isApply) {restoreRefElems(cmd.elem);}
} }
if (cmd.elem.tagName === 'use') { if (cmd.elem.tagName === 'use') {
setUseData(cmd.elem); setUseData(cmd.elem);
@ -390,8 +392,9 @@ $(opac_ani).attr({
var restoreRefElems = function(elem) { var restoreRefElems = function(elem) {
// Look for missing reference elements, restore any found // Look for missing reference elements, restore any found
var attrs = $(elem).attr(ref_attrs); var o, i,
for (var o in attrs) { attrs = $(elem).attr(ref_attrs);
for (o in attrs) {
var val = attrs[o]; var val = attrs[o];
if (val && val.indexOf('url(') === 0) { if (val && val.indexOf('url(') === 0) {
var id = svgedit.utilities.getUrlFromAttr(val).substr(1); var id = svgedit.utilities.getUrlFromAttr(val).substr(1);
@ -406,7 +409,7 @@ var restoreRefElems = function(elem) {
var childs = elem.getElementsByTagName('*'); var childs = elem.getElementsByTagName('*');
if (childs.length) { if (childs.length) {
for (var i = 0, l = childs.length; i < l; i++) { for (i = 0, l = childs.length; i < l; i++) {
restoreRefElems(childs[i]); restoreRefElems(childs[i]);
} }
} }
@ -554,9 +557,10 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
if (!rect) { if (!rect) {
var rubberBBox = rubberBox.getBBox(); var rubberBBox = rubberBox.getBBox();
var bb = {}; var o,
bb = {};
for (var o in rubberBBox) { for (o in rubberBBox) {
bb[o] = rubberBBox[o] / current_zoom; bb[o] = rubberBBox[o] / current_zoom;
} }
rubberBBox = bb; rubberBBox = bb;
@ -566,7 +570,7 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
} }
var i = curBBoxes.length; var i = curBBoxes.length;
while (i--) { while (i--) {
if (!rubberBBox.width || !rubberBBox.width) continue; if (!rubberBBox.width || !rubberBBox.width) {continue;}
if (svgedit.math.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) { if (svgedit.math.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
resultList.push(curBBoxes[i].elem); resultList.push(curBBoxes[i].elem);
} }
@ -588,8 +592,8 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
// Returns: // Returns:
// A single bounding box object // A single bounding box object
getStrokedBBox = this.getStrokedBBox = function(elems) { getStrokedBBox = this.getStrokedBBox = function(elems) {
if (!elems) elems = getVisibleElements(); if (!elems) {elems = getVisibleElements();}
if (!elems.length) return false; if (!elems.length) {return false;}
// Make sure the expected BBox is returned if the element is a group // Make sure the expected BBox is returned if the element is a group
var getCheckedBBox = function(elem) { var getCheckedBBox = function(elem) {
@ -672,13 +676,13 @@ getStrokedBBox = this.getStrokedBBox = function(elems) {
var full_bb; var full_bb;
$.each(elems, function() { $.each(elems, function() {
if (full_bb) return; if (full_bb) {return;}
if (!this.parentNode) return; if (!this.parentNode) {return;}
full_bb = getCheckedBBox(this); full_bb = getCheckedBBox(this);
}); });
// This shouldn't ever happen... // This shouldn't ever happen...
if (full_bb == null) return null; if (full_bb == null) {return null;}
// full_bb doesn't include the stoke, so this does no good! // full_bb doesn't include the stoke, so this does no good!
// if (elems.length == 1) return full_bb; // if (elems.length == 1) return full_bb;
@ -737,7 +741,9 @@ getStrokedBBox = this.getStrokedBBox = function(elems) {
// Returns: // Returns:
// An array with all "visible" elements. // An array with all "visible" elements.
var getVisibleElements = this.getVisibleElements = function(parent) { var getVisibleElements = this.getVisibleElements = function(parent) {
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) {
@ -763,8 +769,9 @@ var getVisibleElements = this.getVisibleElements = function(parent) {
// * elem - The element // * elem - The element
// * bbox - The element's BBox as retrieved from getStrokedBBox // * bbox - The element's BBox as retrieved from getStrokedBBox
var getVisibleElementsAndBBoxes = this.getVisibleElementsAndBBoxes = function(parent) { var getVisibleElementsAndBBoxes = this.getVisibleElementsAndBBoxes = function(parent) {
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 {
@ -887,9 +894,10 @@ this.prepareSvg = function(newDoc) {
this.sanitizeSvg(newDoc.documentElement); this.sanitizeSvg(newDoc.documentElement);
// convert paths into absolute commands // convert paths into absolute commands
var paths = newDoc.getElementsByTagNameNS(NS.SVG, "path"); var i, path,
for (var i = 0, len = paths.length; i < len; ++i) { paths = newDoc.getElementsByTagNameNS(NS.SVG, "path");
var path = paths[i]; for (i = 0, len = paths.length; i < len; ++i) {
path = paths[i];
path.setAttribute('d', pathActions.convertPath(path)); path.setAttribute('d', pathActions.convertPath(path));
pathActions.fixEnd(path); pathActions.fixEnd(path);
} }
@ -905,7 +913,7 @@ this.prepareSvg = function(newDoc) {
// Parameters: // Parameters:
// elem - The (text) DOM element to clone // elem - The (text) DOM element to clone
var ffClone = function(elem) { var ffClone = function(elem) {
if (!svgedit.browser.isGecko()) return elem; if (!svgedit.browser.isGecko()) {return elem;}
var clone = elem.cloneNode(true); var clone = elem.cloneNode(true);
elem.parentNode.insertBefore(clone, elem); elem.parentNode.insertBefore(clone, elem);
elem.parentNode.removeChild(elem); elem.parentNode.removeChild(elem);
@ -1021,16 +1029,17 @@ var root_sctm = null;
// noCall - Optional boolean that when true does not call the "selected" handler // noCall - Optional boolean that when true does not call the "selected" handler
var clearSelection = this.clearSelection = function(noCall) { var clearSelection = this.clearSelection = function(noCall) {
if (selectedElements[0] != null) { if (selectedElements[0] != null) {
var len = selectedElements.length; var i, elem,
for (var i = 0; i < len; ++i) { len = selectedElements.length;
var elem = selectedElements[i]; for (i = 0; i < len; ++i) {
if (elem == null) break; elem = selectedElements[i];
if (elem == null) {break;}
selectorManager.releaseSelector(elem); selectorManager.releaseSelector(elem);
selectedElements[i] = null; selectedElements[i] = null;
} }
// selectedBBoxes[0] = null; // selectedBBoxes[0] = null;
} }
if (!noCall) call("selected", selectedElements); if (!noCall) {call("selected", selectedElements);}
}; };
// TODO: do we need to worry about selectedBBoxes here? // TODO: do we need to worry about selectedBBoxes here?
@ -1058,7 +1067,7 @@ var addToSelection = this.addToSelection = function(elemsToAdd, showGrips) {
var i = elemsToAdd.length; var i = elemsToAdd.length;
while (i--) { while (i--) {
var elem = elemsToAdd[i]; var elem = elemsToAdd[i];
if (!elem || !svgedit.utilities.getBBox(elem)) continue; if (!elem || !svgedit.utilities.getBBox(elem)) {continue;}
if (elem.tagName === 'a' && elem.childNodes.length === 1) { if (elem.tagName === 'a' && elem.childNodes.length === 1) {
// Make "a" element's child be the selected element // Make "a" element's child be the selected element