Commit 8b8b65c9 authored by techird's avatar techird

fix download bug in chrome 35.0.1916.114

parent 60272950
...@@ -35,6 +35,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -35,6 +35,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
var a = document.createElement( 'a' ); var a = document.createElement( 'a' );
a.setAttribute( 'download', filename ); a.setAttribute( 'download', filename );
a.setAttribute( 'href', url ); a.setAttribute( 'href', url );
document.body.appendChild(a);
var evt; var evt;
try { try {
evt = new MouseEvent( 'click' ); evt = new MouseEvent( 'click' );
...@@ -43,6 +44,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -43,6 +44,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
evt.initEvent( 'click', true, true ); evt.initEvent( 'click', true, true );
} }
a.dispatchEvent( evt ); a.dispatchEvent( evt );
document.body.removeChild(a);
} }
var ie_ver = function () { var ie_ver = function () {
...@@ -63,14 +65,14 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -63,14 +65,14 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
iframe.contentDocument.writeln( d ); iframe.contentDocument.writeln( d );
iframe.contentDocument.execCommand( 'saveas', '', filename ); iframe.contentDocument.execCommand( 'saveas', '', filename );
}; };
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
var data = me.exportData( res.value ); var data = me.exportData( res.value );
var p = KityMinder.findProtocal( res.value ); var p = KityMinder.findProtocal( res.value );
var filename = me.getMinderTitle() + p.fileExtension; var filename = me.getMinderTitle() + p.fileExtension;
if ( typeof ( data ) == 'string' ) { if ( typeof ( data ) == 'string' ) {
var url = 'data:text/plain; utf-8,' + encodeURIComponent( data ); var url = 'data:' + (p.mineType || 'text/plain') + '; utf-8,' + encodeURIComponent( data );
if ( ie_ver() > 0 ) { if ( ie_ver() > 0 ) {
//console.log( p.fileExtension );
if ( p.fileExtension === '.km' ) { if ( p.fileExtension === '.km' ) {
doSave( 'application/x-javascript', data, me.getMinderTitle() ); doSave( 'application/x-javascript', data, me.getMinderTitle() );
} else if ( p.fileExtension === '.svg' ) { } else if ( p.fileExtension === '.svg' ) {
......
...@@ -8,6 +8,7 @@ KityMinder.registerProtocal( 'json', function () { ...@@ -8,6 +8,7 @@ KityMinder.registerProtocal( 'json', function () {
return { return {
fileDescription: 'KityMinder', fileDescription: 'KityMinder',
fileExtension: '.km', fileExtension: '.km',
mineType: 'application/json',
encode: function ( json ) { encode: function ( json ) {
return JSON.stringify( json, filter ); return JSON.stringify( json, filter );
}, },
......
...@@ -87,6 +87,7 @@ KityMinder.registerProtocal( "plain", function () { ...@@ -87,6 +87,7 @@ KityMinder.registerProtocal( "plain", function () {
return { return {
fileDescription: '大纲文本', fileDescription: '大纲文本',
fileExtension: '.txt', fileExtension: '.txt',
mineType: 'text/plain',
encode: function ( json ) { encode: function ( json ) {
return encode( json, 0 ); return encode( json, 0 );
}, },
......
...@@ -72,7 +72,7 @@ KityMinder.registerProtocal( "png", function () { ...@@ -72,7 +72,7 @@ KityMinder.registerProtocal( "png", function () {
function generateDataUrl( canvas ) { function generateDataUrl( canvas ) {
var url = canvas.toDataURL( 'png' ); var url = canvas.toDataURL( 'png' );
return url.replace( 'image/png', 'image/octet-stream' ); return url;
} }
loadImage( url, function () { loadImage( url, function () {
var svgImage = this; var svgImage = this;
......
...@@ -2,6 +2,7 @@ KityMinder.registerProtocal( "svg", function () { ...@@ -2,6 +2,7 @@ KityMinder.registerProtocal( "svg", function () {
return { return {
fileDescription: 'SVG 矢量图(暂不支持IE)', fileDescription: 'SVG 矢量图(暂不支持IE)',
fileExtension: '.svg', fileExtension: '.svg',
mineType: 'image/svg+xml',
encode: function ( json, km ) { encode: function ( json, km ) {
// svg 含有   符号导出报错 Entity 'nbsp' not defined // svg 含有   符号导出报错 Entity 'nbsp' not defined
return km.getPaper().container.innerHTML.replace( / /g, ' ' ); return km.getPaper().container.innerHTML.replace( / /g, ' ' );
......
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