cleanup
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@50 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -7,6 +7,8 @@
|
|||||||
* fix flyouts when using color picker
|
* fix flyouts when using color picker
|
||||||
* change license from GPLv2 to Apache License v2.0
|
* change license from GPLv2 to Apache License v2.0
|
||||||
* replaced Farbtastic with jPicker, because of the license issues
|
* replaced Farbtastic with jPicker, because of the license issues
|
||||||
|
* removed dependency on svgcanvas.svg, now created in JavaScript
|
||||||
|
* added Select tool
|
||||||
|
|
||||||
2.0 - June 03, 2009
|
2.0 - June 03, 2009
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
#tools {
|
#tools {
|
||||||
background: #E8E8E8;
|
background: #E8E8E8;
|
||||||
height: 534px;
|
height: 580px;
|
||||||
border: 1px solid #808080;
|
border: 1px solid #808080;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ var palette = ["#000000","#202020","#404040","#606060","#808080","#a0a0a0","#c0c
|
|||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var svgCanvas = new SvgCanvas(document.getElementById("svgcanvas"));
|
var svgCanvas = new SvgCanvas(document.getElementById("svgcanvas"));
|
||||||
|
|
||||||
var selectedChanged = function(window,elem) {
|
var selectedChanged = function(window,elem) {
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
|
|
||||||
// update fill color
|
// update fill color
|
||||||
var fillColor = elem.getAttribute("fill");
|
var fillColor = elem.getAttribute("fill");
|
||||||
if (fillColor == null || fillColor == "" || fillColor == "none") {
|
if (fillColor == null || fillColor == "" || fillColor == "none") {
|
||||||
fillColor = 'url(\'images/none.png\')';
|
fillColor = 'url(\'images/none.png\')';
|
||||||
}
|
}
|
||||||
$('#fill_color').css('background', fillColor);
|
$('#fill_color').css('background', fillColor);
|
||||||
|
|
||||||
// update stroke color
|
// update stroke color
|
||||||
var strokeColor = elem.getAttribute("stroke");
|
var strokeColor = elem.getAttribute("stroke");
|
||||||
if (strokeColor == null || strokeColor == "" || strokeColor == "none") {
|
if (strokeColor == null || strokeColor == "" || strokeColor == "none") {
|
||||||
@@ -20,7 +20,7 @@ $(document).ready(function(){
|
|||||||
}
|
}
|
||||||
$('#stroke_color').css('background', strokeColor);
|
$('#stroke_color').css('background', strokeColor);
|
||||||
|
|
||||||
// update fill opacity
|
// update fill opacity
|
||||||
var fillOpacity = elem.getAttribute("fill-opacity");
|
var fillOpacity = elem.getAttribute("fill-opacity");
|
||||||
if (fillOpacity == null || fillColor == "") {
|
if (fillOpacity == null || fillColor == "") {
|
||||||
fillOpacity = 1.0;
|
fillOpacity = 1.0;
|
||||||
@@ -28,14 +28,22 @@ $(document).ready(function(){
|
|||||||
fillOpacity = (fillOpacity*100)+" %";
|
fillOpacity = (fillOpacity*100)+" %";
|
||||||
$('#fill_opacity').val(fillOpacity);
|
$('#fill_opacity').val(fillOpacity);
|
||||||
|
|
||||||
// update stroke opacity
|
// update stroke opacity
|
||||||
var strokeOpacity = elem.getAttribute("stroke-opacity");
|
var strokeOpacity = elem.getAttribute("stroke-opacity");
|
||||||
if (strokeOpacity == null || strokeOpacity == "") {
|
if (strokeOpacity == null || strokeOpacity == "") {
|
||||||
strokeOpacity = 1.0;
|
strokeOpacity = 1.0;
|
||||||
}
|
}
|
||||||
strokeOpacity = (strokeOpacity*100)+" %";
|
strokeOpacity = (strokeOpacity*100)+" %";
|
||||||
$('#stroke_opacity').val(strokeOpacity);
|
$('#stroke_opacity').val(strokeOpacity);
|
||||||
|
|
||||||
|
// update group opacity
|
||||||
|
var opacity = elem.getAttribute("opacity");
|
||||||
|
if (opacity == null || opacity == "") {
|
||||||
|
opacity = 1.0;
|
||||||
|
}
|
||||||
|
opacity = (opacity*100)+" %";
|
||||||
|
$('#group_opacity').val(opacity);
|
||||||
|
|
||||||
var strokeWidth = elem.getAttribute("stroke-width");
|
var strokeWidth = elem.getAttribute("stroke-width");
|
||||||
if (strokeWidth == null || strokeWidth == "") {
|
if (strokeWidth == null || strokeWidth == "") {
|
||||||
strokeWidth = 1;
|
strokeWidth = 1;
|
||||||
@@ -49,7 +57,7 @@ $(document).ready(function(){
|
|||||||
$('#stroke_dasharray').val(strokeDashArray);
|
$('#stroke_dasharray').val(strokeDashArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the selected event to our function that handles updates to the UI
|
// bind the selected event to our function that handles updates to the UI
|
||||||
svgCanvas.bind("selected", selectedChanged);
|
svgCanvas.bind("selected", selectedChanged);
|
||||||
|
|
||||||
@@ -105,7 +113,7 @@ $(document).ready(function(){
|
|||||||
}
|
}
|
||||||
svgCanvas.setStrokeColor(color);
|
svgCanvas.setStrokeColor(color);
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is a common function used when a tool has been clicked (chosen)
|
// This is a common function used when a tool has been clicked (chosen)
|
||||||
// It does several common things:
|
// It does several common things:
|
||||||
// - hides any flyout menus
|
// - hides any flyout menus
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ function SvgCanvas(c)
|
|||||||
|
|
||||||
var svgdoc = c.ownerDocument;
|
var svgdoc = c.ownerDocument;
|
||||||
var svgroot = svgdoc.createElementNS(svgns, "svg");
|
var svgroot = svgdoc.createElementNS(svgns, "svg");
|
||||||
svgroot.setAttribute("width",640);
|
svgroot.setAttribute("width", 640);
|
||||||
svgroot.setAttribute("height",480);
|
svgroot.setAttribute("height", 480);
|
||||||
svgroot.setAttributeNS(null,"id","svgroot");
|
svgroot.setAttributeNS(null, "id", "svgroot");
|
||||||
container.appendChild(svgroot);
|
container.appendChild(svgroot);
|
||||||
|
|
||||||
var d_attr = null;
|
var d_attr = null;
|
||||||
@@ -84,17 +84,10 @@ function SvgCanvas(c)
|
|||||||
var attr;
|
var attr;
|
||||||
var i;
|
var i;
|
||||||
var childs = elem.childNodes;
|
var childs = elem.childNodes;
|
||||||
// don't include scripts in output svg
|
|
||||||
if (elem.nodeName == "script") return "";
|
|
||||||
for (i=0; i<indent; i++) out += " ";
|
for (i=0; i<indent; i++) out += " ";
|
||||||
out += "<" + elem.nodeName;
|
out += "<" + elem.nodeName;
|
||||||
for (i=attrs.length-1; i>=0; i--) {
|
for (i=attrs.length-1; i>=0; i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
// don't include events in output svg
|
|
||||||
if (attr.nodeName == "onload" ||
|
|
||||||
attr.nodeName == "onmousedown" ||
|
|
||||||
attr.nodeName == "onmousemove" ||
|
|
||||||
attr.nodeName == "onmouseup") continue;
|
|
||||||
out += " " + attr.nodeName + "=\"" + attr.nodeValue+ "\"";
|
out += " " + attr.nodeName + "=\"" + attr.nodeValue+ "\"";
|
||||||
}
|
}
|
||||||
if (elem.hasChildNodes()) {
|
if (elem.hasChildNodes()) {
|
||||||
@@ -307,7 +300,7 @@ function SvgCanvas(c)
|
|||||||
shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size);
|
shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size);
|
||||||
shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size);
|
shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size);
|
||||||
break;
|
break;
|
||||||
case "select":
|
// case "select":
|
||||||
case "rect":
|
case "rect":
|
||||||
shape.setAttributeNS(null, "x", Math.min(start_x,x));
|
shape.setAttributeNS(null, "x", Math.min(start_x,x));
|
||||||
shape.setAttributeNS(null, "y", Math.min(start_y,y));
|
shape.setAttributeNS(null, "y", Math.min(start_y,y));
|
||||||
@@ -349,6 +342,7 @@ function SvgCanvas(c)
|
|||||||
var keep = false;
|
var keep = false;
|
||||||
switch (current_mode)
|
switch (current_mode)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
case "select":
|
case "select":
|
||||||
if (element.getAttribute('width') == 0 &&
|
if (element.getAttribute('width') == 0 &&
|
||||||
element.getAttribute('height') == 0) {
|
element.getAttribute('height') == 0) {
|
||||||
@@ -359,24 +353,25 @@ function SvgCanvas(c)
|
|||||||
// should scan elements which are in rect(x,y,width,height) and select them
|
// should scan elements which are in rect(x,y,width,height) and select them
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
*/
|
||||||
case "path":
|
case "path":
|
||||||
keep = true;
|
keep = true;
|
||||||
break;
|
break;
|
||||||
case "line":
|
case "line":
|
||||||
keep = (element.getAttribute('x1') != element.getAttribute('x2') ||
|
keep = (element.getAttribute('x1') != element.getAttribute('x2') ||
|
||||||
element.getAttribute('y1') == element.getAttribute('y2'));
|
element.getAttribute('y1') == element.getAttribute('y2'));
|
||||||
break;
|
break;
|
||||||
case "square":
|
case "square":
|
||||||
case "rect":
|
case "rect":
|
||||||
keep = (element.getAttribute('width') != 0 ||
|
keep = (element.getAttribute('width') != 0 ||
|
||||||
element.getAttribute('height') != 0);
|
element.getAttribute('height') != 0);
|
||||||
break;
|
break;
|
||||||
case "circle":
|
case "circle":
|
||||||
keep = (element.getAttribute('r') != 0);
|
keep = (element.getAttribute('r') != 0);
|
||||||
break;
|
break;
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
keep = (element.getAttribute('rx') != 0 ||
|
keep = (element.getAttribute('rx') != 0 ||
|
||||||
element.getAttribute('ry') != 0);
|
element.getAttribute('ry') != 0);
|
||||||
break;
|
break;
|
||||||
case "fhellipse":
|
case "fhellipse":
|
||||||
if ((freehand_max_x - freehand_min_x) > 0 &&
|
if ((freehand_max_x - freehand_min_x) > 0 &&
|
||||||
@@ -439,7 +434,7 @@ function SvgCanvas(c)
|
|||||||
|
|
||||||
this.save = function() {
|
this.save = function() {
|
||||||
// remove the selected outline before serializing
|
// remove the selected outline before serializing
|
||||||
this.selectElement(null);
|
this.selectNone();
|
||||||
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
var str = "<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
||||||
str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
str += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||||
str += svgToString(svgroot, 0);
|
str += svgToString(svgroot, 0);
|
||||||
@@ -450,7 +445,7 @@ function SvgCanvas(c)
|
|||||||
var nodes = svgroot.childNodes;
|
var nodes = svgroot.childNodes;
|
||||||
var len = svgroot.childNodes.length;
|
var len = svgroot.childNodes.length;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
this.setSelected(null);
|
this.selectNone();
|
||||||
for(var rep = 0; rep < len; rep++){
|
for(var rep = 0; rep < len; rep++){
|
||||||
if (nodes[i].nodeType == 1) { // element node
|
if (nodes[i].nodeType == 1) { // element node
|
||||||
nodes[i].parentNode.removeChild(nodes[i]);
|
nodes[i].parentNode.removeChild(nodes[i]);
|
||||||
@@ -522,6 +517,10 @@ function SvgCanvas(c)
|
|||||||
|
|
||||||
this.setOpacity = function(val) {
|
this.setOpacity = function(val) {
|
||||||
current_opacity = val;
|
current_opacity = val;
|
||||||
|
if (selected != null) {
|
||||||
|
selected.setAttribute("opacity", val);
|
||||||
|
call("changed", selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getFillOpacity = function() {
|
this.getFillOpacity = function() {
|
||||||
@@ -559,7 +558,7 @@ function SvgCanvas(c)
|
|||||||
this.saveHandler = function(svg) {
|
this.saveHandler = function(svg) {
|
||||||
alert(svg);
|
alert(svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectNone = function() {
|
this.selectNone = function() {
|
||||||
selectElement(null);
|
selectElement(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
||||||
<svg xml:space="preserve" id="svg_image" onload="svgCanvasInit(evt)" width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<script xlink:href="svgcanvas.js" type="text/ecmascript"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 392 B |
Reference in New Issue
Block a user