Skip to content

Commit

Permalink
source code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ACTom committed Oct 12, 2020
1 parent a681933 commit 60f7963
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions js/mindmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ var FilesMindMap = {
var self = this;
if (!Array.isArray(objs)) {
objs = [objs];
};
}
objs.forEach(function(obj){
self._extensions.push(obj);
});
},

getExtensionByMime: function(mime) {
for (i = 0; i < this._extensions.length; i++) {
for (var i = 0; i < this._extensions.length; i++) {
var obj = this._extensions[i];
if (obj.mimes.indexOf(mime) >= 0) {
return obj;
Expand Down Expand Up @@ -159,9 +159,9 @@ var FilesMindMap = {
return;
}

plugin.encode(data).then(function(data) {
plugin.encode(data).then(function(data2) {
var putObject = {
filecontents: data,
filecontents: data2,
path: path
};

Expand Down Expand Up @@ -296,6 +296,7 @@ var FilesMindMap = {
if (context.dir === '/') {
fullName = '/' + fileName;
}
this._file.fullName = fullName;
this.show();
},

Expand Down Expand Up @@ -468,9 +469,9 @@ FilesMindMap.Extensions.XMind = {
if (tmp.length && tmp.length > 0) { //多个子节点
obj.children = [];

for (var i in tmp) {
for (var ii in tmp) {
obj.children.push({});
this.processTopic(tmp[i], obj.children[i]);
this.processTopic(tmp[ii], obj.children[ii]);
}

} else { //一个子节点
Expand All @@ -495,7 +496,7 @@ FilesMindMap.Extensions.XMind = {
if (contentFile != null) {
contentFile.async('text').then(function(text){
try {
json = self.toKm(text);
var json = self.toKm(text);
resolve(json);
} catch (e) {
reject(e);
Expand Down Expand Up @@ -544,8 +545,6 @@ FilesMindMap.Util = {
if (!node) return null;
var self = this;
var txt = '', obj = null, att = null;
var nt = node.nodeType, nn = this.jsVar(node.localName || node.nodeName);
var nv = node.text || node.nodeValue || '';

if (node.childNodes) {
if (node.childNodes.length > 0) {
Expand All @@ -561,7 +560,7 @@ FilesMindMap.Util = {
else if (cnt == 3 || cnt == 4 || !cnn) {
if (cnv.match(/^\s+$/)) {
return;
};
}
txt += cnv.replace(/^\s+/, '').replace(/\s+$/, '');
} else {
obj = obj || {};
Expand All @@ -574,11 +573,11 @@ FilesMindMap.Util = {
obj[cnn].push(self.parseNode(cn, true));
} else {
obj[cnn] = self.parseNode(cn);
};
};
}
}
});
};
};
}
}
if (node.attributes && node.tagName !='title') {
if (node.attributes.length > 0) {
att = {}; obj = obj || {};
Expand All @@ -588,27 +587,25 @@ FilesMindMap.Util = {
att[atn] = atv;
if (obj[atn]) {
obj[cnn] = this.toArray(obj[cnn]);

obj[atn][obj[atn].length] = atv;
obj[atn].length = obj[atn].length;
}
else {
obj[atn] = atv;
};
}
});
};
};
}
}
if (obj) {
obj = Object.assign({}, (txt != '' ? new String(txt) : {}), obj || {});
txt = (obj.text) ? ([obj.text || '']).concat([txt]) : txt;
if (txt) obj.text = txt;
txt = '';
};
}
var out = obj || txt;
return out;
},
parseXML: function (xml) {
root = (xml.nodeType == 9) ? xml.documentElement : xml;
var root = (xml.nodeType == 9) ? xml.documentElement : xml;
return this.parseNode(root, true);
},
xml2json: function (str) {
Expand Down

0 comments on commit 60f7963

Please sign in to comment.