activeadmin_quill_editor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -10
- data/Rakefile +11 -0
- data/app/assets/javascripts/activeadmin/quill.imageUploader.js +362 -0
- data/app/assets/javascripts/activeadmin/quill.imageUploader.min.js +1 -1
- data/app/assets/javascripts/activeadmin/quill_editor/quill.core.js +3 -8594
- data/app/assets/javascripts/activeadmin/quill_editor/quill.js +3 -11562
- data/app/assets/javascripts/activeadmin/quill_editor_input.js +69 -37
- data/app/assets/stylesheets/activeadmin/quill.imageUploader.min.css +4 -4
- data/app/assets/stylesheets/activeadmin/quill_editor/quill.bubble.css +6 -948
- data/app/assets/stylesheets/activeadmin/quill_editor/quill.core.css +6 -393
- data/app/assets/stylesheets/activeadmin/quill_editor/quill.snow.css +6 -941
- data/lib/activeadmin/quill_editor/version.rb +2 -2
- metadata +4 -18
- data/app/assets/javascripts/activeadmin/quill_editor/quill.min.js +0 -8
@@ -1,10 +1,11 @@
|
|
1
|
+
/* globals $ Quill ImageUploader */
|
1
2
|
(function () {
|
2
|
-
'use strict'
|
3
|
+
'use strict';
|
3
4
|
|
4
5
|
// --- functions ---------------------------------------------------------------
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
const initQuillEditors = () => {
|
7
|
+
const defaultTheme = 'snow';
|
8
|
+
const defaultToolbar = [
|
8
9
|
['bold', 'italic', 'underline'],
|
9
10
|
['link', 'blockquote', 'code-block'],
|
10
11
|
[{ 'script': 'sub' }, { 'script': 'super' }],
|
@@ -12,59 +13,65 @@
|
|
12
13
|
[{ 'color': [] }, { 'background': [] }],
|
13
14
|
['image'],
|
14
15
|
['clean'],
|
15
|
-
]
|
16
|
-
|
17
|
-
|
16
|
+
];
|
17
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
18
|
+
const registeredPlugins = {};
|
18
19
|
|
19
20
|
for (let i = 0; i < editors.length; i++) {
|
20
|
-
|
21
|
-
|
21
|
+
const content = editors[i].querySelector('[data-aa-quill-content]');
|
22
|
+
const isActive = editors[i].classList.contains('quill-editor--active');
|
23
|
+
|
22
24
|
if (content && !isActive) {
|
23
25
|
// Setup editor options
|
24
|
-
|
25
|
-
|
26
|
-
if (!options.
|
27
|
-
if (!options.modules
|
26
|
+
const options = editors[i].getAttribute('data-options') ? JSON.parse(editors[i].getAttribute('data-options')) : {};
|
27
|
+
|
28
|
+
if (!options.theme) options.theme = defaultTheme;
|
29
|
+
if (!options.modules) options.modules = {};
|
30
|
+
if (!options.modules.toolbar) options.modules.toolbar = defaultToolbar;
|
28
31
|
|
29
32
|
// Setup plugin options
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
const pluginOptions = editors[i].getAttribute('data-plugins') ? JSON.parse(editors[i].getAttribute('data-plugins')) : {};
|
34
|
+
|
35
|
+
if (pluginOptions.image_uploader && pluginOptions.image_uploader.server_url) {
|
36
|
+
if (!registeredPlugins.image_uploader) {
|
37
|
+
Quill.register('modules/imageUploader', ImageUploader);
|
38
|
+
registeredPlugins.image_uploader = true;
|
35
39
|
}
|
36
|
-
|
37
|
-
|
40
|
+
const opts = pluginOptions.image_uploader;
|
41
|
+
|
42
|
+
options.modules.imageUploader = setupImageUploader(opts.server_url, opts.field_name);
|
38
43
|
}
|
39
44
|
|
40
45
|
// Init editor
|
41
|
-
editors[i]['_quill-editor'] = new Quill(content, options)
|
42
|
-
editors[i].classList += ' quill-editor--active'
|
46
|
+
editors[i]['_quill-editor'] = new Quill(content, options);
|
47
|
+
editors[i].classList += ' quill-editor--active';
|
43
48
|
}
|
44
49
|
}
|
45
50
|
|
46
|
-
|
51
|
+
const formtastic = document.querySelector('form.formtastic');
|
52
|
+
|
47
53
|
if (formtastic) {
|
48
54
|
formtastic.onsubmit = () => {
|
49
55
|
for (let i = 0; i < editors.length; i++) {
|
50
|
-
|
56
|
+
const input = editors[i].querySelector('input[type="hidden"]');
|
57
|
+
|
51
58
|
if (editors[i]['_quill-editor'].editor.isBlank()) {
|
52
|
-
input.value = ''
|
59
|
+
input.value = '';
|
53
60
|
} else {
|
54
|
-
input.value = editors[i]['_quill-editor'].root.innerHTML
|
61
|
+
input.value = editors[i]['_quill-editor'].root.innerHTML;
|
55
62
|
}
|
56
63
|
}
|
57
64
|
};
|
58
65
|
}
|
59
|
-
}
|
66
|
+
};
|
60
67
|
|
61
|
-
|
68
|
+
const setupImageUploader = (server_url, field_name) => {
|
62
69
|
return {
|
63
|
-
upload: file => {
|
70
|
+
upload: (file) => {
|
64
71
|
return new Promise((resolve, reject) => {
|
65
|
-
const formData = new FormData()
|
66
|
-
formData.append(field_name || 'file_upload', file)
|
72
|
+
const formData = new FormData();
|
67
73
|
|
74
|
+
formData.append(field_name || 'file_upload', file);
|
68
75
|
fetch(server_url, {
|
69
76
|
body: formData,
|
70
77
|
headers: {
|
@@ -73,19 +80,44 @@
|
|
73
80
|
method: 'POST'
|
74
81
|
}).then(response => response.json())
|
75
82
|
.then(result => {
|
83
|
+
if (!result.url) {
|
84
|
+
reject('Upload failed');
|
85
|
+
}
|
76
86
|
resolve(result.url);
|
77
87
|
})
|
78
88
|
.catch(error => {
|
79
|
-
reject('Upload failed')
|
80
|
-
console.error('Error: ', error)
|
89
|
+
reject('Upload failed');
|
90
|
+
console.error('Error: ', error);
|
81
91
|
})
|
82
92
|
})
|
83
93
|
}
|
84
94
|
}
|
85
95
|
}
|
86
96
|
|
97
|
+
// --- public functions --------------------------------------------------------
|
98
|
+
window.getQuillEditors = function() {
|
99
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
100
|
+
const list = [];
|
101
|
+
|
102
|
+
editors.forEach(function(editor) { list.push(editor['_quill-editor']) });
|
103
|
+
|
104
|
+
return list;
|
105
|
+
}
|
106
|
+
|
107
|
+
window.getQuillEditorByIndex = function(index) {
|
108
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
109
|
+
|
110
|
+
return (index >= 0 && index < editors.length) ? editors[index]['_quill-editor'] : null;
|
111
|
+
}
|
112
|
+
|
113
|
+
window.getQuillEditorByElementId = function(id) {
|
114
|
+
const editor = document.querySelector(`[data-aa-quill-editor]#${id}`);
|
115
|
+
|
116
|
+
return editor ? editor['_quill-editor'] : null;
|
117
|
+
}
|
118
|
+
|
87
119
|
// --- events ------------------------------------------------------------------
|
88
|
-
$(document).ready(initQuillEditors)
|
89
|
-
$(document).on('has_many_add:after', '.has_many_container', initQuillEditors)
|
90
|
-
$(document).on('turbolinks:load', initQuillEditors)
|
91
|
-
})()
|
120
|
+
$(document).ready(initQuillEditors);
|
121
|
+
$(document).on('has_many_add:after', '.has_many_container', initQuillEditors);
|
122
|
+
$(document).on('turbolinks:load', initQuillEditors);
|
123
|
+
})();
|
@@ -1,15 +1,15 @@
|
|
1
|
-
.image-uploading {
|
1
|
+
.quill-image-uploading {
|
2
2
|
position: relative;
|
3
3
|
display: inline-block;
|
4
4
|
}
|
5
5
|
|
6
|
-
.image-uploading img {
|
6
|
+
.quill-image-uploading img {
|
7
7
|
max-width: 98% !important;
|
8
8
|
filter: blur(5px);
|
9
9
|
opacity: 0.3;
|
10
10
|
}
|
11
11
|
|
12
|
-
.image-uploading::before {
|
12
|
+
.quill-image-uploading::before {
|
13
13
|
content: "";
|
14
14
|
box-sizing: border-box;
|
15
15
|
position: absolute;
|
@@ -21,7 +21,7 @@
|
|
21
21
|
margin-left: -15px;
|
22
22
|
border-radius: 50%;
|
23
23
|
border: 3px solid #ccc;
|
24
|
-
border-top-color: #
|
24
|
+
border-top-color: #1e40af;
|
25
25
|
z-index: 1;
|
26
26
|
animation: spinner 0.6s linear infinite;
|
27
27
|
}
|