Commit 3719ebde authored by 张博's avatar 张博

add decodeData in data.js

parent 40f51378
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "kityminder-core", "name": "kityminder-core",
"title": "Kity Minder Core", "title": "Kity Minder Core",
"description": "Powerful online mind graphic visualization and editor (command based)", "description": "Powerful online mind graphic visualization and editor (command based)",
"version": "1.4.10", "version": "1.4.11",
"main": [ "main": [
"release/kityminder.core.min.js", "release/kityminder.core.min.js",
"release/kityminder.core.css" "release/kityminder.core.css"
......
/*! /*!
* ==================================================== * ====================================================
* kityminder - v1.4.1 - 2015-07-10 * kityminder - v1.4.1 - 2015-07-22
* https://github.com/fex-team/kityminder-core * https://github.com/fex-team/kityminder-core
* GitHub: https://github.com/fex-team/kityminder-core.git * GitHub: https://github.com/fex-team/kityminder-core.git
* Copyright (c) 2015 Baidu FEX; Licensed MIT * Copyright (c) 2015 Baidu FEX; Licensed MIT
...@@ -827,7 +827,7 @@ _p[11] = { ...@@ -827,7 +827,7 @@ _p[11] = {
/** /**
* @method importData() * @method importData()
* @for Minder * @for Minder
* @description 使用指定的数据协议,导出脑图数据 * @description 使用指定的数据协议,导入脑图数据,覆盖当前实例的脑图
* *
* @grammar importData(protocol, callback) => Promise<json> * @grammar importData(protocol, callback) => Promise<json>
* *
...@@ -855,6 +855,37 @@ _p[11] = { ...@@ -855,6 +855,37 @@ _p[11] = {
minder.importJson(json); minder.importJson(json);
return json; return json;
}); });
},
/**
* @method decodeData()
* @for Minder
* @description 使用指定的数据协议,解析为脑图数据,与 importData 的区别在于:不覆盖当前实例的脑图
*
* @grammar decodeData(protocol, callback) => Promise<json>
*
* @param {string} protocol 指定的用于解析数据的数据协议(默认内置三种数据协议 `json`、`text` 和 `markdown` 的支持)
* @param {any} data 要导入的数据
*/
decodeData: function(protocolName, data, option) {
var json, protocol;
var minder = this;
// 指定了协议进行导入,需要检测协议是否支持
if (protocolName) {
protocol = protocols[protocolName];
if (!protocol || !protocol.decode) {
return Promise.reject(new Error("Not supported protocol:" + protocolName));
}
}
var params = {
local: data,
protocolName: protocolName,
protocol: protocol
};
// 导入前抛事件
this._fire(new MinderEvent("beforeimport", params));
return Promise.resolve(protocol.decode(data, this, option)).then(function(json) {
return json;
});
} }
}); });
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -178,7 +178,7 @@ define(function(require, exports, module) { ...@@ -178,7 +178,7 @@ define(function(require, exports, module) {
/** /**
* @method importData() * @method importData()
* @for Minder * @for Minder
* @description 使用指定的数据协议,导出脑图数据 * @description 使用指定的数据协议,导入脑图数据,覆盖当前实例的脑图
* *
* @grammar importData(protocol, callback) => Promise<json> * @grammar importData(protocol, callback) => Promise<json>
* *
...@@ -211,6 +211,43 @@ define(function(require, exports, module) { ...@@ -211,6 +211,43 @@ define(function(require, exports, module) {
minder.importJson(json); minder.importJson(json);
return json; return json;
}); });
},
/**
* @method decodeData()
* @for Minder
* @description 使用指定的数据协议,解析为脑图数据,与 importData 的区别在于:不覆盖当前实例的脑图
*
* @grammar decodeData(protocol, callback) => Promise<json>
*
* @param {string} protocol 指定的用于解析数据的数据协议(默认内置三种数据协议 `json`、`text` 和 `markdown` 的支持)
* @param {any} data 要导入的数据
*/
decodeData: function(protocolName, data, option) {
var json, protocol;
var minder = this;
// 指定了协议进行导入,需要检测协议是否支持
if (protocolName) {
protocol = protocols[protocolName];
if (!protocol || !protocol.decode) {
return Promise.reject(new Error('Not supported protocol:' + protocolName));
}
}
var params = {
local: data,
protocolName: protocolName,
protocol: protocol
};
// 导入前抛事件
this._fire(new MinderEvent('beforeimport', params));
return Promise.resolve(protocol.decode(data, this, option)).then(function(json) {
return json;
});
} }
}); });
}); });
\ No newline at end of file
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