Skip to content

Commit

Permalink
[Refactor] remove outdated ajax method, update the example data in di…
Browse files Browse the repository at this point in the history
…fferent formats (#558)

* remove outdated ajax method, update the default data in different formats

* format
  • Loading branch information
hizzgdev authored Jan 2, 2024
1 parent 5767531 commit 4eee75f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 75 deletions.
34 changes: 10 additions & 24 deletions src/jsmind.format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import { Mind } from './jsmind.mind.js';
import { Node } from './jsmind.node.js';
import { util } from './jsmind.util.js';

const DEFAULT_META = { name: 'jsMind', author: __author__, version: __version__ };

export const format = {
node_tree: {
example: {
meta: {
name: 'jsMind node_tree simple',
author: __author__,
version: __version__,
},
meta: DEFAULT_META,
format: 'node_tree',
data: { id: 'root', topic: 'jsMind Example' },
data: { id: 'root', topic: 'jsMind node_tree example' },
},
get_mind: function (source) {
var df = format.node_tree;
Expand Down Expand Up @@ -128,13 +126,9 @@ export const format = {

node_array: {
example: {
meta: {
name: 'jsMind node_array simple',
author: __author__,
version: __version__,
},
meta: DEFAULT_META,
format: 'node_array',
data: [{ id: 'root', topic: 'jsMind Example', isroot: true }],
data: [{ id: 'root', topic: 'jsMind node_array example', isroot: true }],
},

get_mind: function (source) {
Expand Down Expand Up @@ -283,13 +277,9 @@ export const format = {

freemind: {
example: {
meta: {
name: 'jsMind freemind example',
author: __author__,
version: __version__,
},
meta: DEFAULT_META,
format: 'freemind',
data: '<map version="1.0.1"><node ID="root" TEXT="freemind Example"/></map>',
data: '<map version="1.0.1"><node ID="root" TEXT="jsMind freemind example"/></map>',
},
get_mind: function (source) {
var df = format.freemind;
Expand Down Expand Up @@ -457,13 +447,9 @@ export const format = {
},
text: {
example: {
meta: {
name: 'jsMind text example',
author: __author__,
version: __version__,
},
meta: DEFAULT_META,
format: 'text',
data: 'Text Example\n node1\n node1-sub\n node1-sub\n node2',
data: 'jsMind text example\n node1\n node1-sub\n node1-sub\n node2',
},
_line_regex: /\s*/,
get_mind: function (source) {
Expand Down
51 changes: 0 additions & 51 deletions src/jsmind.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,8 @@
*/

import { $ } from './jsmind.dom.js';
import { logger } from './jsmind.common.js';

export const util = {
ajax: {
request: function (url, param, method, callback, fail_callback) {
var p = Object.keys(param)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(param[k]))
.join('&');
var xhr = new XMLHttpRequest();
if (!xhr) {
return;
}
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 0) {
if (typeof callback === 'function') {
var data = util.json.string2json(xhr.responseText);
if (data != null) {
callback(data);
} else {
callback(xhr.responseText);
}
}
} else {
if (typeof fail_callback === 'function') {
fail_callback(xhr);
} else {
logger.error('xhr request failed.', xhr);
}
}
}
};
method = method || 'GET';
xhr.open(method, url, true);
xhr.setRequestHeader('If-Modified-Since', '0');
if (method == 'POST') {
xhr.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded;charset=utf-8'
);
xhr.send(p);
} else {
xhr.send();
}
},
get: function (url, callback) {
return util.ajax.request(url, {}, 'GET', callback);
},
post: function (url, param, callback) {
return util.ajax.request(url, param, 'POST', callback);
},
},

file: {
read: function (file_data, fn_callback) {
var reader = new FileReader();
Expand Down

0 comments on commit 4eee75f

Please sign in to comment.