Commit 4d023087 authored by techird's avatar techird

添加GBK导入的选项

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