compatibility.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define(function(require, exports, module) {
  2. var utils = require('./utils');
  3. function compatibility(json) {
  4. var version = json.version || (json.root ? '1.4.0' : '1.1.3');
  5. switch (version) {
  6. case '1.1.3':
  7. c_113_120(json);
  8. /* falls through */
  9. case '1.2.0':
  10. case '1.2.1':
  11. c_120_130(json);
  12. /* falls through */
  13. case '1.3.0':
  14. case '1.3.1':
  15. case '1.3.2':
  16. case '1.3.3':
  17. case '1.3.4':
  18. case '1.3.5':
  19. /* falls through */
  20. c_130_140(json);
  21. }
  22. return json;
  23. }
  24. function traverse(node, fn) {
  25. fn(node);
  26. if (node.children) node.children.forEach(function(child) {
  27. traverse(child, fn);
  28. });
  29. }
  30. /* 脑图数据升级 */
  31. function c_120_130(json) {
  32. traverse(json, function(node) {
  33. var data = node.data;
  34. delete data.layout_bottom_offset;
  35. delete data.layout_default_offset;
  36. delete data.layout_filetree_offset;
  37. });
  38. }
  39. /**
  40. * 脑图数据升级
  41. * v1.1.3 => v1.2.0
  42. * */
  43. function c_113_120(json) {
  44. // 原本的布局风格
  45. var ocs = json.data.currentstyle;
  46. delete json.data.currentstyle;
  47. // 为 1.2 选择模板,同时保留老版本文件的皮肤
  48. if (ocs == 'bottom') {
  49. json.template = 'structure';
  50. json.theme = 'snow';
  51. } else if (ocs == 'default') {
  52. json.template = 'default';
  53. json.theme = 'classic';
  54. }
  55. traverse(json, function(node) {
  56. var data = node.data;
  57. // 升级优先级、进度图标
  58. if ('PriorityIcon' in data) {
  59. data.priority = data.PriorityIcon;
  60. delete data.PriorityIcon;
  61. }
  62. if ('ProgressIcon' in data) {
  63. data.progress = 1 + ((data.ProgressIcon - 1) << 1);
  64. delete data.ProgressIcon;
  65. }
  66. // 删除过时属性
  67. delete data.point;
  68. delete data.layout;
  69. });
  70. }
  71. function c_130_140(json) {
  72. json.root = {
  73. data: json.data,
  74. children: json.children
  75. };
  76. delete json.data;
  77. delete json.children;
  78. }
  79. return compatibility;
  80. });