Commit 4d023087 authored by techird's avatar techird

添加GBK导入的选项

parent ad8d2e16
...@@ -124,16 +124,24 @@ $(function() { ...@@ -124,16 +124,24 @@ $(function() {
acceptFiles.push(p.fileExtension); acceptFiles.push(p.fileExtension);
} }
}); });
menus = menus.concat([{
label: '导入本地文件', function importUseEncoding(encoding) {
click: function() { return function() {
$('<input type="file" />') $('<input type="file" />')
.attr('accept', acceptFiles.join(',')) .attr('accept', acceptFiles.join(','))
.on('change', function(e) { .on('change', function(e) {
e = e.originalEvent; e = e.originalEvent;
minder.importFile(e.target.files[0]); minder.importFile(e.target.files[0], encoding);
}).click(); }).click();
};
} }
menus = menus.concat([{
label: '导入...',
click: importUseEncoding('utf8')
}, {
label: '以 GBK 编码导入...',
click: importUseEncoding('gbk')
}, { }, {
divider: true divider: true
}]); }]);
......
...@@ -34,7 +34,7 @@ KityMinder.registerModule('DropFile', function() { ...@@ -34,7 +34,7 @@ KityMinder.registerModule('DropFile', function() {
} }
} }
function importMinderFile(minder, file) { function importMinderFile(minder, file, encoding) {
if (!file) return; if (!file) return;
var ext = /(.)\w+$/.exec(file.name); var ext = /(.)\w+$/.exec(file.name);
...@@ -48,11 +48,11 @@ KityMinder.registerModule('DropFile', function() { ...@@ -48,11 +48,11 @@ KityMinder.registerModule('DropFile', function() {
} else if ((/mmap/g).test(ext)) { // mindmanager zip } else if ((/mmap/g).test(ext)) { // mindmanager zip
importSync(minder, file, 'mindmanager'); importSync(minder, file, 'mindmanager');
} else if ((/mm/g).test(ext)) { //freemind xml } else if ((/mm/g).test(ext)) { //freemind xml
importAsync(minder, file, 'freemind'); importAsync(minder, file, 'freemind', encoding);
} else if (/km/.test(ext)) { // txt json } else if (/km/.test(ext)) { // txt json
importAsync(minder, file, 'json'); importAsync(minder, file, 'json', encoding);
} else if (/txt/.test(ext)) { } else if (/txt/.test(ext)) {
importAsync(minder, file, 'plain'); importAsync(minder, file, 'plain', encoding);
} else { } else {
alert('不支持导入此类文件!'); alert('不支持导入此类文件!');
} }
...@@ -78,12 +78,12 @@ KityMinder.registerModule('DropFile', function() { ...@@ -78,12 +78,12 @@ KityMinder.registerModule('DropFile', function() {
} }
// 异步加载文件 // 异步加载文件
function importAsync(minder, file, protocal) { function importAsync(minder, file, protocal, encoding) {
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function(e) { reader.onload = function (e) {
importSync(minder, e.target.result, protocal); importSync(minder, e.target.result, protocal);
}; };
reader.readAsText(file); reader.readAsText(file, encoding || 'utf8');
} }
function createDraft(minder) { function createDraft(minder) {
...@@ -92,8 +92,8 @@ KityMinder.registerModule('DropFile', function() { ...@@ -92,8 +92,8 @@ KityMinder.registerModule('DropFile', function() {
} }
kity.extendClass(Minder, { kity.extendClass(Minder, {
importFile: function(file) { importFile: function(file, encoding) {
importMinderFile(this, file); importMinderFile(this, file, encoding);
return this; return this;
} }
}); });
......
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