-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (66 loc) · 1.97 KB
/
index.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
63
64
65
66
67
68
69
70
/*
* INTER-Mediator
* Copyright (c) INTER-Mediator Directive Committee (http://inter-mediator.org)
* This project started at the end of 2009 by Masayuki Nii msyk@msyk.net.
*
* INTER-Mediator is supplied under MIT License.
* Please see the full license for details:
* https://github.com/INTER-Mediator/INTER-Mediator/blob/master/dist-docs/License.txt
*/
IMParts_Catalog['codemirror'] = {
instantiate: function (parentNode) {
let newId = parentNode.getAttribute('id') + '-cm'
let newNode = document.createElement('TEXTAREA')
newNode.setAttribute('id', newId)
newNode.setAttribute('class', '_im_codemirror')
parentNode.appendChild(newNode)
this.ids.push(newId)
parentNode._im_getComponentId = (function () {
let theId = newId
return function () {
return theId
}
})()
parentNode._im_setValue = (function () {
let theId = newId
let self = IMParts_Catalog['codemirror']
return function (str) {
self.initialValues[theId] = str
}
})()
},
ids: [],
initialValues: {},
mode: 'htmlmixed',
finish: function () {
let targetId, targetNode, editor, i
let self = IMParts_Catalog['codemirror']
for (i = 0; i < self.ids.length; i++) {
targetId = self.ids[i]
targetNode = document.getElementById(targetId)
if (targetNode) {
editor = CodeMirror.fromTextArea(targetNode, {
mode: self.mode,
autoRefresh: true,
lineNumbers: true,
indentUnit: 4
})
editor.setValue(self.initialValues[targetId])
editor.on('change', function () {
let nodeId = targetId
return function (instance, obj) {
IMLibUI.valueChange(nodeId)
}
}())
targetNode._im_getValue = function () {
let insideEditor = editor
return function () {
return insideEditor.getValue()
}
}()
}
}
this.ids = []
this.initialValues = {}
}
}