JSLint
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2644 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
d12694f9fa
commit
75bd787023
186
editor/coords.js
186
editor/coords.js
|
@ -1,3 +1,5 @@
|
|||
/*globals $, svgroot */
|
||||
/*jslint vars: true, eqeq: true, forin: true*/
|
||||
/**
|
||||
* Coords.
|
||||
*
|
||||
|
@ -15,7 +17,7 @@
|
|||
|
||||
var svgedit = svgedit || {};
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.coords) {
|
||||
svgedit.coords = {};
|
||||
|
@ -39,18 +41,24 @@ svgedit.coords.init = function(editorContext) {
|
|||
// changes - Object with changes to be remapped
|
||||
// m - Matrix object to use for remapping coordinates
|
||||
svgedit.coords.remapElement = function(selected, changes, m) {
|
||||
var remap = function(x, y) { return svgedit.math.transformPoint(x, y, m); },
|
||||
var i, type,
|
||||
remap = function(x, y) { return svgedit.math.transformPoint(x, y, m); },
|
||||
scalew = function(w) { return m.a * w; },
|
||||
scaleh = function(h) { return m.d * h; },
|
||||
doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg',
|
||||
finishUp = function() {
|
||||
if (doSnapping) for (var o in changes) changes[o] = svgedit.utilities.snapToGrid(changes[o]);
|
||||
var o;
|
||||
if (doSnapping) {
|
||||
for (o in changes) {
|
||||
changes[o] = svgedit.utilities.snapToGrid(changes[o]);
|
||||
}
|
||||
}
|
||||
svgedit.utilities.assignAttributes(selected, changes, 1000, true);
|
||||
},
|
||||
box = svgedit.utilities.getBBox(selected);
|
||||
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var type = i === 0 ? 'fill' : 'stroke';
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
type = i === 0 ? 'fill' : 'stroke';
|
||||
var attrVal = selected.getAttribute(type);
|
||||
if (attrVal && attrVal.indexOf('url(') === 0) {
|
||||
if (m.a < 0 || m.d < 0) {
|
||||
|
@ -84,6 +92,7 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
}
|
||||
|
||||
var elName = selected.tagName;
|
||||
var chlist, mt;
|
||||
if (elName === 'g' || elName === 'text' || elName == 'tspan' || elName === 'use') {
|
||||
// if it was a translate, then just update x,y
|
||||
if (m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && (m.e != 0 || m.f != 0) ) {
|
||||
|
@ -95,14 +104,14 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
changes.y = parseFloat(changes.y) + t_new.f;
|
||||
} else {
|
||||
// we just absorb all matrices into the element and don't do any remapping
|
||||
var chlist = svgedit.transformlist.getTransformList(selected);
|
||||
var mt = svgroot.createSVGTransform();
|
||||
chlist = svgedit.transformlist.getTransformList(selected);
|
||||
mt = svgroot.createSVGTransform();
|
||||
mt.setMatrix(svgedit.math.matrixMultiply(svgedit.math.transformListToTransform(chlist).matrix, m));
|
||||
chlist.clear();
|
||||
chlist.appendItem(mt);
|
||||
}
|
||||
}
|
||||
|
||||
var c, pt, pt1, pt2, len;
|
||||
// now we have a set of changes and an applied reduced transform list
|
||||
// we apply the changes directly to the DOM
|
||||
switch (elName) {
|
||||
|
@ -112,13 +121,13 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
// Allow images to be inverted (give them matrix when flipped)
|
||||
if (elName === 'image' && (m.a < 0 || m.d < 0)) {
|
||||
// Convert to matrix
|
||||
var chlist = svgedit.transformlist.getTransformList(selected);
|
||||
var mt = svgroot.createSVGTransform();
|
||||
chlist = svgedit.transformlist.getTransformList(selected);
|
||||
mt = svgroot.createSVGTransform();
|
||||
mt.setMatrix(svgedit.math.matrixMultiply(svgedit.math.transformListToTransform(chlist).matrix, m));
|
||||
chlist.clear();
|
||||
chlist.appendItem(mt);
|
||||
} else {
|
||||
var pt1 = remap(changes.x, changes.y);
|
||||
pt1 = remap(changes.x, changes.y);
|
||||
changes.width = scalew(changes.width);
|
||||
changes.height = scaleh(changes.height);
|
||||
changes.x = pt1.x + Math.min(0, changes.width);
|
||||
|
@ -129,7 +138,7 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
finishUp();
|
||||
break;
|
||||
case 'ellipse':
|
||||
var c = remap(changes.cx, changes.cy);
|
||||
c = remap(changes.cx, changes.cy);
|
||||
changes.cx = c.x;
|
||||
changes.cy = c.y;
|
||||
changes.rx = scalew(changes.rx);
|
||||
|
@ -139,7 +148,7 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
finishUp();
|
||||
break;
|
||||
case 'circle':
|
||||
var c = remap(changes.cx,changes.cy);
|
||||
c = remap(changes.cx,changes.cy);
|
||||
changes.cx = c.x;
|
||||
changes.cy = c.y;
|
||||
// take the minimum of the new selected box's dimensions for the new circle radius
|
||||
|
@ -147,11 +156,12 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
var w = tbox.tr.x - tbox.tl.x, h = tbox.bl.y - tbox.tl.y;
|
||||
changes.r = Math.min(w/2, h/2);
|
||||
|
||||
if (changes.r) changes.r = Math.abs(changes.r);
|
||||
if (changes.r) {changes.r = Math.abs(changes.r);}
|
||||
finishUp();
|
||||
break;
|
||||
case 'line':
|
||||
var pt1 = remap(changes.x1, changes.y1), pt2 = remap(changes.x2, changes.y2);
|
||||
pt1 = remap(changes.x1, changes.y1);
|
||||
pt2 = remap(changes.x2, changes.y2);
|
||||
changes.x1 = pt1.x;
|
||||
changes.y1 = pt1.y;
|
||||
changes.x2 = pt2.x;
|
||||
|
@ -170,87 +180,87 @@ svgedit.coords.remapElement = function(selected, changes, m) {
|
|||
break;
|
||||
case 'polyline':
|
||||
case 'polygon':
|
||||
var len = changes.points.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var pt = changes.points[i];
|
||||
pt = remap(pt.x, pt.y);
|
||||
changes.points[i].x = pt.x;
|
||||
changes.points[i].y = pt.y;
|
||||
len = changes.points.length;
|
||||
for (i = 0; i < len; ++i) {
|
||||
pt = changes.points[i];
|
||||
pt = remap(pt.x, pt.y);
|
||||
changes.points[i].x = pt.x;
|
||||
changes.points[i].y = pt.y;
|
||||
}
|
||||
|
||||
var len = changes.points.length;
|
||||
len = changes.points.length;
|
||||
var pstr = '';
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var pt = changes.points[i];
|
||||
pstr += pt.x + ',' + pt.y + ' ';
|
||||
for (i = 0; i < len; ++i) {
|
||||
pt = changes.points[i];
|
||||
pstr += pt.x + ',' + pt.y + ' ';
|
||||
}
|
||||
selected.setAttribute('points', pstr);
|
||||
break;
|
||||
case 'path':
|
||||
case 'path':
|
||||
var seg;
|
||||
var segList = selected.pathSegList;
|
||||
len = segList.numberOfItems;
|
||||
changes.d = new Array(len);
|
||||
for (i = 0; i < len; ++i) {
|
||||
seg = segList.getItem(i);
|
||||
changes.d[i] = {
|
||||
type: seg.pathSegType,
|
||||
x: seg.x,
|
||||
y: seg.y,
|
||||
x1: seg.x1,
|
||||
y1: seg.y1,
|
||||
x2: seg.x2,
|
||||
y2: seg.y2,
|
||||
r1: seg.r1,
|
||||
r2: seg.r2,
|
||||
angle: seg.angle,
|
||||
largeArcFlag: seg.largeArcFlag,
|
||||
sweepFlag: seg.sweepFlag
|
||||
};
|
||||
}
|
||||
|
||||
var segList = selected.pathSegList;
|
||||
var len = segList.numberOfItems;
|
||||
changes.d = new Array(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var seg = segList.getItem(i);
|
||||
changes.d[i] = {
|
||||
type: seg.pathSegType,
|
||||
x: seg.x,
|
||||
y: seg.y,
|
||||
x1: seg.x1,
|
||||
y1: seg.y1,
|
||||
x2: seg.x2,
|
||||
y2: seg.y2,
|
||||
r1: seg.r1,
|
||||
r2: seg.r2,
|
||||
angle: seg.angle,
|
||||
largeArcFlag: seg.largeArcFlag,
|
||||
sweepFlag: seg.sweepFlag
|
||||
};
|
||||
}
|
||||
|
||||
var len = changes.d.length,
|
||||
firstseg = changes.d[0],
|
||||
currentpt = remap(firstseg.x, firstseg.y);
|
||||
changes.d[0].x = currentpt.x;
|
||||
changes.d[0].y = currentpt.y;
|
||||
for (var i = 1; i < len; ++i) {
|
||||
var seg = changes.d[i];
|
||||
var type = seg.type;
|
||||
len = changes.d.length;
|
||||
var firstseg = changes.d[0],
|
||||
currentpt = remap(firstseg.x, firstseg.y);
|
||||
changes.d[0].x = currentpt.x;
|
||||
changes.d[0].y = currentpt.y;
|
||||
for (i = 1; i < len; ++i) {
|
||||
seg = changes.d[i];
|
||||
type = seg.type;
|
||||
// if absolute or first segment, we want to remap x, y, x1, y1, x2, y2
|
||||
// if relative, we want to scalew, scaleh
|
||||
if (type % 2 == 0) { // absolute
|
||||
var thisx = (seg.x != undefined) ? seg.x : currentpt.x, // for V commands
|
||||
thisy = (seg.y != undefined) ? seg.y : currentpt.y, // for H commands
|
||||
pt = remap(thisx,thisy),
|
||||
pt1 = remap(seg.x1, seg.y1),
|
||||
pt2 = remap(seg.x2, seg.y2);
|
||||
seg.x = pt.x;
|
||||
seg.y = pt.y;
|
||||
seg.x1 = pt1.x;
|
||||
seg.y1 = pt1.y;
|
||||
seg.x2 = pt2.x;
|
||||
seg.y2 = pt2.y;
|
||||
seg.r1 = scalew(seg.r1),
|
||||
seg.r2 = scaleh(seg.r2);
|
||||
var thisx = (seg.x != undefined) ? seg.x : currentpt.x, // for V commands
|
||||
thisy = (seg.y != undefined) ? seg.y : currentpt.y; // for H commands
|
||||
pt = remap(thisx,thisy);
|
||||
pt1 = remap(seg.x1, seg.y1);
|
||||
pt2 = remap(seg.x2, seg.y2);
|
||||
seg.x = pt.x;
|
||||
seg.y = pt.y;
|
||||
seg.x1 = pt1.x;
|
||||
seg.y1 = pt1.y;
|
||||
seg.x2 = pt2.x;
|
||||
seg.y2 = pt2.y;
|
||||
seg.r1 = scalew(seg.r1);
|
||||
seg.r2 = scaleh(seg.r2);
|
||||
}
|
||||
else { // relative
|
||||
seg.x = scalew(seg.x);
|
||||
seg.y = scaleh(seg.y);
|
||||
seg.x1 = scalew(seg.x1);
|
||||
seg.y1 = scaleh(seg.y1);
|
||||
seg.x2 = scalew(seg.x2);
|
||||
seg.y2 = scaleh(seg.y2);
|
||||
seg.r1 = scalew(seg.r1),
|
||||
seg.r2 = scaleh(seg.r2);
|
||||
seg.x = scalew(seg.x);
|
||||
seg.y = scaleh(seg.y);
|
||||
seg.x1 = scalew(seg.x1);
|
||||
seg.y1 = scaleh(seg.y1);
|
||||
seg.x2 = scalew(seg.x2);
|
||||
seg.y2 = scaleh(seg.y2);
|
||||
seg.r1 = scalew(seg.r1);
|
||||
seg.r2 = scaleh(seg.r2);
|
||||
}
|
||||
} // for each segment
|
||||
} // for each segment
|
||||
|
||||
var dstr = '';
|
||||
var len = changes.d.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var seg = changes.d[i];
|
||||
var type = seg.type;
|
||||
var dstr = '';
|
||||
len = changes.d.length;
|
||||
for (i = 0; i < len; ++i) {
|
||||
seg = changes.d[i];
|
||||
type = seg.type;
|
||||
dstr += pathMap[type];
|
||||
switch (type) {
|
||||
case 13: // relative horizontal line (h)
|
||||
|
@ -287,12 +297,12 @@ case 'path':
|
|||
case 16: // absolute smooth cubic (S)
|
||||
dstr += seg.x2 + ',' + seg.y2 + ' ' + seg.x + ',' + seg.y + ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selected.setAttribute('d', dstr);
|
||||
break;
|
||||
selected.setAttribute('d', dstr);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
|
@ -1,3 +1,5 @@
|
|||
/*globals $, svgedit*/
|
||||
/*jslint vars: true, eqeq: true*/
|
||||
/**
|
||||
* Package: svgedit.draw
|
||||
*
|
||||
|
@ -11,7 +13,7 @@
|
|||
// 2) browser.js
|
||||
// 3) svgutils.js
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.draw) {
|
||||
svgedit.draw = {};
|
||||
|
@ -169,7 +171,7 @@ svgedit.draw.Drawing.prototype.clearNonce = function() {
|
|||
svgedit.draw.Drawing.prototype.getId = function() {
|
||||
return this.nonce_ ?
|
||||
this.idPrefix + this.nonce_ + '_' + this.obj_num :
|
||||
this.idPrefix + this.obj_num;
|
||||
this.idPrefix + this.obj_num;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -225,7 +227,7 @@ svgedit.draw.Drawing.prototype.releaseId = function(id) {
|
|||
return false;
|
||||
}
|
||||
// extract the obj_num of this id
|
||||
var num = parseInt(id.substr(front.length));
|
||||
var num = parseInt(id.substr(front.length), 10);
|
||||
|
||||
// if we didn't get a positive number or we already released this number
|
||||
// then return false.
|
||||
|
@ -251,8 +253,9 @@ svgedit.draw.Drawing.prototype.getNumLayers = function() {
|
|||
// Function: svgedit.draw.Drawing.hasLayer
|
||||
// Check if layer with given name already exists
|
||||
svgedit.draw.Drawing.prototype.hasLayer = function(name) {
|
||||
for(var i = 0; i < this.getNumLayers(); i++) {
|
||||
if(this.all_layers[i][0] == name) return true;
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); i++) {
|
||||
if(this.all_layers[i][0] == name) {return true;}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
@ -287,7 +290,8 @@ svgedit.draw.Drawing.prototype.getCurrentLayer = function() {
|
|||
// Returns:
|
||||
// The name of the currently active layer.
|
||||
svgedit.draw.Drawing.prototype.getCurrentLayerName = function() {
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (this.all_layers[i][1] == this.current_layer) {
|
||||
return this.getLayerName(i);
|
||||
}
|
||||
|
@ -305,7 +309,8 @@ svgedit.draw.Drawing.prototype.getCurrentLayerName = function() {
|
|||
// Returns:
|
||||
// true if the current layer was switched, otherwise false
|
||||
svgedit.draw.Drawing.prototype.setCurrentLayer = function(name) {
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (name == this.getLayerName(i)) {
|
||||
if (this.current_layer != this.all_layers[i][1]) {
|
||||
this.current_layer.setAttribute("style", "pointer-events:none");
|
||||
|
@ -346,7 +351,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
|
|||
var orphans = [], layernames = [];
|
||||
var a_layer = null;
|
||||
var childgroups = false;
|
||||
for (var i = 0; i < numchildren; ++i) {
|
||||
var i;
|
||||
for (i = 0; i < numchildren; ++i) {
|
||||
var child = this.svgElem_.childNodes.item(i);
|
||||
// for each g, find its layer name
|
||||
if (child && child.nodeType == 1) {
|
||||
|
@ -383,7 +389,7 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
|
|||
// create a new layer and add all the orphans to it
|
||||
var svgdoc = this.svgElem_.ownerDocument;
|
||||
if (orphans.length > 0 || !childgroups) {
|
||||
var i = 1;
|
||||
i = 1;
|
||||
// TODO(codedread): What about internationalization of "Layer"?
|
||||
while (layernames.indexOf(("Layer " + i)) >= 0) { i++; }
|
||||
var newname = "Layer " + i;
|
||||
|
@ -391,7 +397,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
|
|||
var layer_title = svgdoc.createElementNS(NS.SVG, "title");
|
||||
layer_title.textContent = newname;
|
||||
a_layer.appendChild(layer_title);
|
||||
for (var j = 0; j < orphans.length; ++j) {
|
||||
var j;
|
||||
for (j = 0; j < orphans.length; ++j) {
|
||||
a_layer.appendChild(orphans[j]);
|
||||
}
|
||||
this.svgElem_.appendChild(a_layer);
|
||||
|
@ -435,13 +442,14 @@ svgedit.draw.Drawing.prototype.createLayer = function(name) {
|
|||
svgedit.draw.Drawing.prototype.getLayerVisibility = function(layername) {
|
||||
// find the layer
|
||||
var layer = null;
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (this.getLayerName(i) == layername) {
|
||||
layer = this.all_layers[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!layer) return false;
|
||||
if (!layer) {return false;}
|
||||
return (layer.getAttribute('display') != 'none');
|
||||
};
|
||||
|
||||
|
@ -461,16 +469,17 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible
|
|||
}
|
||||
// find the layer
|
||||
var layer = null;
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (this.getLayerName(i) == layername) {
|
||||
layer = this.all_layers[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!layer) return null;
|
||||
if (!layer) {return null;}
|
||||
|
||||
var oldDisplay = layer.getAttribute("display");
|
||||
if (!oldDisplay) oldDisplay = "inline";
|
||||
if (!oldDisplay) {oldDisplay = "inline";}
|
||||
layer.setAttribute("display", bVisible ? "inline" : "none");
|
||||
return layer;
|
||||
};
|
||||
|
@ -486,7 +495,8 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible
|
|||
// The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null
|
||||
// if layername is not a valid layer
|
||||
svgedit.draw.Drawing.prototype.getLayerOpacity = function(layername) {
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (this.getLayerName(i) == layername) {
|
||||
var g = this.all_layers[i][1];
|
||||
var opacity = g.getAttribute('opacity');
|
||||
|
@ -510,7 +520,8 @@ svgedit.draw.Drawing.prototype.setLayerOpacity = function(layername, opacity) {
|
|||
if (typeof opacity != typeof 1.0 || opacity < 0.0 || opacity > 1.0) {
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < this.getNumLayers(); ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.getNumLayers(); ++i) {
|
||||
if (this.getLayerName(i) == layername) {
|
||||
var g = this.all_layers[i][1];
|
||||
g.setAttribute("opacity", opacity);
|
||||
|
@ -519,4 +530,4 @@ svgedit.draw.Drawing.prototype.setLayerOpacity = function(layername, opacity) {
|
|||
}
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
||||
|
|
|
@ -98,12 +98,13 @@ function EmbeddedSVGEdit(frame){
|
|||
if (typeof e.data !== 'string') {
|
||||
return;
|
||||
}
|
||||
var data = e.data && JSON.parse(e.data);
|
||||
var result, cbid,
|
||||
data = e.data && JSON.parse(e.data);
|
||||
if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit') {
|
||||
return;
|
||||
}
|
||||
var result = data.result || data.error,
|
||||
cbid = data.id;
|
||||
result = data.result || data.error;
|
||||
cbid = data.id;
|
||||
if(t.callbacks[cbid]){
|
||||
if(data.result){
|
||||
t.callbacks[cbid](result);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/*globals svgedit*/
|
||||
/*jslint vars: true, eqeq: true, continue: true, forin: true*/
|
||||
/**
|
||||
* Package: svedit.history
|
||||
*
|
||||
|
@ -11,7 +13,7 @@
|
|||
// 2) svgtransformlist.js
|
||||
// 3) svgutils.js
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.history) {
|
||||
svgedit.history = {};
|
||||
|
@ -253,10 +255,11 @@ svgedit.history.ChangeElementCommand = function(elem, attrs, text) {
|
|||
this.text = text ? ("Change " + elem.tagName + " " + text) : ("Change " + elem.tagName);
|
||||
this.newValues = {};
|
||||
this.oldValues = attrs;
|
||||
for (var attr in attrs) {
|
||||
if (attr == "#text") this.newValues[attr] = elem.textContent;
|
||||
else if (attr == "#href") this.newValues[attr] = svgedit.utilities.getHref(elem);
|
||||
else this.newValues[attr] = elem.getAttribute(attr);
|
||||
var attr;
|
||||
for (attr in attrs) {
|
||||
if (attr == "#text") {this.newValues[attr] = elem.textContent;}
|
||||
else if (attr == "#href") {this.newValues[attr] = svgedit.utilities.getHref(elem);}
|
||||
else {this.newValues[attr] = elem.getAttribute(attr);}
|
||||
}
|
||||
};
|
||||
svgedit.history.ChangeElementCommand.type = function() { return 'svgedit.history.ChangeElementCommand'; };
|
||||
|
@ -275,11 +278,12 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
|||
}
|
||||
|
||||
var bChangedTransform = false;
|
||||
for (var attr in this.newValues ) {
|
||||
var attr;
|
||||
for (attr in this.newValues ) {
|
||||
if (this.newValues[attr]) {
|
||||
if (attr == "#text") this.elem.textContent = this.newValues[attr];
|
||||
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.newValues[attr]);
|
||||
else this.elem.setAttribute(attr, this.newValues[attr]);
|
||||
if (attr == "#text") {this.elem.textContent = this.newValues[attr];}
|
||||
else if (attr == "#href") {svgedit.utilities.setHref(this.elem, this.newValues[attr]);}
|
||||
else {this.elem.setAttribute(attr, this.newValues[attr]);}
|
||||
}
|
||||
else {
|
||||
if (attr == "#text") {
|
||||
|
@ -298,6 +302,8 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
|||
if (!bChangedTransform) {
|
||||
var angle = svgedit.utilities.getRotationAngle(this.elem);
|
||||
if (angle) {
|
||||
// TODO: These instances of elem either need to be declared as global
|
||||
// (which would not be good for conflicts) or declare/use this.elem
|
||||
var bbox = elem.getBBox();
|
||||
var cx = bbox.x + bbox.width/2,
|
||||
cy = bbox.y + bbox.height/2;
|
||||
|
@ -323,17 +329,20 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
|
|||
}
|
||||
|
||||
var bChangedTransform = false;
|
||||
for (var attr in this.oldValues ) {
|
||||
var attr;
|
||||
for (attr in this.oldValues ) {
|
||||
if (this.oldValues[attr]) {
|
||||
if (attr == "#text") this.elem.textContent = this.oldValues[attr];
|
||||
else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.oldValues[attr]);
|
||||
else this.elem.setAttribute(attr, this.oldValues[attr]);
|
||||
if (attr == "#text") {this.elem.textContent = this.oldValues[attr];}
|
||||
else if (attr == "#href") {svgedit.utilities.setHref(this.elem, this.oldValues[attr]);}
|
||||
else {
|
||||
this.elem.setAttribute(attr, this.oldValues[attr]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (attr == "#text") {
|
||||
this.elem.textContent = "";
|
||||
}
|
||||
else this.elem.removeAttribute(attr);
|
||||
else {this.elem.removeAttribute(attr);}
|
||||
}
|
||||
if (attr == "transform") { bChangedTransform = true; }
|
||||
}
|
||||
|
@ -398,8 +407,9 @@ svgedit.history.BatchCommand.prototype.apply = function(handler) {
|
|||
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this);
|
||||
}
|
||||
|
||||
var len = this.stack.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var i,
|
||||
len = this.stack.length;
|
||||
for (i = 0; i < len; ++i) {
|
||||
this.stack[i].apply(handler);
|
||||
}
|
||||
|
||||
|
@ -415,7 +425,8 @@ svgedit.history.BatchCommand.prototype.unapply = function(handler) {
|
|||
handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this);
|
||||
}
|
||||
|
||||
for (var i = this.stack.length-1; i >= 0; i--) {
|
||||
var i;
|
||||
for (i = this.stack.length-1; i >= 0; i--) {
|
||||
this.stack[i].unapply(handler);
|
||||
}
|
||||
|
||||
|
@ -433,7 +444,7 @@ svgedit.history.BatchCommand.prototype.elements = function() {
|
|||
var thisElems = this.stack[cmd].elements();
|
||||
var elem = thisElems.length;
|
||||
while (elem--) {
|
||||
if (elems.indexOf(thisElems[elem]) == -1) elems.push(thisElems[elem]);
|
||||
if (elems.indexOf(thisElems[elem]) == -1) {elems.push(thisElems[elem]);}
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
|
@ -560,7 +571,7 @@ svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, e
|
|||
var oldValues = new Array(i), elements = new Array(i);
|
||||
while (i--) {
|
||||
var elem = elems[i];
|
||||
if (elem == null) continue;
|
||||
if (elem == null) {continue;}
|
||||
elements[i] = elem;
|
||||
oldValues[i] = elem.getAttribute(attrName);
|
||||
}
|
||||
|
@ -586,7 +597,7 @@ svgedit.history.UndoManager.prototype.finishUndoableChange = function() {
|
|||
var batchCmd = new svgedit.history.BatchCommand("Change " + attrName);
|
||||
while (i--) {
|
||||
var elem = changeset.elements[i];
|
||||
if (elem == null) continue;
|
||||
if (elem == null) {continue;}
|
||||
var changes = {};
|
||||
changes[attrName] = changeset.oldValues[i];
|
||||
if (changes[attrName] != elem.getAttribute(attrName)) {
|
||||
|
@ -597,4 +608,4 @@ svgedit.history.UndoManager.prototype.finishUndoableChange = function() {
|
|||
return batchCmd;
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
|
@ -1,3 +1,5 @@
|
|||
/*globals $, jQuery */
|
||||
/*jslint vars: true */
|
||||
/**
|
||||
* jQuery module to work with SVG.
|
||||
*
|
||||
|
@ -8,7 +10,7 @@
|
|||
// Dependencies:
|
||||
// 1) jquery
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
// This fixes $(...).attr() to work as expected with SVG elements.
|
||||
// Does not currently use *AttributeNS() since we rarely need that.
|
||||
|
@ -24,9 +26,10 @@
|
|||
// TODO use NS.SVG instead
|
||||
svgns = "http://www.w3.org/2000/svg";
|
||||
jQuery.fn.attr = function(key, value) {
|
||||
var len = this.length;
|
||||
if (!len) return proxied.apply(this, arguments);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var i, attr;
|
||||
var len = this.length;
|
||||
if (!len) {return proxied.apply(this, arguments);}
|
||||
for (i = 0; i < len; ++i) {
|
||||
var elem = this[i];
|
||||
// set/get SVG attribute
|
||||
if (elem.namespaceURI === svgns) {
|
||||
|
@ -39,7 +42,7 @@
|
|||
|
||||
while (j--) {
|
||||
var aname = key[j];
|
||||
var attr = elem.getAttribute(aname);
|
||||
attr = elem.getAttribute(aname);
|
||||
// This returns a number when appropriate
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
|
@ -47,14 +50,16 @@
|
|||
obj[aname] = attr;
|
||||
}
|
||||
return obj;
|
||||
} else if (typeof key === "object") {
|
||||
}
|
||||
if (typeof key === "object") {
|
||||
// Setting attributes form object
|
||||
for (var v in key) {
|
||||
var v;
|
||||
for (v in key) {
|
||||
elem.setAttribute(v, key[v]);
|
||||
}
|
||||
// Getting attribute
|
||||
} else {
|
||||
var attr = elem.getAttribute(key);
|
||||
attr = elem.getAttribute(key);
|
||||
if (attr || attr === "0") {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/*globals svgedit*/
|
||||
/*jslint vars: true, eqeq: true */
|
||||
/**
|
||||
* Package: svedit.math
|
||||
*
|
||||
|
@ -10,7 +12,7 @@
|
|||
// Dependencies:
|
||||
// None.
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.math) {
|
||||
svgedit.math = {};
|
||||
|
@ -66,12 +68,12 @@ svgedit.math.matrixMultiply = function() {
|
|||
var m1 = args[i-1];
|
||||
m = m1.multiply(m);
|
||||
}
|
||||
if (Math.abs(m.a) < NEAR_ZERO) m.a = 0;
|
||||
if (Math.abs(m.b) < NEAR_ZERO) m.b = 0;
|
||||
if (Math.abs(m.c) < NEAR_ZERO) m.c = 0;
|
||||
if (Math.abs(m.d) < NEAR_ZERO) m.d = 0;
|
||||
if (Math.abs(m.e) < NEAR_ZERO) m.e = 0;
|
||||
if (Math.abs(m.f) < NEAR_ZERO) m.f = 0;
|
||||
if (Math.abs(m.a) < NEAR_ZERO) {m.a = 0;}
|
||||
if (Math.abs(m.b) < NEAR_ZERO) {m.b = 0;}
|
||||
if (Math.abs(m.c) < NEAR_ZERO) {m.c = 0;}
|
||||
if (Math.abs(m.d) < NEAR_ZERO) {m.d = 0;}
|
||||
if (Math.abs(m.e) < NEAR_ZERO) {m.e = 0;}
|
||||
if (Math.abs(m.f) < NEAR_ZERO) {m.f = 0;}
|
||||
|
||||
return m;
|
||||
};
|
||||
|
@ -85,11 +87,11 @@ svgedit.math.matrixMultiply = function() {
|
|||
// Returns:
|
||||
// Boolean on whether or not a matrix transform was found
|
||||
svgedit.math.hasMatrixTransform = function(tlist) {
|
||||
if (!tlist) return false;
|
||||
if (!tlist) {return false;}
|
||||
var num = tlist.numberOfItems;
|
||||
while (num--) {
|
||||
var xform = tlist.getItem(num);
|
||||
if (xform.type == 1 && !svgedit.math.isIdentity(xform.matrix)) return true;
|
||||
if (xform.type == 1 && !svgedit.math.isIdentity(xform.matrix)) {return true;}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
@ -166,7 +168,8 @@ svgedit.math.transformListToTransform = function(tlist, min, max) {
|
|||
max = parseInt(max, 10);
|
||||
if (min > max) { var temp = max; max = min; min = temp; }
|
||||
var m = svg.createSVGMatrix();
|
||||
for (var i = min; i <= max; ++i) {
|
||||
var i;
|
||||
for (i = min; i <= max; ++i) {
|
||||
// if our indices are out of range, just use a harmless identity matrix
|
||||
var mtom = (i >= 0 && i < tlist.numberOfItems ?
|
||||
tlist.getItem(i).matrix :
|
||||
|
@ -238,4 +241,4 @@ svgedit.math.rectsIntersect = function(r1, r2) {
|
|||
(r2.y+r2.height) > r1.y;
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
|
@ -942,10 +942,11 @@
|
|||
if (toolButtonClick(show_sel)) {
|
||||
options.fn();
|
||||
}
|
||||
var icon;
|
||||
if (options.icon) {
|
||||
var icon = $.getSvgIcon(options.icon, true);
|
||||
icon = $.getSvgIcon(options.icon, true);
|
||||
} else {
|
||||
var icon = $(options.sel).children().eq(0).clone();
|
||||
icon = $(options.sel).children().eq(0).clone();
|
||||
}
|
||||
|
||||
icon[0].setAttribute('width', shower.width());
|
||||
|
@ -1169,7 +1170,7 @@
|
|||
|
||||
// Add buttons given by extension
|
||||
$.each(ext.buttons, function(i, btn) {
|
||||
var icon;
|
||||
var icon, svgicon;
|
||||
var id = btn.id;
|
||||
var num = i;
|
||||
|
||||
|
@ -1182,7 +1183,7 @@
|
|||
icon = $('<img src="' + btn.icon + '">');
|
||||
} else {
|
||||
fallback_obj[id] = btn.icon;
|
||||
var svgicon = btn.svgicon || btn.id;
|
||||
svgicon = btn.svgicon || btn.id;
|
||||
if (btn.type == 'app_menu') {
|
||||
placement_obj['#' + id + ' > div'] = svgicon;
|
||||
} else {
|
||||
|
@ -1212,7 +1213,7 @@
|
|||
parent = '#main_menu ul';
|
||||
break;
|
||||
}
|
||||
|
||||
var flyout_holder, cur_h, show_btn;
|
||||
var button = $((btn.list || btn.type == 'app_menu') ? '<li/>' : '<div/>')
|
||||
.attr('id', id)
|
||||
.attr('title', btn.title)
|
||||
|
@ -1230,12 +1231,12 @@
|
|||
// // opts.button, default, position
|
||||
var ref_btn = $(button);
|
||||
|
||||
var flyout_holder = ref_btn.parent();
|
||||
flyout_holder = ref_btn.parent();
|
||||
// Create a flyout menu if there isn't one already
|
||||
if (!ref_btn.parent().hasClass('tools_flyout')) {
|
||||
// Create flyout placeholder
|
||||
var tls_id = ref_btn[0].id.replace('tool_', 'tools_');
|
||||
var show_btn = ref_btn.clone()
|
||||
show_btn = ref_btn.clone()
|
||||
.attr('id',tls_id + '_show')
|
||||
.append($('<div>', {'class': 'flyout_arrow_horiz'}));
|
||||
|
||||
|
@ -1252,7 +1253,7 @@
|
|||
// TODO: Find way to set the current icon using the iconloader if this is not default
|
||||
|
||||
// Include data for extension button as well as ref button
|
||||
var cur_h = holders['#'+flyout_holder[0].id] = [{
|
||||
cur_h = holders['#'+flyout_holder[0].id] = [{
|
||||
sel: '#'+id,
|
||||
fn: btn.events.click,
|
||||
icon: btn.id,
|
||||
|
@ -1282,7 +1283,7 @@
|
|||
$('#' + btn.list + '_opts').append(button);
|
||||
if (btn.isDefault) {
|
||||
$('#cur_' + btn.list).append(button.children().clone());
|
||||
var svgicon = btn.svgicon || btn.id;
|
||||
svgicon = btn.svgicon || btn.id;
|
||||
placement_obj['#cur_' + btn.list] = svgicon;
|
||||
}
|
||||
} else if (btn.includeWith) {
|
||||
|
@ -1291,12 +1292,12 @@
|
|||
// opts.button, default, position
|
||||
var ref_btn = $(opts.button);
|
||||
|
||||
var flyout_holder = ref_btn.parent();
|
||||
flyout_holder = ref_btn.parent();
|
||||
// Create a flyout menu if there isn't one already
|
||||
if (!ref_btn.parent().hasClass('tools_flyout')) {
|
||||
// Create flyout placeholder
|
||||
var tls_id = ref_btn[0].id.replace('tool_', 'tools_');
|
||||
var show_btn = ref_btn.clone()
|
||||
show_btn = ref_btn.clone()
|
||||
.attr('id',tls_id + '_show')
|
||||
.append($('<div>', {'class': 'flyout_arrow_horiz'}));
|
||||
|
||||
|
@ -1314,7 +1315,7 @@
|
|||
// TODO: Find way to set the current icon using the iconloader if this is not default
|
||||
|
||||
// Include data for extension button as well as ref button
|
||||
var cur_h = holders['#'+flyout_holder[0].id] = [{
|
||||
cur_h = holders['#'+flyout_holder[0].id] = [{
|
||||
sel: '#'+id,
|
||||
fn: btn.events.click,
|
||||
icon: btn.id,
|
||||
|
@ -1355,7 +1356,9 @@
|
|||
}
|
||||
if (btn.key) {
|
||||
$(document).bind('keydown', btn.key, func);
|
||||
if (btn.title) button.attr('title', btn.title + ' ['+btn.key+']');
|
||||
if (btn.title) {
|
||||
button.attr('title', btn.title + ' ['+btn.key+']');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
button.bind(name, func);
|
||||
|
@ -1370,8 +1373,9 @@
|
|||
addAltDropDown(this.elem, this.list, this.callback, {seticon: true});
|
||||
});
|
||||
|
||||
if (svgicons)
|
||||
if (svgicons) {
|
||||
cb_ready = false; // Delay callback
|
||||
}
|
||||
|
||||
$.svgIcons(svgicons, {
|
||||
w:24, h:24,
|
||||
|
@ -1415,6 +1419,7 @@
|
|||
// updates the toolbar (colors, opacity, etc) based on the selected element
|
||||
// This function also updates the opacity and id elements that are in the context panel
|
||||
var updateToolbar = function() {
|
||||
var i;
|
||||
if (selectedElement != null) {
|
||||
switch (selectedElement.tagName) {
|
||||
case 'use':
|
||||
|
@ -1426,7 +1431,7 @@
|
|||
// Look for common styles
|
||||
var gWidth = null;
|
||||
var childs = selectedElement.getElementsByTagName('*');
|
||||
for (var i = 0, len = childs.length; i < len; i++) {
|
||||
for (i = 0, len = childs.length; i < len; i++) {
|
||||
var swidth = childs[i].getAttribute('stroke-width');
|
||||
|
||||
if (i === 0) {
|
||||
|
@ -1451,13 +1456,15 @@
|
|||
|
||||
var attr = selectedElement.getAttribute('stroke-linejoin') || 'miter';
|
||||
|
||||
if ($('#linejoin_' + attr).length != 0)
|
||||
if ($('#linejoin_' + attr).length != 0) {
|
||||
setStrokeOpt($('#linejoin_' + attr)[0]);
|
||||
}
|
||||
|
||||
attr = selectedElement.getAttribute('stroke-linecap') || 'butt';
|
||||
|
||||
if ($('#linecap_' + attr).length != 0)
|
||||
if ($('#linecap_' + attr).length != 0) {
|
||||
setStrokeOpt($('#linecap_' + attr)[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1473,7 +1480,9 @@
|
|||
};
|
||||
|
||||
var setImageURL = Editor.setImageURL = function(url) {
|
||||
if (!url) url = defaultImageURL;
|
||||
if (!url) {
|
||||
url = defaultImageURL;
|
||||
}
|
||||
svgCanvas.setImageURL(url);
|
||||
$('#image_url').val(url);
|
||||
|
||||
|
@ -1502,15 +1511,16 @@
|
|||
var updateContextPanel = function() {
|
||||
var elem = selectedElement;
|
||||
// If element has just been deleted, consider it null
|
||||
if (elem != null && !elem.parentNode) elem = null;
|
||||
if (elem != null && !elem.parentNode) {elem = null;}
|
||||
var currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName();
|
||||
var currentMode = svgCanvas.getMode();
|
||||
var unit = curConfig.baseUnit !== 'px' ? curConfig.baseUnit : null;
|
||||
|
||||
var is_node = currentMode == 'pathedit'; //elem ? (elem.id && elem.id.indexOf('pathpointgrip') == 0) : false;
|
||||
var menu_items = $('#cmenu_canvas li');
|
||||
$('#selected_panel, #multiselected_panel, #g_panel, #rect_panel, #circle_panel,\
|
||||
#ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel, #use_panel, #a_panel').hide();
|
||||
$('#selected_panel, #multiselected_panel, #g_panel, #rect_panel, #circle_panel,'+
|
||||
'#ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel,'+
|
||||
' #use_panel, #a_panel').hide();
|
||||
if (elem != null) {
|
||||
var elname = elem.nodeName;
|
||||
// If this is a link with no transform and one child, pretend
|
||||
|
@ -1736,7 +1746,7 @@
|
|||
// Set up editor background functionality
|
||||
// TODO add checkerboard as "pattern"
|
||||
var color_blocks = ['#FFF', '#888', '#000']; // ,'url(data:image/gif;base64,R0lGODlhEAAQAIAAAP%2F%2F%2F9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG%2Bgq4jM3IFLJgpswNly%2FXkcBpIiVaInlLJr9FZWAQA7)'];
|
||||
var str = '';
|
||||
str = '';
|
||||
$.each(color_blocks, function() {
|
||||
str += '<div class="color_block" style="background-color:' + this + ';"></div>';
|
||||
});
|
||||
|
@ -1785,8 +1795,8 @@
|
|||
};
|
||||
var changeZoom = function(ctl) {
|
||||
var zoomlevel = ctl.value / 100;
|
||||
if (zoomlevel < .001) {
|
||||
ctl.value = .1;
|
||||
if (zoomlevel < 0.001) {
|
||||
ctl.value = 0.1;
|
||||
return;
|
||||
}
|
||||
var zoom = svgCanvas.getZoom();
|
||||
|
@ -1803,7 +1813,7 @@
|
|||
};
|
||||
|
||||
var changeOpacity = function(ctl, val) {
|
||||
if (val == null) val = ctl.value;
|
||||
if (val == null) {val = ctl.value;}
|
||||
$('#group_opacity').val(val);
|
||||
if (!ctl || !ctl.handle) {
|
||||
$('#opac_slider').slider('option', 'value', val);
|
||||
|
@ -1812,7 +1822,7 @@
|
|||
};
|
||||
|
||||
var changeBlur = function(ctl, val, noUndo) {
|
||||
if (val == null) val = ctl.value;
|
||||
if (val == null) {val = ctl.value;}
|
||||
$('#blur').val(val);
|
||||
var complete = false;
|
||||
if (!ctl || !ctl.handle) {
|
||||
|
@ -1853,7 +1863,7 @@
|
|||
var destLayer = this.options[this.selectedIndex].value;
|
||||
var confirmStr = uiStrings.notification.QmoveElemsToLayer.replace('%s', destLayer);
|
||||
var moveToLayer = function(ok) {
|
||||
if (!ok) return;
|
||||
if (!ok) {return;}
|
||||
promptMoveLayerOnce = true;
|
||||
svgCanvas.moveSelectedToLayer(destLayer);
|
||||
svgCanvas.clearSelection();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/*globals $, svgedit*/
|
||||
/*jslint vars: true, eqeq: true*/
|
||||
/**
|
||||
* SVGTransformList
|
||||
*
|
||||
|
@ -10,7 +12,7 @@
|
|||
// Dependencies:
|
||||
// 1) browser.js
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.transformlist) {
|
||||
svgedit.transformlist = {};
|
||||
|
@ -30,8 +32,8 @@ function transformToString(xform) {
|
|||
text = 'translate(' + m.e + ',' + m.f + ')';
|
||||
break;
|
||||
case 3: // SCALE
|
||||
if (m.a == m.d) text = 'scale(' + m.a + ')';
|
||||
else text = 'scale(' + m.a + ',' + m.d + ')';
|
||||
if (m.a == m.d) {text = 'scale(' + m.a + ')';}
|
||||
else {text = 'scale(' + m.a + ',' + m.d + ')';}
|
||||
break;
|
||||
case 4: // ROTATE
|
||||
var cx = 0, cy = 0;
|
||||
|
@ -80,7 +82,8 @@ svgedit.transformlist.SVGTransformList = function(elem) {
|
|||
this._update = function() {
|
||||
var tstr = '';
|
||||
var concatMatrix = svgroot.createSVGMatrix();
|
||||
for (var i = 0; i < this.numberOfItems; ++i) {
|
||||
var i;
|
||||
for (i = 0; i < this.numberOfItems; ++i) {
|
||||
var xform = this._list.getItem(i);
|
||||
tstr += transformToString(xform) + ' ';
|
||||
}
|
||||
|
@ -90,7 +93,7 @@ svgedit.transformlist.SVGTransformList = function(elem) {
|
|||
this._init = function() {
|
||||
// Transform attribute parser
|
||||
var str = this._elem.getAttribute('transform');
|
||||
if (!str) return;
|
||||
if (!str) {return;}
|
||||
|
||||
// TODO: Add skew support in future
|
||||
var re = /\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/;
|
||||
|
@ -134,9 +137,11 @@ svgedit.transformlist.SVGTransformList = function(elem) {
|
|||
// Check if this transform is already in a transformlist, and
|
||||
// remove it if so.
|
||||
var found = false;
|
||||
for (var id in listMap_) {
|
||||
var id;
|
||||
for (id in listMap_) {
|
||||
var tl = listMap_[id];
|
||||
for (var i = 0, len = tl._xforms.length; i < len; ++i) {
|
||||
var i, len;
|
||||
for (i = 0, len = tl._xforms.length; i < len; ++i) {
|
||||
if (tl._xforms[i] == item) {
|
||||
found = true;
|
||||
tl.removeItem(i);
|
||||
|
@ -176,11 +181,13 @@ svgedit.transformlist.SVGTransformList = function(elem) {
|
|||
this._removeFromOtherLists(newItem);
|
||||
var newxforms = new Array(this.numberOfItems + 1);
|
||||
// TODO: use array copying and slicing
|
||||
for ( var i = 0; i < index; ++i) {
|
||||
var i;
|
||||
for (i = 0; i < index; ++i) {
|
||||
newxforms[i] = this._xforms[i];
|
||||
}
|
||||
newxforms[i] = newItem;
|
||||
for ( var j = i+1; i < this.numberOfItems; ++j, ++i) {
|
||||
var j;
|
||||
for (j = i+1; i < this.numberOfItems; ++j, ++i) {
|
||||
newxforms[j] = this._xforms[i];
|
||||
}
|
||||
this.numberOfItems++;
|
||||
|
@ -210,10 +217,11 @@ svgedit.transformlist.SVGTransformList = function(elem) {
|
|||
if (index < this.numberOfItems && index >= 0) {
|
||||
var retValue = this._xforms[index];
|
||||
var newxforms = new Array(this.numberOfItems - 1);
|
||||
for (var i = 0; i < index; ++i) {
|
||||
var i, j;
|
||||
for (i = 0; i < index; ++i) {
|
||||
newxforms[i] = this._xforms[i];
|
||||
}
|
||||
for (var j = i; j < this.numberOfItems-1; ++j, ++i) {
|
||||
for (j = i; j < this.numberOfItems-1; ++j, ++i) {
|
||||
newxforms[j] = this._xforms[i+1];
|
||||
}
|
||||
this.numberOfItems--;
|
||||
|
@ -278,4 +286,4 @@ svgedit.transformlist.getTransformList = function(elem) {
|
|||
return null;
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
|
@ -1,3 +1,5 @@
|
|||
/*globals $, svgedit, unescape, DOMParser, ActiveXObject, getStrokedBBox*/
|
||||
/*jslint vars: true, eqeq: true, bitwise: true, continue: true, forin: true*/
|
||||
/**
|
||||
* Package: svgedit.utilities
|
||||
*
|
||||
|
@ -13,7 +15,7 @@
|
|||
// 3) svgtransformlist.js
|
||||
// 4) units.js
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.utilities) {
|
||||
svgedit.utilities = {};
|
||||
|
@ -74,7 +76,7 @@ svgedit.utilities.fromXml = function(str) {
|
|||
// Base64 code from Tyler Akins -- http://rumkin.com
|
||||
|
||||
// schiller: Removed string concatenation in favour of Array.join() optimization,
|
||||
// also precalculate the size of the array needed.
|
||||
// also precalculate the size of the array needed.
|
||||
|
||||
// Function: svgedit.utilities.encode64
|
||||
// Converts a string to base64
|
||||
|
@ -158,32 +160,33 @@ svgedit.utilities.decode64 = function(input) {
|
|||
// Currently not being used, so commented out for now
|
||||
// based on http://phpjs.org/functions/utf8_encode:577
|
||||
// codedread:does not seem to work with webkit-based browsers on OSX
|
||||
// 'encodeUTF8': function(input) {
|
||||
// //return unescape(encodeURIComponent(input)); //may or may not work
|
||||
// var output = '';
|
||||
// for (var n = 0; n < input.length; n++){
|
||||
// var c = input.charCodeAt(n);
|
||||
// if (c < 128) {
|
||||
// output += input[n];
|
||||
// }
|
||||
// else if (c > 127) {
|
||||
// if (c < 2048){
|
||||
// output += String.fromCharCode((c >> 6) | 192);
|
||||
// }
|
||||
// else {
|
||||
// output += String.fromCharCode((c >> 12) | 224) + String.fromCharCode((c >> 6) & 63 | 128);
|
||||
// }
|
||||
// output += String.fromCharCode((c & 63) | 128);
|
||||
// }
|
||||
// }
|
||||
// return output;
|
||||
// },
|
||||
// 'encodeUTF8': function(input) {
|
||||
// //return unescape(encodeURIComponent(input)); //may or may not work
|
||||
// var output = '';
|
||||
// for (var n = 0; n < input.length; n++){
|
||||
// var c = input.charCodeAt(n);
|
||||
// if (c < 128) {
|
||||
// output += input[n];
|
||||
// }
|
||||
// else if (c > 127) {
|
||||
// if (c < 2048){
|
||||
// output += String.fromCharCode((c >> 6) | 192);
|
||||
// }
|
||||
// else {
|
||||
// output += String.fromCharCode((c >> 12) | 224) + String.fromCharCode((c >> 6) & 63 | 128);
|
||||
// }
|
||||
// output += String.fromCharCode((c & 63) | 128);
|
||||
// }
|
||||
// }
|
||||
// return output;
|
||||
// },
|
||||
|
||||
// Function: svgedit.utilities.convertToXMLReferences
|
||||
// Converts a string to use XML references
|
||||
svgedit.utilities.convertToXMLReferences = function(input) {
|
||||
var output = '';
|
||||
for (var n = 0; n < input.length; n++){
|
||||
var n,
|
||||
output = '';
|
||||
for (n = 0; n < input.length; n++){
|
||||
var c = input.charCodeAt(n);
|
||||
if (c < 128) {
|
||||
output += input[n];
|
||||
|
@ -202,18 +205,22 @@ svgedit.utilities.text2xml = function(sXML) {
|
|||
sXML = sXML.replace(/<(\/?)svg:/g, '<$1').replace('xmlns:svg', 'xmlns');
|
||||
}
|
||||
|
||||
var out;
|
||||
var out, dXML;
|
||||
try{
|
||||
var dXML = (window.DOMParser)?new DOMParser():new ActiveXObject('Microsoft.XMLDOM');
|
||||
dXML = (window.DOMParser)?new DOMParser():new ActiveXObject('Microsoft.XMLDOM');
|
||||
dXML.async = false;
|
||||
} catch(e){
|
||||
throw new Error('XML Parser could not be instantiated');
|
||||
}
|
||||
try{
|
||||
if(dXML.loadXML) out = (dXML.loadXML(sXML)) ? dXML : false;
|
||||
else out = dXML.parseFromString(sXML, 'text/xml');
|
||||
if (dXML.loadXML) {
|
||||
out = (dXML.loadXML(sXML)) ? dXML : false;
|
||||
}
|
||||
else {
|
||||
out = dXML.parseFromString(sXML, 'text/xml');
|
||||
}
|
||||
}
|
||||
catch(e){ throw new Error('Error parsing XML string'); }
|
||||
catch(e2){ throw new Error('Error parsing XML string'); }
|
||||
return out;
|
||||
};
|
||||
|
||||
|
@ -286,10 +293,10 @@ svgedit.utilities.getUrlFromAttr = function(attrVal) {
|
|||
return attrVal.substring(5, attrVal.indexOf('"',6));
|
||||
}
|
||||
// url('#somegrad')
|
||||
else if (attrVal.indexOf("url('") === 0) {
|
||||
if (attrVal.indexOf("url('") === 0) {
|
||||
return attrVal.substring(5, attrVal.indexOf("'",6));
|
||||
}
|
||||
else if (attrVal.indexOf("url(") === 0) {
|
||||
if (attrVal.indexOf("url(") === 0) {
|
||||
return attrVal.substring(4, attrVal.indexOf(')'));
|
||||
}
|
||||
}
|
||||
|
@ -349,10 +356,11 @@ svgedit.utilities.getPathBBox = function(path) {
|
|||
var start = seglist.getItem(0);
|
||||
var P0 = [start.x, start.y];
|
||||
|
||||
for(var i=0; i < tot; i++) {
|
||||
var i;
|
||||
for (i = 0; i < tot; i++) {
|
||||
var seg = seglist.getItem(i);
|
||||
|
||||
if(typeof seg.x == 'undefined') continue;
|
||||
if(typeof seg.x == 'undefined') {continue;}
|
||||
|
||||
// Add actual points to limits
|
||||
bounds[0].push(P0[0]);
|
||||
|
@ -363,7 +371,8 @@ svgedit.utilities.getPathBBox = function(path) {
|
|||
P2 = [seg.x2, seg.y2],
|
||||
P3 = [seg.x, seg.y];
|
||||
|
||||
for(var j=0; j < 2; j++) {
|
||||
var j;
|
||||
for (j = 0; j < 2; j++) {
|
||||
|
||||
var calc = function(t) {
|
||||
return Math.pow(1-t,3) * P0[j]
|
||||
|
@ -376,22 +385,22 @@ svgedit.utilities.getPathBBox = function(path) {
|
|||
var a = -3 * P0[j] + 9 * P1[j] - 9 * P2[j] + 3 * P3[j];
|
||||
var c = 3 * P1[j] - 3 * P0[j];
|
||||
|
||||
if(a == 0) {
|
||||
if(b == 0) {
|
||||
if (a == 0) {
|
||||
if (b == 0) {
|
||||
continue;
|
||||
}
|
||||
var t = -c / b;
|
||||
if(0 < t && t < 1) {
|
||||
if (0 < t && t < 1) {
|
||||
bounds[j].push(calc(t));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
var b2ac = Math.pow(b,2) - 4 * c * a;
|
||||
if(b2ac < 0) continue;
|
||||
if (b2ac < 0) {continue;}
|
||||
var t1 = (-b + Math.sqrt(b2ac))/(2 * a);
|
||||
if(0 < t1 && t1 < 1) bounds[j].push(calc(t1));
|
||||
if (0 < t1 && t1 < 1) {bounds[j].push(calc(t1));}
|
||||
var t2 = (-b - Math.sqrt(b2ac))/(2 * a);
|
||||
if(0 < t2 && t2 < 1) bounds[j].push(calc(t2));
|
||||
if (0 < t2 && t2 < 1) {bounds[j].push(calc(t2));}
|
||||
}
|
||||
P0 = P3;
|
||||
} else {
|
||||
|
@ -426,10 +435,10 @@ function groupBBFix(selected) {
|
|||
}
|
||||
var ref = $.data(selected, 'ref');
|
||||
var matched = null;
|
||||
var ret;
|
||||
var ret, copy;
|
||||
|
||||
if(ref) {
|
||||
var copy = $(ref).children().clone().attr('visibility', 'hidden');
|
||||
copy = $(ref).children().clone().attr('visibility', 'hidden');
|
||||
$(svgroot_).append(copy);
|
||||
matched = copy.filter('line, path');
|
||||
} else {
|
||||
|
@ -446,7 +455,7 @@ function groupBBFix(selected) {
|
|||
});
|
||||
if(issue) {
|
||||
var elems = ref ? copy : $(selected).children();
|
||||
ret = getStrokedBBox(elems);
|
||||
ret = getStrokedBBox(elems); // getStrokedBBox defined in svgcanvas
|
||||
} else {
|
||||
ret = selected.getBBox();
|
||||
}
|
||||
|
@ -467,7 +476,7 @@ function groupBBFix(selected) {
|
|||
// elem - Optional DOM element to get the BBox for
|
||||
svgedit.utilities.getBBox = function(elem) {
|
||||
var selected = elem || editorContext_.geSelectedElements()[0];
|
||||
if (elem.nodeType != 1) return null;
|
||||
if (elem.nodeType != 1) {return null;}
|
||||
var ret = null;
|
||||
var elname = selected.nodeName;
|
||||
|
||||
|
@ -485,7 +494,7 @@ svgedit.utilities.getBBox = function(elem) {
|
|||
if(!svgedit.browser.supportsPathBBox()) {
|
||||
ret = svgedit.utilities.getPathBBox(selected);
|
||||
} else {
|
||||
try { ret = selected.getBBox();} catch(e){}
|
||||
try { ret = selected.getBBox();} catch(e2){}
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
|
@ -498,7 +507,7 @@ svgedit.utilities.getBBox = function(elem) {
|
|||
ret = groupBBFix(selected, true);
|
||||
}
|
||||
if(elname === 'use' || ( elname === 'foreignObject' && svgedit.browser.isWebkit() ) ) {
|
||||
if(!ret) ret = selected.getBBox();
|
||||
if(!ret) {ret = selected.getBBox();}
|
||||
// This is resolved in later versions of webkit, perhaps we should
|
||||
// have a featured detection for correct 'use' behavior?
|
||||
// ——————————
|
||||
|
@ -512,13 +521,13 @@ svgedit.utilities.getBBox = function(elem) {
|
|||
//}
|
||||
} else if(~visElems_arr.indexOf(elname)) {
|
||||
try { ret = selected.getBBox();}
|
||||
catch(e) {
|
||||
catch(e3) {
|
||||
// Check if element is child of a foreignObject
|
||||
var fo = $(selected).closest('foreignObject');
|
||||
if(fo.length) {
|
||||
try {
|
||||
ret = fo[0].getBBox();
|
||||
} catch(e) {
|
||||
} catch(e4) {
|
||||
ret = null;
|
||||
}
|
||||
} else {
|
||||
|
@ -548,9 +557,10 @@ svgedit.utilities.getRotationAngle = function(elem, to_rad) {
|
|||
var selected = elem || editorContext_.getSelectedElements()[0];
|
||||
// find the rotation transform (if any) and set it
|
||||
var tlist = svgedit.transformlist.getTransformList(selected);
|
||||
if(!tlist) return 0; // <svg> elements have no tlist
|
||||
if(!tlist) {return 0;} // <svg> elements have no tlist
|
||||
var N = tlist.numberOfItems;
|
||||
for (var i = 0; i < N; ++i) {
|
||||
var i;
|
||||
for (i = 0; i < N; ++i) {
|
||||
var xform = tlist.getItem(i);
|
||||
if (xform.type == 4) {
|
||||
return to_rad ? xform.angle * Math.PI / 180.0 : xform.angle;
|
||||
|
@ -604,12 +614,13 @@ if (svgedit.browser.supportsSelectors()) {
|
|||
// suspendLength - Optional integer of milliseconds to suspend redraw
|
||||
// unitCheck - Boolean to indicate the need to use svgedit.units.setUnitAttr
|
||||
svgedit.utilities.assignAttributes = function(node, attrs, suspendLength, unitCheck) {
|
||||
if(!suspendLength) suspendLength = 0;
|
||||
if(!suspendLength) {suspendLength = 0;}
|
||||
// Opera has a problem with suspendRedraw() apparently
|
||||
var handle = null;
|
||||
if (!svgedit.browser.isOpera()) svgroot_.suspendRedraw(suspendLength);
|
||||
if (!svgedit.browser.isOpera()) {svgroot_.suspendRedraw(suspendLength);}
|
||||
|
||||
for (var i in attrs) {
|
||||
var i;
|
||||
for (i in attrs) {
|
||||
var ns = (i.substr(0,4) === 'xml:' ? NS.XML :
|
||||
i.substr(0,6) === 'xlink:' ? NS.XLINK : null);
|
||||
|
||||
|
@ -621,7 +632,7 @@ svgedit.utilities.assignAttributes = function(node, attrs, suspendLength, unitCh
|
|||
svgedit.units.setUnitAttr(node, i, attrs[i]);
|
||||
}
|
||||
}
|
||||
if (!svgedit.browser.isOpera()) svgroot_.unsuspendRedraw(handle);
|
||||
if (!svgedit.browser.isOpera()) {svgroot_.unsuspendRedraw(handle);}
|
||||
};
|
||||
|
||||
// Function: cleanupElement
|
||||
|
@ -645,7 +656,8 @@ svgedit.utilities.cleanupElement = function(element) {
|
|||
'ry':0
|
||||
};
|
||||
|
||||
for(var attr in defaults) {
|
||||
var attr;
|
||||
for (attr in defaults) {
|
||||
var val = defaults[attr];
|
||||
if(element.getAttribute(attr) == val) {
|
||||
element.removeAttribute(attr);
|
||||
|
@ -668,4 +680,4 @@ svgedit.utilities.snapToGrid = function(value) {
|
|||
return value;
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript/
|
||||
function touchHandler(event) {
|
||||
function touchHandler(event) {'use strict';
|
||||
|
||||
var touches = event.changedTouches,
|
||||
var simulatedEvent,
|
||||
touches = event.changedTouches,
|
||||
first = touches[0],
|
||||
type = "";
|
||||
switch (event.type) {
|
||||
|
@ -15,7 +16,7 @@ function touchHandler(event) {
|
|||
// screenX, screenY, clientX, clientY, ctrlKey,
|
||||
// altKey, shiftKey, metaKey, button, relatedTarget);
|
||||
|
||||
var simulatedEvent = document.createEvent("MouseEvent");
|
||||
simulatedEvent = document.createEvent("MouseEvent");
|
||||
simulatedEvent.initMouseEvent(type, true, true, window, 1,
|
||||
first.screenX, first.screenY,
|
||||
first.clientX, first.clientY, false,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/*globals $, svgedit*/
|
||||
/*jslint vars: true, eqeq: true*/
|
||||
/**
|
||||
* Package: svgedit.units
|
||||
*
|
||||
|
@ -10,7 +12,7 @@
|
|||
// Dependencies:
|
||||
// 1) jQuery
|
||||
|
||||
(function() {
|
||||
(function() {'use strict';
|
||||
|
||||
if (!svgedit.units) {
|
||||
svgedit.units = {};
|
||||
|
@ -133,7 +135,7 @@ svgedit.units.convertUnit = function(val, unit) {
|
|||
// attr - String with the name of the attribute associated with the value
|
||||
// val - String with the attribute value to convert
|
||||
svgedit.units.setUnitAttr = function(elem, attr, val) {
|
||||
if (!isNaN(val)) {
|
||||
// if (!isNaN(val)) {
|
||||
// New value is a number, so check currently used unit
|
||||
// var old_val = elem.getAttribute(attr);
|
||||
|
||||
|
@ -163,7 +165,7 @@ svgedit.units.setUnitAttr = function(elem, attr, val) {
|
|||
//
|
||||
// val += unit;
|
||||
// }
|
||||
}
|
||||
// }
|
||||
elem.setAttribute(attr, val);
|
||||
};
|
||||
|
||||
|
@ -187,18 +189,20 @@ svgedit.units.convertAttrs = function(element) {
|
|||
var elName = element.tagName;
|
||||
var unit = elementContainer_.getBaseUnit();
|
||||
var attrs = attrsToConvert[elName];
|
||||
if (!attrs) return;
|
||||
if (!attrs) {return;}
|
||||
|
||||
var len = attrs.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var i;
|
||||
for (i = 0; i < len; i++) {
|
||||
var attr = attrs[i];
|
||||
var cur = element.getAttribute(attr);
|
||||
if (cur) {
|
||||
if (!isNaN(cur)) {
|
||||
element.setAttribute(attr, (cur / typeMap_[unit]) + unit);
|
||||
} else {
|
||||
// Convert existing?
|
||||
}
|
||||
// else {
|
||||
// Convert existing?
|
||||
// }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -212,11 +216,11 @@ svgedit.units.convertAttrs = function(element) {
|
|||
// val - String with the attribute value to convert
|
||||
svgedit.units.convertToNum = function(attr, val) {
|
||||
// Return a number if that's what it already is
|
||||
if (!isNaN(val)) return val-0;
|
||||
|
||||
if (!isNaN(val)) {return val-0;}
|
||||
var num;
|
||||
if (val.substr(-1) === '%') {
|
||||
// Deal with percentage, depends on attribute
|
||||
var num = val.substr(0, val.length-1)/100;
|
||||
num = val.substr(0, val.length-1)/100;
|
||||
var width = elementContainer_.getWidth();
|
||||
var height = elementContainer_.getHeight();
|
||||
|
||||
|
@ -229,7 +233,7 @@ svgedit.units.convertToNum = function(attr, val) {
|
|||
return num * Math.sqrt((width*width) + (height*height))/Math.sqrt(2);
|
||||
}
|
||||
var unit = val.substr(-2);
|
||||
var num = val.substr(0, val.length-2);
|
||||
num = val.substr(0, val.length-2);
|
||||
// Note that this multiplication turns the string into a number
|
||||
return num * typeMap_[unit];
|
||||
};
|
||||
|
@ -250,9 +254,9 @@ svgedit.units.isValidUnit = function(attr, val, selectedElement) {
|
|||
// Not a number, check if it has a valid unit
|
||||
val = val.toLowerCase();
|
||||
$.each(typeMap_, function(unit) {
|
||||
if (valid) return;
|
||||
if (valid) {return;}
|
||||
var re = new RegExp('^-?[\\d\\.]+' + unit + '$');
|
||||
if (re.test(val)) valid = true;
|
||||
if (re.test(val)) {valid = true;}
|
||||
});
|
||||
}
|
||||
} else if (attr == 'id') {
|
||||
|
@ -269,11 +273,10 @@ svgedit.units.isValidUnit = function(attr, val, selectedElement) {
|
|||
result = (elem == null || elem === selectedElement);
|
||||
} catch(e) {}
|
||||
return result;
|
||||
} else {
|
||||
valid = true;
|
||||
}
|
||||
valid = true;
|
||||
|
||||
return valid;
|
||||
};
|
||||
|
||||
})();
|
||||
}());
|
Loading…
Reference in New Issue