-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.js
More file actions
225 lines (210 loc) · 7.72 KB
/
edit.js
File metadata and controls
225 lines (210 loc) · 7.72 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
let editor;
let modals;
const today = () => {
let date = new Date();
return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
};
let post = {
published: today(),
title: '',
content: '',
images: []
};
let postModified = post;
// TinyMCE functions
function editorRefresh() {
let editorContent = tinymce.activeEditor.getContent();
document.getElementById("content").innerHTML = editorContent
localStorage.setItem("blog_draft",editorContent)
}
function editorInit() {
if (localStorage.getItem("blog_draft") !== null) tinymce.activeEditor.setContent(localStorage.getItem("blog_draft"));
document.getElementById("content").innerHTML = localStorage.getItem("blog_draft")
editorRefresh();
}
let configTinyMCE = {
selector: 'textarea',
theme_advanced_resizing : false,
resize: false,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste imagetools wordcount',
'codesample emoticons media wordcount slashcommands'
],
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media| emoticons codesample wordcount | gallery',
editor: "restore_draft",
toolbar_mode: 'floating',
automatic_uploads: true,
image_title: true,
file_picker_types: 'image',
file_picker_callback: function (cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = async function () {
const formData = new FormData()
formData.append('image', file)
let uploadData = await fetch('https://api.benzenebots.com/store/upload', {
method: 'POST',
"headers": {
"password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
"id": "a34de56a-bb3a-483a-8d96-e95f885b3396",
},
body: formData
})
let uploadJson = await uploadData.json();
let galleryData = await fetch('https://api.benzenebots.com/gallery', {
method: 'POST',
"headers": {
"password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
"id": "a34de56a-bb3a-483a-8d96-e95f885b3396",
},
body: formData
})
let galleryJson = await galleryData.json();
cb("https://api.benzenebots.com/"+uploadJson.id, { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
},
setup : function(editor) {
editor.on('init', editorInit);
editor.on('Paste Change NodeChange Input Undo Redo', function(e) {
editorRefresh()
});
editor.ui.registry.addButton('gallery', {
icon : `gallery`,
onAction: function (_) {
tinyMCE.activeEditor.windowManager.open({
title: 'My Gallery', // The dialog's title - displayed in the dialog header
size: 'large',
body: {
type: 'panel', // The root body type - a Panel or TabPanel
items: [ // A list of panel components
{
type: 'htmlpanel', // A HTML panel component
html: '<div class="gallery-div"><input type="hidden" id="image"/>Your Gallery Items Html</div>'
}
]
},
buttons: [
{
type: 'cancel',
name: 'closeButton',
text: 'Cancel'
},
{
type: 'submit',
name: 'submitButton',
text: 'Insert To Editor',
primary: true
}
],
onSubmit: function (api) {
}
});
}
});
},
image_caption: true,
branding: false,
skin: "oxide-dark",
icons: "thin",
content_css: "dark",
}
tinymce.PluginManager.add('slashcommands', function (editor) {
var insertActions = [
{
text: 'Heading 1',
icon: 'h1',
action: function () {
editor.execCommand('mceInsertContent', false, '<h1>Heading 1</h1>')
editor.selection.select(editor.selection.getNode());
}
},
{
text: 'Heading 2',
icon: 'h2',
action: function () {
editor.execCommand('mceInsertContent', false, '<h2>Heading 2</h2>');
editor.selection.select(editor.selection.getNode());
}
},
{
text: 'Heading 3',
icon: 'h3',
action: function () {
editor.execCommand('mceInsertContent', false, '<h3>Heading 3</h3>');
editor.selection.select(editor.selection.getNode());
}
},
{
type: 'separator'
},
{
text: 'Paragraph',
icon: 'p',
action: function () {
editor.execCommand('mceInsertContent', false, '<p>Paragraph</p>');
editor.selection.select(editor.selection.getNode());
}
},
{
type: 'separator'
},
{
text: 'Bulleted list',
icon: 'unordered-list',
action: function () {
editor.execCommand('InsertUnorderedList', false);
}
},
{
text: 'Numbered list',
icon: 'ordered-list',
action: function () {
editor.execCommand('InsertOrderedList', false);
}
}
];
// Register the slash commands autocompleter
editor.ui.registry.addAutocompleter('slashcommands', {
ch: '/',
minChars: 0,
columns: 1,
fetch: function (pattern) {
const matchedActions = insertActions.filter(function (action) {
return action.type === 'separator' ||
action.text.toLowerCase().indexOf(pattern.toLowerCase()) !== -1;
});
return new tinymce.util.Promise(function (resolve) {
var results = matchedActions.map(function (action) {
return {
meta: action,
text: action.text,
icon: action.icon,
value: action.text,
type: action.type
}
});
resolve(results);
});
},
onAction: function (autocompleteApi, rng, action, meta) {
editor.selection.setRng(rng);
// Some actions don't delete the "slash", so we delete all the slash
// command content before performing the action
editor.execCommand('Delete');
meta.action();
autocompleteApi.hide();
}
});
return {};
});
tinyMCE.remove('textarea')
tinyMCE.init(configTinyMCE);