More JSLint

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2642 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-01-31 01:05:03 +00:00
parent 0df050aeb4
commit d12694f9fa
5 changed files with 111 additions and 83 deletions

View File

@ -1,3 +1,5 @@
/*globals $, svgedit, svgroot*/
/*jslint vars: true, eqeq: true, continue: true*/
/** /**
* Package: svgedit.path * Package: svgedit.path
* *
@ -13,7 +15,7 @@
// 3) math.js // 3) math.js
// 4) svgutils.js // 4) svgutils.js
(function() { (function() {'use strict';
if (!svgedit.path) { if (!svgedit.path) {
svgedit.path = {}; svgedit.path = {};
@ -75,12 +77,13 @@ svgedit.path.insertItemBefore = function(elem, newseg, index) {
} }
var len = list.numberOfItems; var len = list.numberOfItems;
var arr = []; var arr = [];
for (var i=0; i<len; i++) { var i;
for (i=0; i < len; i++) {
var cur_seg = list.getItem(i); var cur_seg = list.getItem(i);
arr.push(cur_seg); arr.push(cur_seg);
} }
list.clear(); list.clear();
for (var i=0; i<len; i++) { for (i=0; i < len; i++) {
if (i == index) { //index+1 if (i == index) { //index+1
list.appendItem(newseg); list.appendItem(newseg);
} }
@ -92,7 +95,8 @@ svgedit.path.insertItemBefore = function(elem, newseg, index) {
svgedit.path.ptObjToArr = function(type, seg_item) { svgedit.path.ptObjToArr = function(type, seg_item) {
var arr = segData[type], len = arr.length; var arr = segData[type], len = arr.length;
var out = Array(len); var out = Array(len);
for (var i=0; i<len; i++) { var i;
for (i = 0; i < len; i++) {
out[i] = seg_item[arr[i]]; out[i] = seg_item[arr[i]];
} }
return out; return out;
@ -122,7 +126,7 @@ svgedit.path.getPointFromGrip = function(pt, path) {
}; };
if (path.matrix) { if (path.matrix) {
var pt = svgedit.math.transformPoint(out.x, out.y, path.imatrix); pt = svgedit.math.transformPoint(out.x, out.y, path.imatrix);
out.x = pt.x; out.x = pt.x;
out.y = pt.y; out.y = pt.y;
} }
@ -156,7 +160,9 @@ svgedit.path.addPointGrip = function(index, x, y) {
var grip = $('#pathpointgrip_'+index); var grip = $('#pathpointgrip_'+index);
grip.dblclick(function() { grip.dblclick(function() {
if (svgedit.path.path) svgedit.path.path.setSegType(); if (svgedit.path.path) {
svgedit.path.path.setSegType();
}
}); });
} }
if (x && y) { if (x && y) {
@ -182,7 +188,7 @@ svgedit.path.getGripContainer = function() {
svgedit.path.addCtrlGrip = function(id) { svgedit.path.addCtrlGrip = function(id) {
var pointGrip = svgedit.utilities.getElem('ctrlpointgrip_'+id); var pointGrip = svgedit.utilities.getElem('ctrlpointgrip_'+id);
if (pointGrip) return pointGrip; if (pointGrip) {return pointGrip;}
pointGrip = document.createElementNS(NS.SVG, 'circle'); pointGrip = document.createElementNS(NS.SVG, 'circle');
svgedit.utilities.assignAttributes(pointGrip, { svgedit.utilities.assignAttributes(pointGrip, {
@ -202,7 +208,7 @@ svgedit.path.addCtrlGrip = function(id) {
svgedit.path.getCtrlLine = function(id) { svgedit.path.getCtrlLine = function(id) {
var ctrlLine = svgedit.utilities.getElem('ctrlLine_'+id); var ctrlLine = svgedit.utilities.getElem('ctrlLine_'+id);
if (ctrlLine) return ctrlLine; if (ctrlLine) {return ctrlLine;}
ctrlLine = document.createElementNS(NS.SVG, 'line'); ctrlLine = document.createElementNS(NS.SVG, 'line');
svgedit.utilities.assignAttributes(ctrlLine, { svgedit.utilities.assignAttributes(ctrlLine, {
@ -234,7 +240,7 @@ svgedit.path.getPointGrip = function(seg, update) {
svgedit.path.getControlPoints = function(seg) { svgedit.path.getControlPoints = function(seg) {
var item = seg.item; var item = seg.item;
var index = seg.index; var index = seg.index;
if (!('x1' in item) || !('x2' in item)) return null; if (!('x1' in item) || !('x2' in item)) {return null;}
var cpt = {}; var cpt = {};
var pointGripContainer = svgedit.path.getGripContainer(); var pointGripContainer = svgedit.path.getGripContainer();
@ -243,7 +249,8 @@ svgedit.path.getControlPoints = function(seg) {
var seg_items = [prev, item]; var seg_items = [prev, item];
for (var i=1; i<3; i++) { var i;
for (i = 1; i < 3; i++) {
var id = index + 'c' + i; var id = index + 'c' + i;
var ctrlLine = cpt['c' + i + '_line'] = svgedit.path.getCtrlLine(id); var ctrlLine = cpt['c' + i + '_line'] = svgedit.path.getCtrlLine(id);
@ -286,12 +293,13 @@ svgedit.path.replacePathSeg = function(type, index, pts, elem) {
var segList = path.pathSegList; var segList = path.pathSegList;
var len = segList.numberOfItems; var len = segList.numberOfItems;
var arr = []; var arr = [];
for (var i=0; i<len; i++) { var i;
for (i = 0; i < len; i++) {
var cur_seg = segList.getItem(i); var cur_seg = segList.getItem(i);
arr.push(cur_seg); arr.push(cur_seg);
} }
segList.clear(); segList.clear();
for (var i=0; i<len; i++) { for (i = 0; i < len; i++) {
if (i == index) { if (i == index) {
segList.appendItem(seg); segList.appendItem(seg);
} else { } else {
@ -332,8 +340,9 @@ svgedit.path.getSegSelector = function(seg, update) {
svgedit.path.replacePathSeg(2, 0, [pt.x, pt.y], segLine); svgedit.path.replacePathSeg(2, 0, [pt.x, pt.y], segLine);
var pts = svgedit.path.ptObjToArr(seg.type, seg.item, true); var pts = svgedit.path.ptObjToArr(seg.type, seg.item, true);
for (var i=0; i < pts.length; i+=2) { var i;
var pt = svgedit.path.getGripPt(seg, {x:pts[i], y:pts[i+1]}); for (i = 0; i < pts.length; i += 2) {
pt = svgedit.path.getGripPt(seg, {x:pts[i], y:pts[i+1]});
pts[i] = pt.x; pts[i] = pt.x;
pts[i+1] = pt.y; pts[i+1] = pt.y;
} }
@ -406,7 +415,8 @@ svgedit.path.Segment = function(index, item) {
}; };
svgedit.path.Segment.prototype.showCtrlPts = function(y) { svgedit.path.Segment.prototype.showCtrlPts = function(y) {
for (var i in this.ctrlpts) { var i;
for (i in this.ctrlpts) {
this.ctrlpts[i].setAttribute('display', y ? 'inline' : 'none'); this.ctrlpts[i].setAttribute('display', y ? 'inline' : 'none');
} }
}; };
@ -484,14 +494,14 @@ svgedit.path.Segment.prototype.move = function(dx, dy) {
if (this.mate) { if (this.mate) {
// The last point of a closed subpath has a 'mate', // The last point of a closed subpath has a 'mate',
// which is the 'M' segment of the subpath // which is the 'M' segment of the subpath
var item = this.mate.item; item = this.mate.item;
var pts = [item.x += dx, item.y += dy]; var pts = [item.x += dx, item.y += dy];
svgedit.path.replacePathSeg(this.mate.type, this.mate.index, pts); svgedit.path.replacePathSeg(this.mate.type, this.mate.index, pts);
// Has no grip, so does not need 'updating'? // Has no grip, so does not need 'updating'?
} }
this.update(true); this.update(true);
if (this.next) this.next.update(true); if (this.next) {this.next.update(true);}
}; };
svgedit.path.Segment.prototype.setLinked = function(num) { svgedit.path.Segment.prototype.setLinked = function(num) {
@ -499,12 +509,12 @@ svgedit.path.Segment.prototype.setLinked = function(num) {
if (num == 2) { if (num == 2) {
anum = 1; anum = 1;
seg = this.next; seg = this.next;
if (!seg) return; if (!seg) {return;}
pt = this.item; pt = this.item;
} else { } else {
anum = 2; anum = 2;
seg = this.prev; seg = this.prev;
if (!seg) return; if (!seg) {return;}
pt = seg.item; pt = seg.item;
} }
@ -566,7 +576,8 @@ svgedit.path.Path.prototype.init = function() {
this.first_seg = null; this.first_seg = null;
// Set up segs array // Set up segs array
for (var i=0; i < len; i++) { var i;
for (i = 0; i < len; i++) {
var item = segList.getItem(i); var item = segList.getItem(i);
var segment = new svgedit.path.Segment(i, item); var segment = new svgedit.path.Segment(i, item);
segment.path = this; segment.path = this;
@ -576,16 +587,16 @@ svgedit.path.Path.prototype.init = function() {
var segs = this.segs; var segs = this.segs;
var start_i = null; var start_i = null;
for (var i=0; i < len; i++) { for (i = 0; i < len; i++) {
var seg = segs[i]; var seg = segs[i];
var next_seg = (i+1) >= len ? null : segs[i+1]; var next_seg = (i+1) >= len ? null : segs[i+1];
var prev_seg = (i-1) < 0 ? null : segs[i-1]; var prev_seg = (i-1) < 0 ? null : segs[i-1];
var start_seg;
if (seg.type === 2) { if (seg.type === 2) {
if (prev_seg && prev_seg.type !== 1) { if (prev_seg && prev_seg.type !== 1) {
// New sub-path, last one is open, // New sub-path, last one is open,
// so add a grip to last sub-path's first point // so add a grip to last sub-path's first point
var start_seg = segs[start_i]; start_seg = segs[start_i];
start_seg.next = segs[start_i+1]; start_seg.next = segs[start_i+1];
start_seg.next.prev = start_seg; start_seg.next.prev = start_seg;
start_seg.addGrip(); start_seg.addGrip();
@ -608,7 +619,7 @@ svgedit.path.Path.prototype.init = function() {
if (seg.type !== 1) { if (seg.type !== 1) {
// Last seg, doesn't close so add a grip // Last seg, doesn't close so add a grip
// to last sub-path's first point // to last sub-path's first point
var start_seg = segs[start_i]; start_seg = segs[start_i];
start_seg.next = segs[start_i+1]; start_seg.next = segs[start_i+1];
start_seg.next.prev = start_seg; start_seg.next.prev = start_seg;
start_seg.addGrip(); start_seg.addGrip();
@ -634,17 +645,18 @@ svgedit.path.Path.prototype.init = function() {
}; };
svgedit.path.Path.prototype.eachSeg = function(fn) { svgedit.path.Path.prototype.eachSeg = function(fn) {
var i;
var len = this.segs.length; var len = this.segs.length;
for (var i=0; i < len; i++) { for (i = 0; i < len; i++) {
var ret = fn.call(this.segs[i], i); var ret = fn.call(this.segs[i], i);
if (ret === false) break; if (ret === false) {break;}
} }
}; };
svgedit.path.Path.prototype.addSeg = function(index) { svgedit.path.Path.prototype.addSeg = function(index) {
// Adds a new segment // Adds a new segment
var seg = this.segs[index]; var seg = this.segs[index];
if (!seg.prev) return; if (!seg.prev) {return;}
var prev = seg.prev; var prev = seg.prev;
var newseg; var newseg;
@ -683,9 +695,10 @@ svgedit.path.Path.prototype.deleteSeg = function(index) {
seg.show(false); seg.show(false);
var next = seg.next; var next = seg.next;
var pt;
if (seg.mate) { if (seg.mate) {
// Make the next point be the "M" point // Make the next point be the "M" point
var pt = [next.item.x, next.item.y]; pt = [next.item.x, next.item.y];
svgedit.path.replacePathSeg(2, next.index, pt); svgedit.path.replacePathSeg(2, next.index, pt);
// Reposition last node // Reposition last node
@ -695,7 +708,7 @@ svgedit.path.Path.prototype.deleteSeg = function(index) {
} else if (!seg.prev) { } else if (!seg.prev) {
// First node of open path, make next point the M // First node of open path, make next point the M
var item = seg.item; var item = seg.item;
var pt = [next.item.x, next.item.y]; pt = [next.item.x, next.item.y];
svgedit.path.replacePathSeg(2, seg.next.index, pt); svgedit.path.replacePathSeg(2, seg.next.index, pt);
list.removeItem(index); list.removeItem(index);
} else { } else {
@ -707,7 +720,7 @@ svgedit.path.Path.prototype.subpathIsClosed = function(index) {
var closed = false; var closed = false;
// Check if subpath is already open // Check if subpath is already open
svgedit.path.path.eachSeg(function(i) { svgedit.path.path.eachSeg(function(i) {
if (i <= index) return true; if (i <= index) {return true;}
if (this.type === 2) { if (this.type === 2) {
// Found M first, so open // Found M first, so open
return false; return false;
@ -782,7 +795,7 @@ svgedit.path.Path.prototype.setSegType = function(new_type) {
// Selected seg // Selected seg
var cur = this.segs[sel_pt]; var cur = this.segs[sel_pt];
var prev = cur.prev; var prev = cur.prev;
if (!prev) continue; if (!prev) {continue;}
if (!new_type) { // double-click, so just toggle if (!new_type) { // double-click, so just toggle
text = 'Toggle Path Segment Type'; text = 'Toggle Path Segment Type';
@ -877,12 +890,14 @@ svgedit.path.Path.prototype.update = function() {
svgedit.path.getPath_ = function(elem) { svgedit.path.getPath_ = function(elem) {
var p = pathData[elem.id]; var p = pathData[elem.id];
if (!p) p = pathData[elem.id] = new svgedit.path.Path(elem); if (!p) {
p = pathData[elem.id] = new svgedit.path.Path(elem);
}
return p; return p;
}; };
svgedit.path.removePath_ = function(id) { svgedit.path.removePath_ = function(id) {
if (id in pathData) delete pathData[id]; if (id in pathData) {delete pathData[id];}
}; };
var getRotVals = function(x, y) { var getRotVals = function(x, y) {
@ -919,7 +934,7 @@ var getRotVals = function(x, y) {
svgedit.path.recalcRotatedPath = function() { svgedit.path.recalcRotatedPath = function() {
var current_path = svgedit.path.path.elem; var current_path = svgedit.path.path.elem;
var angle = svgedit.utilities.getRotationAngle(current_path, true); var angle = svgedit.utilities.getRotationAngle(current_path, true);
if (!angle) return; if (!angle) {return;}
// selectedBBoxes[0] = svgedit.path.path.oldbbox; // selectedBBoxes[0] = svgedit.path.path.oldbbox;
var box = svgedit.utilities.getBBox(current_path), var box = svgedit.utilities.getBBox(current_path),
oldbox = svgedit.path.path.oldbbox,//selectedBBoxes[0], oldbox = svgedit.path.path.oldbbox,//selectedBBoxes[0],
@ -943,7 +958,7 @@ svgedit.path.recalcRotatedPath = function() {
i -= 1; i -= 1;
var seg = list.getItem(i), var seg = list.getItem(i),
type = seg.pathSegType; type = seg.pathSegType;
if (type == 1) continue; if (type == 1) {continue;}
var rvals = getRotVals(seg.x, seg.y), var rvals = getRotVals(seg.x, seg.y),
points = [rvals.x, rvals.y]; points = [rvals.x, rvals.y];
@ -973,4 +988,4 @@ svgedit.path.clearData = function() {
pathData = {}; pathData = {};
}; };
})(); }());

View File

@ -1,3 +1,5 @@
/*globals $*/
/*jslint vars: true, eqeq: true, continue: true*/
/** /**
* Recalculate. * Recalculate.
* *
@ -63,7 +65,7 @@ svgedit.recalculate.updateClipPath = function(attr, tx, ty) {
// Returns: // Returns:
// Undo command object with the resulting change // Undo command object with the resulting change
svgedit.recalculate.recalculateDimensions = function(selected) { svgedit.recalculate.recalculateDimensions = function(selected) {
if (selected == null) return null; if (selected == null) {return null;}
// Firefox Issue - 1081 // Firefox Issue - 1081
if (selected.nodeName == "svg" && navigator.userAgent.indexOf("Firefox/20") >= 0) { if (selected.nodeName == "svg" && navigator.userAgent.indexOf("Firefox/20") >= 0) {
@ -72,10 +74,10 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
var svgroot = context_.getSVGRoot(); var svgroot = context_.getSVGRoot();
var tlist = svgedit.transformlist.getTransformList(selected); var tlist = svgedit.transformlist.getTransformList(selected);
var k;
// remove any unnecessary transforms // remove any unnecessary transforms
if (tlist && tlist.numberOfItems > 0) { if (tlist && tlist.numberOfItems > 0) {
var k = tlist.numberOfItems; k = tlist.numberOfItems;
while (k--) { while (k--) {
var xform = tlist.getItem(k); var xform = tlist.getItem(k);
if (xform.type === 0) { if (xform.type === 0) {
@ -96,7 +98,7 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
} }
// End here if all it has is a rotation // End here if all it has is a rotation
if (tlist.numberOfItems === 1 && if (tlist.numberOfItems === 1 &&
svgedit.utilities.getRotationAngle(selected)) return null; svgedit.utilities.getRotationAngle(selected)) {return null;}
} }
// if this element had no transforms, we are done // if this element had no transforms, we are done
@ -109,7 +111,7 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
// TODO: Make this work for more than 2 // TODO: Make this work for more than 2
if (tlist) { if (tlist) {
var k = tlist.numberOfItems; k = tlist.numberOfItems;
var mxs = []; var mxs = [];
while (k--) { while (k--) {
var xform = tlist.getItem(k); var xform = tlist.getItem(k);
@ -187,19 +189,20 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
case 'polygon': case 'polygon':
case 'polyline': case 'polyline':
initial = {}; initial = {};
initial['points'] = selected.getAttribute('points'); initial.points = selected.getAttribute('points');
var list = selected.points; var list = selected.points;
var len = list.numberOfItems; var len = list.numberOfItems;
changes['points'] = new Array(len); changes.points = new Array(len);
for (var i = 0; i < len; ++i) { var i;
for (i = 0; i < len; ++i) {
var pt = list.getItem(i); var pt = list.getItem(i);
changes['points'][i] = {x:pt.x, y:pt.y}; changes.points[i] = {x:pt.x, y:pt.y};
} }
break; break;
case 'path': case 'path':
initial = {}; initial = {};
initial['d'] = selected.getAttribute('d'); initial.d = selected.getAttribute('d');
changes['d'] = selected.getAttribute('d'); changes.d = selected.getAttribute('d');
break; break;
} // switch on element type to get initial values } // switch on element type to get initial values
@ -246,7 +249,8 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
// FIXME: This blows up if the angle is exactly 0! // FIXME: This blows up if the angle is exactly 0!
var s = 2/a; var s = 2/a;
} }
for (var i = 0; i < tlist.numberOfItems; ++i) { var i;
for (i = 0; i < tlist.numberOfItems; ++i) {
var xform = tlist.getItem(i); var xform = tlist.getItem(i);
if (xform.type == 4) { if (xform.type == 4) {
// extract old center through mystical arts // extract old center through mystical arts
@ -288,7 +292,7 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
var childTlist = svgedit.transformlist.getTransformList(child); var childTlist = svgedit.transformlist.getTransformList(child);
// some children might not have a transform (<metadata>, <defs>, etc) // some children might not have a transform (<metadata>, <defs>, etc)
if (!childTlist) continue; if (!childTlist) {continue;}
var m = svgedit.math.transformListToTransform(childTlist).matrix; var m = svgedit.math.transformListToTransform(childTlist).matrix;
@ -473,7 +477,7 @@ svgedit.recalculate.recalculateDimensions = function(selected) {
context_.setStartTransform(child.getAttribute('transform')); context_.setStartTransform(child.getAttribute('transform'));
var childTlist = svgedit.transformlist.getTransformList(child); var childTlist = svgedit.transformlist.getTransformList(child);
if (!childTlist) continue; if (!childTlist) {continue;}
var em = svgedit.math.matrixMultiply(m, svgedit.math.transformListToTransform(childTlist).matrix); var em = svgedit.math.matrixMultiply(m, svgedit.math.transformListToTransform(childTlist).matrix);
var e2m = svgroot.createSVGTransform(); var e2m = svgroot.createSVGTransform();

View File

@ -1,3 +1,5 @@
/*globals $, svgedit*/
/*jslint vars: true, eqeq: true*/
/** /**
* Package: svgedit.sanitize * Package: svgedit.sanitize
* *
@ -12,7 +14,7 @@
// 2) browser.js // 2) browser.js
// 3) svgutils.js // 3) svgutils.js
(function() { (function() {'use strict';
if (!svgedit.sanitize) { if (!svgedit.sanitize) {
svgedit.sanitize = {}; svgedit.sanitize = {};
@ -138,12 +140,12 @@ svgedit.sanitize.sanitizeSvg = function(node) {
var allowedAttrs = svgWhiteList_[node.nodeName]; var allowedAttrs = svgWhiteList_[node.nodeName];
var allowedAttrsNS = svgWhiteListNS_[node.nodeName]; var allowedAttrsNS = svgWhiteListNS_[node.nodeName];
var i;
// if this element is supported, sanitize it // if this element is supported, sanitize it
if (typeof allowedAttrs !== 'undefined') { if (typeof allowedAttrs !== 'undefined') {
var seAttrs = []; var seAttrs = [];
var i = node.attributes.length; i = node.attributes.length;
while (i--) { while (i--) {
// if the attribute is not in our whitelist, then remove it // if the attribute is not in our whitelist, then remove it
// could use jQuery's inArray(), but I don't know if that's any better // could use jQuery's inArray(), but I don't know if that's any better
@ -173,6 +175,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
case 'patternTransform': case 'patternTransform':
var val = attr.nodeValue.replace(/(\d)-/g, '$1 -'); var val = attr.nodeValue.replace(/(\d)-/g, '$1 -');
node.setAttribute(attrName, val); node.setAttribute(attrName, val);
break;
} }
} }
@ -202,8 +205,7 @@ svgedit.sanitize.sanitizeSvg = function(node) {
var href = svgedit.utilities.getHref(node); var href = svgedit.utilities.getHref(node);
if (href && if (href &&
['filter', 'linearGradient', 'pattern', ['filter', 'linearGradient', 'pattern',
'radialGradient', 'textPath', 'use'].indexOf(node.nodeName) >= 0) 'radialGradient', 'textPath', 'use'].indexOf(node.nodeName) >= 0) {
{
// TODO: we simply check if the first character is a #, is this bullet-proof? // TODO: we simply check if the first character is a #, is this bullet-proof?
if (href[0] != '#') { if (href[0] != '#') {
// remove the attribute (but keep the element) // remove the attribute (but keep the element)
@ -248,9 +250,9 @@ svgedit.sanitize.sanitizeSvg = function(node) {
parent.removeChild(node); parent.removeChild(node);
// call sanitizeSvg on each of those children // call sanitizeSvg on each of those children
var i = children.length; i = children.length;
while (i--) { svgedit.sanitize.sanitizeSvg(children[i]); } while (i--) { svgedit.sanitize.sanitizeSvg(children[i]); }
} }
}; };
})(); }());

View File

@ -1,3 +1,5 @@
/*globals $, svgedit*/
/*jslint vars: true, eqeq: true, forin: true*/
/** /**
* Package: svedit.select * Package: svedit.select
* *
@ -13,7 +15,7 @@
// 3) math.js // 3) math.js
// 4) svgutils.js // 4) svgutils.js
(function() { (function() {'use strict';
if (!svgedit.select) { if (!svgedit.select) {
svgedit.select = {}; svgedit.select = {};
@ -96,10 +98,11 @@ svgedit.select.Selector.prototype.reset = function(e) {
// Parameters: // Parameters:
// angle - Float indicating current rotation angle in degrees // angle - Float indicating current rotation angle in degrees
svgedit.select.Selector.prototype.updateGripCursors = function(angle) { svgedit.select.Selector.prototype.updateGripCursors = function(angle) {
var dir_arr = []; var dir,
var steps = Math.round(angle / 45); dir_arr = [],
if (steps < 0) steps += 8; steps = Math.round(angle / 45);
for (var dir in selectorManager_.selectorGrips) { if (steps < 0) {steps += 8;}
for (dir in selectorManager_.selectorGrips) {
dir_arr.push(dir); dir_arr.push(dir);
} }
while (steps > 0) { while (steps > 0) {
@ -107,7 +110,7 @@ svgedit.select.Selector.prototype.updateGripCursors = function(angle) {
steps--; steps--;
} }
var i = 0; var i = 0;
for (var dir in selectorManager_.selectorGrips) { for (dir in selectorManager_.selectorGrips) {
selectorManager_.selectorGrips[dir].setAttribute('style', ('cursor:' + dir_arr[i] + '-resize')); selectorManager_.selectorGrips[dir].setAttribute('style', ('cursor:' + dir_arr[i] + '-resize'));
i++; i++;
} }
@ -169,7 +172,7 @@ svgedit.select.Selector.prototype.resize = function() {
} }
// apply the transforms // apply the transforms
var l = bbox.x, t = bbox.y, w = bbox.width, h = bbox.height, var l = bbox.x, t = bbox.y, w = bbox.width, h = bbox.height;
bbox = {x:l, y:t, width:w, height:h}; bbox = {x:l, y:t, width:w, height:h};
// we need to handle temporary transforms too // we need to handle temporary transforms too
@ -206,12 +209,12 @@ svgedit.select.Selector.prototype.resize = function() {
maxx = tl.x, maxx = tl.x,
maxy = tl.y; maxy = tl.y;
var Min = Math.min, Max = Math.max; var min = Math.min, max = Math.max;
minx = Min(minx, Min(nbox.tr.x, Min(nbox.bl.x, nbox.br.x) ) ) - offset; minx = min(minx, min(nbox.tr.x, min(nbox.bl.x, nbox.br.x) ) ) - offset;
miny = Min(miny, Min(nbox.tr.y, Min(nbox.bl.y, nbox.br.y) ) ) - offset; miny = min(miny, min(nbox.tr.y, min(nbox.bl.y, nbox.br.y) ) ) - offset;
maxx = Max(maxx, Max(nbox.tr.x, Max(nbox.bl.x, nbox.br.x) ) ) + offset; maxx = max(maxx, max(nbox.tr.x, max(nbox.bl.x, nbox.br.x) ) ) + offset;
maxy = Max(maxy, Max(nbox.tr.y, Max(nbox.bl.y, nbox.br.y) ) ) + offset; maxy = max(maxy, max(nbox.tr.y, max(nbox.bl.y, nbox.br.y) ) ) + offset;
nbax = minx; nbax = minx;
nbay = miny; nbay = miny;
@ -241,8 +244,8 @@ svgedit.select.Selector.prototype.resize = function() {
'e': [nbax + nbaw, nbay + (nbah)/2], 'e': [nbax + nbaw, nbay + (nbah)/2],
's': [nbax + (nbaw)/2, nbay + nbah] 's': [nbax + (nbaw)/2, nbay + nbah]
}; };
var dir;
for (var dir in this.gripCoords) { for (dir in this.gripCoords) {
var coords = this.gripCoords[dir]; var coords = this.gripCoords[dir];
selectedGrips[dir].setAttribute('cx', coords[0]); selectedGrips[dir].setAttribute('cx', coords[0]);
selectedGrips[dir].setAttribute('cy', coords[1]); selectedGrips[dir].setAttribute('cy', coords[1]);
@ -320,7 +323,8 @@ svgedit.select.SelectorManager.prototype.initGroup = function() {
this.rubberBandBox = null; this.rubberBandBox = null;
// add the corner grips // add the corner grips
for (var dir in this.selectorGrips) { var dir;
for (dir in this.selectorGrips) {
var grip = svgFactory_.createSVGElement({ var grip = svgFactory_.createSVGElement({
'element': 'circle', 'element': 'circle',
'attr': { 'attr': {
@ -369,7 +373,7 @@ svgedit.select.SelectorManager.prototype.initGroup = function() {
); );
$.data(this.rotateGrip, 'type', 'rotate'); $.data(this.rotateGrip, 'type', 'rotate');
if ($('#canvasBackground').length) return; if ($('#canvasBackground').length) {return;}
var dims = config_.dimensions; var dims = config_.dimensions;
var canvasbg = svgFactory_.createSVGElement({ var canvasbg = svgFactory_.createSVGElement({
@ -412,14 +416,15 @@ svgedit.select.SelectorManager.prototype.initGroup = function() {
// Parameters: // Parameters:
// elem - DOM element to get the selector for // elem - DOM element to get the selector for
svgedit.select.SelectorManager.prototype.requestSelector = function(elem) { svgedit.select.SelectorManager.prototype.requestSelector = function(elem) {
if (elem == null) return null; if (elem == null) {return null;}
var N = this.selectors.length; var i,
N = this.selectors.length;
// If we've already acquired one for this element, return it. // If we've already acquired one for this element, return it.
if (typeof(this.selectorMap[elem.id]) == 'object') { if (typeof(this.selectorMap[elem.id]) == 'object') {
this.selectorMap[elem.id].locked = true; this.selectorMap[elem.id].locked = true;
return this.selectorMap[elem.id]; return this.selectorMap[elem.id];
} }
for (var i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
if (this.selectors[i] && !this.selectors[i].locked) { if (this.selectors[i] && !this.selectors[i].locked) {
this.selectors[i].locked = true; this.selectors[i].locked = true;
this.selectors[i].reset(elem); this.selectors[i].reset(elem);
@ -440,10 +445,11 @@ svgedit.select.SelectorManager.prototype.requestSelector = function(elem) {
// Parameters: // Parameters:
// elem - DOM element to remove the selector for // elem - DOM element to remove the selector for
svgedit.select.SelectorManager.prototype.releaseSelector = function(elem) { svgedit.select.SelectorManager.prototype.releaseSelector = function(elem) {
if (elem == null) return; if (elem == null) {return;}
var N = this.selectors.length, var i,
N = this.selectors.length,
sel = this.selectorMap[elem.id]; sel = this.selectorMap[elem.id];
for (var i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
if (this.selectors[i] && this.selectors[i] == sel) { if (this.selectors[i] && this.selectors[i] == sel) {
if (sel.locked == false) { if (sel.locked == false) {
// TODO(codedread): Ensure this exists in this module. // TODO(codedread): Ensure this exists in this module.
@ -525,4 +531,4 @@ svgedit.select.getSelectorManager = function() {
return selectorManager_; return selectorManager_;
}; };
})(); }());

View File

@ -1,7 +1,8 @@
/*globals $, svgedit*/
/** /**
* *
* Licensed under the MIT License * Licensed under the MIT License
* main object, loaded first so other modules have the garanty of its existence * main object, loaded first so other modules have the guarantee of its existence
*/ */
svgedit = { svgedit = {
@ -18,7 +19,7 @@ svgedit = {
}; };
// return the svgedit.NS with key values switched and lowercase // return the svgedit.NS with key values switched and lowercase
svgedit.getReverseNS = function() { svgedit.getReverseNS = function() {'use strict';
var reverseNS = {}; var reverseNS = {};
$.each(this.NS, function(name, URI) { $.each(this.NS, function(name, URI) {
reverseNS[URI] = name.toLowerCase(); reverseNS[URI] = name.toLowerCase();