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
This commit is contained in:
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 * Copyright(c) 2009 Narendra Sisodya
* *
*/ */
var put_locale = function(svgCanvas, given_param){ var put_locale = function(svgCanvas, given_param, good_langs){
var lang_param; 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) { if(given_param) {
lang_param = given_param; lang_param = given_param;
} else { } else {
@@ -28,7 +27,7 @@ var put_locale = function(svgCanvas, given_param){
if($.inArray(lang_param, good_langs) == -1) { if($.inArray(lang_param, good_langs) == -1) {
lang_param = "en"; lang_param = "en";
} }
// don't bother on first run if language is English // don't bother on first run if language is English
if(lang_param.indexOf("en") == 0) return; if(lang_param.indexOf("en") == 0) return;
} }

View File

@@ -2907,7 +2907,11 @@ function svg_edit_setup() {
// This happens when the page is loaded // This happens when the page is loaded
$(function() { $(function() {
svgCanvas = svg_edit_setup(); 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{ try{
json_encode = function(obj){ 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 // TODO: declare the variables and set them as null, then move this setup stuff to
// an initialization function - probably just use clear() // an initialization function - probably just use clear()
var canvas = this, var canvas = this,
svgns = "http://www.w3.org/2000/svg", svgns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink", xlinkns = "http://www.w3.org/1999/xlink",
@@ -937,6 +938,13 @@ function BatchCommand(text) {
'</svg>').documentElement, true); '</svg>').documentElement, true);
$(svgroot).appendTo(container); $(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"); var svgcontent = svgdoc.createElementNS(svgns, "svg");
$(svgcontent).attr({ $(svgcontent).attr({
@@ -1476,6 +1484,7 @@ function BatchCommand(text) {
var svgToString = function(elem, indent) { var svgToString = function(elem, indent) {
var out = new Array(); var out = new Array();
if (elem) { if (elem) {
cleanupElement(elem); cleanupElement(elem);
var attrs = elem.attributes, var attrs = elem.attributes,
@@ -1486,15 +1495,24 @@ function BatchCommand(text) {
for (var i=0; i<indent; i++) out.push(" "); for (var i=0; i<indent; i++) out.push(" ");
out.push("<"); out.push(elem.nodeName); out.push("<"); out.push(elem.nodeName);
if(elem.id == 'svgcontent') { if(elem.id == 'svgcontent') {
// Process root element separately; Prevents errors caused // Process root element separately
// in webkit when removing attributes
var res = canvas.getResolution(); var res = canvas.getResolution();
out.push(' width="' + res.w + '" height="' + res.h out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
+ '" xmlns:xlink="'+xlinkns+'" xmlns="'+svgns+'"');
if(svgcontent.getAttribute("xmlns:se")) { var nsuris = {};
// TODO: Check if any se: attributes are actually used
out.push(' xmlns:se="'+se_ns+'"'); // 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 { } else {
for (var i=attrs.length-1; i>=0; i--) { for (var i=attrs.length-1; i>=0; i--) {
attr = attrs.item(i); attr = attrs.item(i);
@@ -1520,19 +1538,10 @@ function BatchCommand(text) {
} }
// map various namespaces to our fixed namespace prefixes // 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) {
if (attr.namespaceURI == xlinkns) { out.push(nsMap[attr.namespaceURI]+':');
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:');
} }
out.push(attr.localName); out.push("=\""); out.push(attr.localName); out.push("=\"");
out.push(attrVal); out.push("\""); out.push(attrVal); out.push("\"");
} }