This repository has been archived by the owner on Jul 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
start.js
62 lines (57 loc) · 2.14 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*global require, document, window, console */
const MAPJS = require('mindmup-mapjs'),
jQuery = require('jquery'),
themeProvider = require('./theme'),
ThemeProcessor = require('mindmup-mapjs-layout').ThemeProcessor,
testMap = require('./example-map'),
content = require('mindmup-mapjs-model').content,
init = function () {
'use strict';
const container = jQuery('#container'),
idea = content(testMap),
imageInsertController = new MAPJS.ImageInsertController('http://localhost:4999?u='),
mapModel = new MAPJS.MapModel(MAPJS.DOMRender.layoutCalculator, []);
jQuery.fn.attachmentEditorWidget = function (mapModel) {
return this.each(function () {
mapModel.addEventListener('attachmentOpened', function (nodeId, attachment) {
mapModel.setAttachment(
'attachmentEditorWidget',
nodeId, {
contentType: 'text/html',
content: window.prompt('attachment', attachment && attachment.content)
}
);
});
});
};
window.onerror = window.alert;
jQuery('#themecss').themeCssWidget(themeProvider, new ThemeProcessor(), mapModel);
container.domMapWidget(console, mapModel, false, imageInsertController);
jQuery('body').mapToolbarWidget(mapModel);
jQuery('body').attachmentEditorWidget(mapModel);
mapModel.setIdea(idea);
jQuery('#linkEditWidget').linkEditWidget(mapModel);
window.mapModel = mapModel;
jQuery('.arrow').click(function () {
jQuery(this).toggleClass('active');
});
imageInsertController.addEventListener('imageInsertError', function (reason) {
console.log('image insert error', reason);
});
container.on('drop', function (e) {
const dataTransfer = e.originalEvent.dataTransfer;
e.stopPropagation();
e.preventDefault();
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
const fileInfo = dataTransfer.files[0];
if (/\.mup$/.test(fileInfo.name)) {
const oFReader = new window.FileReader();
oFReader.onload = function (oFREvent) {
mapModel.setIdea(content(JSON.parse(oFREvent.target.result)));
};
oFReader.readAsText(fileInfo, 'UTF-8');
}
}
});
};
document.addEventListener('DOMContentLoaded', init);