Made 'good' locale array be populated based on svg-editor.html, made namespaces only be added on serialization when used

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1377 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-11 21:24:15 +00:00
parent 507e50767f
commit eb8b9ab5e6
3 changed files with 37 additions and 25 deletions

View File

@ -6,10 +6,9 @@
* Copyright(c) 2009 Narendra Sisodya
*
*/
var put_locale = function(svgCanvas, given_param){
var put_locale = function(svgCanvas, given_param, good_langs){
var lang_param;
// TODO: Make this array be based on entries in svg-editor.html
var good_langs = ['ar','cs','de','en','es','fa','fr','fy','hi','ja','nl','ro','ru','sk','zh-TW'];
if(given_param) {
lang_param = given_param;
} else {

View File

@ -2907,7 +2907,11 @@ function svg_edit_setup() {
// This happens when the page is loaded
$(function() {
svgCanvas = svg_edit_setup();
put_locale(svgCanvas);
var good_langs = [];
$('#lang_select option').each(function() {
good_langs.push(this.value);
});
put_locale(svgCanvas, null, good_langs);
try{
json_encode = function(obj){

View File

@ -913,6 +913,7 @@ function BatchCommand(text) {
// TODO: declare the variables and set them as null, then move this setup stuff to
// an initialization function - probably just use clear()
var canvas = this,
svgns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink",
@ -938,6 +939,13 @@ function BatchCommand(text) {
$(svgroot).appendTo(container);
var nsMap = {};
nsMap[xlinkns] = 'xlink';
nsMap[xmlns] = 'xmlns';
nsMap[se_ns] = 'se';
nsMap[htmlns] = 'xhtml';
nsMap[mathns] = 'mathml';
var svgcontent = svgdoc.createElementNS(svgns, "svg");
$(svgcontent).attr({
id: 'svgcontent',
@ -1476,6 +1484,7 @@ function BatchCommand(text) {
var svgToString = function(elem, indent) {
var out = new Array();
if (elem) {
cleanupElement(elem);
var attrs = elem.attributes,
@ -1486,15 +1495,24 @@ function BatchCommand(text) {
for (var i=0; i<indent; i++) out.push(" ");
out.push("<"); out.push(elem.nodeName);
if(elem.id == 'svgcontent') {
// Process root element separately; Prevents errors caused
// in webkit when removing attributes
// Process root element separately
var res = canvas.getResolution();
out.push(' width="' + res.w + '" height="' + res.h
+ '" xmlns:xlink="'+xlinkns+'" xmlns="'+svgns+'"');
if(svgcontent.getAttribute("xmlns:se")) {
// TODO: Check if any se: attributes are actually used
out.push(' xmlns:se="'+se_ns+'"');
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
var nsuris = {};
// Check elements for namespaces, add if found
$(elem).find('*').each(function() {
var el = this;
$.each(this.attributes, function(i, attr) {
var uri = attr.namespaceURI;
if(uri && !nsuris[uri]) {
nsuris[uri] = true;
out.push(" xmlns:" + nsMap[uri] + '="' + uri +'"');
}
});
});
} else {
for (var i=attrs.length-1; i>=0; i--) {
attr = attrs.item(i);
@ -1520,19 +1538,10 @@ function BatchCommand(text) {
}
// map various namespaces to our fixed namespace prefixes
// TODO: put this into a map and do a look-up instead of if-else
if (attr.namespaceURI == xlinkns) {
out.push('xlink:');
}
else if(attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' && attr.localName != 'xmlns') {
out.push('xmlns:');
}
else if(attr.namespaceURI == xmlns) {
out.push('xml:');
}
else if(attr.namespaceURI == se_ns) {
out.push('se:');
if(attr.namespaceURI) {
out.push(nsMap[attr.namespaceURI]+':');
}
out.push(attr.localName); out.push("=\"");
out.push(attrVal); out.push("\"");
}