Commit c6f94031 authored by Akikonata's avatar Akikonata

fixed svg download bug

parent bebae1e6
The MIT License (MIT)
Copyright (c) 2014, FEX,Baidu.
All rights reserved.
Copyright (c) 2013 KityMinder
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
......@@ -39,12 +39,11 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
var data = me.exportData( res.value );
console.log( data );
var p = KityMinder.findProtocal( res.value );
var filename = me.getMinderTitle() + p.fileExtension;
if ( p.fileExtension === '' ) {
} else if ( typeof ( data ) == 'string' ) {
var url = 'data:text/plain; utf-8,' + encodeURI( data );
if ( typeof ( data ) == 'string' ) {
var url = 'data:text/plain; utf-8,' + encodeURIComponent( data );
doDownload( url, filename );
} else if ( data && data.then ) {
data.then( function ( url ) {
......
......@@ -10,97 +10,96 @@ KityMinder.registerProtocal( 'mindmanager', function () {
// 标签 map
var markerMap = {
'urn:mindjet:Prio1' : ['PriorityIcon', 1]
,'urn:mindjet:Prio2' : ['PriorityIcon', 2]
,'urn:mindjet:Prio3' : ['PriorityIcon', 3]
,'urn:mindjet:Prio4' : ['PriorityIcon', 4]
,'urn:mindjet:Prio5' : ['PriorityIcon', 5]
,'0' : ['ProgressIcon', 1]
,'25' : ['ProgressIcon', 2]
,'50' : ['ProgressIcon', 3]
,'75' : ['ProgressIcon', 4]
,'100' : ['ProgressIcon', 5]
'urn:mindjet:Prio1': [ 'PriorityIcon', 1 ],
'urn:mindjet:Prio2': [ 'PriorityIcon', 2 ],
'urn:mindjet:Prio3': [ 'PriorityIcon', 3 ],
'urn:mindjet:Prio4': [ 'PriorityIcon', 4 ],
'urn:mindjet:Prio5': [ 'PriorityIcon', 5 ],
'0': [ 'ProgressIcon', 1 ],
'25': [ 'ProgressIcon', 2 ],
'50': [ 'ProgressIcon', 3 ],
'75': [ 'ProgressIcon', 4 ],
'100': [ 'ProgressIcon', 5 ]
};
function processTopic(topic, obj){
function processTopic( topic, obj ) {
//处理文本
obj.data = { text : topic.Text && topic.Text.PlainText || '' }; // 节点默认的文本,没有Text属性
obj.data = {
text: topic.Text && topic.Text.PlainText || ''
}; // 节点默认的文本,没有Text属性
// 处理标签
if(topic.Task){
if ( topic.Task ) {
var type;
if(topic.Task.TaskPriority){
if ( topic.Task.TaskPriority ) {
type = markerMap[ topic.Task.TaskPriority ];
type && (obj.data[ type[0] ] = type[1]);
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
}
if(topic.Task.TaskPercentage){
if ( topic.Task.TaskPercentage ) {
type = markerMap[ topic.Task.TaskPercentage ];
type && (obj.data[ type[0] ] = type[1]);
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
}
}
//处理子节点
if( topic.SubTopics && topic.SubTopics.Topic ){
if ( topic.SubTopics && topic.SubTopics.Topic ) {
var tmp = topic.SubTopics.Topic;
if( tmp.length && tmp.length > 0 ){ //多个子节点
if ( tmp.length && tmp.length > 0 ) { //多个子节点
obj.children = [];
for(var i in tmp){
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
for ( var i in tmp ) {
obj.children.push( {} );
processTopic( tmp[ i ], obj.children[ i ] );
}
}else{ //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
} else { //一个子节点
obj.children = [ {} ];
processTopic( tmp, obj.children[ 0 ] );
}
}
}
function xml2km(xml){
var json = $.xml2json(xml);
function xml2km( xml ) {
var json = $.xml2json( xml );
var result = {};
processTopic(json.OneTopic.Topic, result);
processTopic( json.OneTopic.Topic, result );
return result;
}
function getEntries(file, onend) {
zip.createReader(new zip.BlobReader(file), function(zipReader) {
zipReader.getEntries(onend);
}, onerror);
function getEntries( file, onend ) {
zip.createReader( new zip.BlobReader( file ), function ( zipReader ) {
zipReader.getEntries( onend );
}, onerror );
}
return {
fileDescription: 'mindmanager格式文件',
fileExtension: '.mmap',
decode: function ( local ) {
return {
then : function(local, callback){
getEntries( local, function( entries ) {
entries.forEach(function( entry ) {
if(entry.filename == 'Document.xml'){
entry.getData(new zip.TextWriter(), function(text) {
var km = xml2km($.parseXML(text));
callback && callback( km );
});
}
});
});
}
};
},
// recognize: recognize,
recognizePriority: -1
};
} );
return {
fileDescription: 'mindmanager格式文件',
fileExtension: '.mmap',
decode: function ( local ) {
return {
then: function ( local, callback ) {
getEntries( local, function ( entries ) {
entries.forEach( function ( entry ) {
if ( entry.filename == 'Document.xml' ) {
entry.getData( new zip.TextWriter(), function ( text ) {
var km = xml2km( $.parseXML( text ) );
callback && callback( km );
} );
}
} );
} );
}
};
},
// recognize: recognize,
recognizePriority: -1
};
} );
\ No newline at end of file
......@@ -42,10 +42,10 @@ KityMinder.registerProtocal( "png", function () {
} );
// need a xml with width and height
svgXml = $( '<div></div' ).append( $svg ).html();
svgXml = $( '<div></div>' ).append( $svg ).html();
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, '&#xa0;');
svgXml = svgXml.replace( /&nbsp;/g, '&#xa0;' );
blob = new Blob( [ svgXml ], {
type: "image/svg+xml;charset=utf-8"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment