Hopefully finally fixed gradient serialization issues in Opera/Win/Non-en

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@945 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-11-13 20:45:18 +00:00
parent d4fcca35ae
commit 0278caccd8
3 changed files with 33 additions and 10 deletions

View File

@ -49,6 +49,22 @@ if(!window.console) {
this.dir = function(str) {}; this.dir = function(str) {};
}; };
} }
$.cloneNode = function(el) {
if(!window.opera) return el.cloneNode(true);
// manually create a copy of the element
opera.postError(ns.svg, el.nodeName);
var new_el = document.createElementNS(ns.svg, el.nodeName);
$.each(el.attributes, function(i, attr) {
new_el.setAttributeNS(ns.svg, attr.nodeName, attr.nodeValue);
});
$.each(el.childNodes, function(i, child) {
if(child.nodeType == 1) {
new_el.appendChild($.cloneNode(child));
}
});
return new_el;
}
$.jGraduate = { $.jGraduate = {
Paint: Paint:
function(opt) { function(opt) {
@ -69,7 +85,7 @@ $.jGraduate = {
break; break;
case "linearGradient": case "linearGradient":
this.solidColor = null; this.solidColor = null;
this.linearGradient = options.copy.linearGradient.cloneNode(true); this.linearGradient = $.cloneNode(options.copy.linearGradient);
break; break;
} }
} }
@ -77,7 +93,7 @@ $.jGraduate = {
else if (options.linearGradient) { else if (options.linearGradient) {
this.type = "linearGradient"; this.type = "linearGradient";
this.solidColor = null; this.solidColor = null;
this.linearGradient = options.linearGradient.cloneNode(true); this.linearGradient = $.cloneNode(options.linearGradient);
} }
// create solid color paint // create solid color paint
else if (options.solidColor) { else if (options.solidColor) {
@ -209,7 +225,8 @@ jQuery.fn.jGraduate =
// if we are sent a gradient, import it // if we are sent a gradient, import it
if ($this.paint.type == "linearGradient") { if ($this.paint.type == "linearGradient") {
$this.paint.linearGradient.id = id+'_jgraduate_grad'; $this.paint.linearGradient.id = id+'_jgraduate_grad';
$this.paint.linearGradient = svg.appendChild(document.importNode($this.paint.linearGradient, true)); // $this.paint.linearGradient = svg.appendChild(document.importNode($this.paint.linearGradient, true));
$this.paint.linearGradient = svg.appendChild($.cloneNode($this.paint.linearGradient));
} }
else { // we create a gradient else { // we create a gradient
var grad = svg.appendChild(document.createElementNS(ns.svg, 'linearGradient')); var grad = svg.appendChild(document.createElementNS(ns.svg, 'linearGradient'));

View File

@ -229,7 +229,6 @@ function svg_edit_setup() {
var getPaint = function(color, opac) { var getPaint = function(color, opac) {
// update the editor's fill paint // update the editor's fill paint
var opts = null; var opts = null;
if (color.substr(0,5) == "url(#") { if (color.substr(0,5) == "url(#") {
opts = { opts = {
alpha: opac, alpha: opac,
@ -825,6 +824,7 @@ function svg_edit_setup() {
var clickClear = function(){ var clickClear = function(){
if( confirm(uiStrings.QwantToClear) ) { if( confirm(uiStrings.QwantToClear) ) {
svgCanvas.clear(); svgCanvas.clear();
populateLayers();
updateContextPanel(); updateContextPanel();
} }
}; };
@ -1413,6 +1413,7 @@ function svg_edit_setup() {
if (paint.type == "linearGradient") { if (paint.type == "linearGradient") {
svgbox.removeChild(oldgrad); svgbox.removeChild(oldgrad);
var newgrad = svgbox.appendChild(document.importNode(paint.linearGradient, true)); var newgrad = svgbox.appendChild(document.importNode(paint.linearGradient, true));
svgCanvas.fixOperaXML(newgrad, paint.linearGradient)
newgrad.id = "gradbox_"+picker; newgrad.id = "gradbox_"+picker;
rectbox.setAttribute("fill", "url(#gradbox_" + picker + ")"); rectbox.setAttribute("fill", "url(#gradbox_" + picker + ")");
} }

View File

@ -982,7 +982,6 @@ function BatchCommand(text) {
node.nodeValue = node.nodeValue.replace(/^\s+|\s+$/g, ""); node.nodeValue = node.nodeValue.replace(/^\s+|\s+$/g, "");
} }
if (node.nodeType != 1) return; if (node.nodeType != 1) return;
var doc = node.ownerDocument; var doc = node.ownerDocument;
var parent = node.parentNode; var parent = node.parentNode;
// can parent ever be null here? I think the root node's parent is the document... // can parent ever be null here? I think the root node's parent is the document...
@ -1054,7 +1053,7 @@ function BatchCommand(text) {
var i = lgrads.length; var i = lgrads.length;
while (i--) { while (i--) {
var grad = lgrads[i]; var grad = lgrads[i];
var id = grad.getAttribute('id'); var id = grad.id;
var url_id = 'url(#' + id + ')'; var url_id = 'url(#' + id + ')';
if($.inArray(url_id, grad_uses) == -1) { if($.inArray(url_id, grad_uses) == -1) {
// Not found, so remove // Not found, so remove
@ -1166,7 +1165,7 @@ function BatchCommand(text) {
// importNode, like cloneNode, causes the comma-to-period // importNode, like cloneNode, causes the comma-to-period
// issue in Opera/Win/non-en. Thankfully we can compare to the original XML // issue in Opera/Win/non-en. Thankfully we can compare to the original XML
// and simply use the original value when necessary // and simply use the original value when necessary
var fixOperaXML = function(elem, orig_el) { this.fixOperaXML = function(elem, orig_el) {
var x_attrs = elem.attributes; var x_attrs = elem.attributes;
$.each(x_attrs, function(i, attr) { $.each(x_attrs, function(i, attr) {
if(attr.nodeValue.indexOf(',') == -1) return; if(attr.nodeValue.indexOf(',') == -1) return;
@ -1174,14 +1173,18 @@ function BatchCommand(text) {
var ns = attr.nodeName == 'href' ? xlinkns : var ns = attr.nodeName == 'href' ? xlinkns :
attr.prefix == "xml" ? xmlns : null; attr.prefix == "xml" ? xmlns : null;
var good_attrval = orig_el.getAttribute(attr.nodeName); var good_attrval = orig_el.getAttribute(attr.nodeName);
if(ns) {
elem.setAttributeNS(ns, attr.nodeName, good_attrval); elem.setAttributeNS(ns, attr.nodeName, good_attrval);
} else {
elem.setAttribute(attr.nodeName, good_attrval);
}
}); });
var childs = elem.childNodes; var childs = elem.childNodes;
var o_childs = orig_el.childNodes; var o_childs = orig_el.childNodes;
$.each(childs, function(i, child) { $.each(childs, function(i, child) {
if(child.nodeType == 1) { if(child.nodeType == 1) {
fixOperaXML(child, o_childs[i]); canvas.fixOperaXML(child, o_childs[i]);
} }
}); });
} }
@ -3881,7 +3884,7 @@ function BatchCommand(text) {
// Fix XML for Opera/Win/Non-EN // Fix XML for Opera/Win/Non-EN
if(window.opera) { if(window.opera) {
fixOperaXML(svgcontent, newDoc.documentElement); canvas.fixOperaXML(svgcontent, newDoc.documentElement);
} }
svgcontent.setAttribute('id', 'svgcontent'); svgcontent.setAttribute('id', 'svgcontent');
@ -4685,7 +4688,9 @@ function BatchCommand(text) {
var defs = findDefs(); var defs = findDefs();
// no duplicate found, so import gradient into defs // no duplicate found, so import gradient into defs
if (!duplicate_grad) { if (!duplicate_grad) {
var orig_grad = grad;
grad = defs.appendChild( svgdoc.importNode(grad, true) ); grad = defs.appendChild( svgdoc.importNode(grad, true) );
canvas.fixOperaXML(grad, orig_grad);
// get next id and set it on the grad // get next id and set it on the grad
grad.id = getNextId(); grad.id = getNextId();
} }