activeadmin_quill_editor 1.3.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 +2 -47
- 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 +54 -47
- 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 +7 -18
- data/app/assets/javascripts/activeadmin/quill_editor/quill.min.js +0 -8
@@ -1,11 +1,11 @@
|
|
1
|
-
/*
|
1
|
+
/* globals $ Quill ImageUploader */
|
2
2
|
(function () {
|
3
|
-
'use strict'
|
3
|
+
'use strict';
|
4
4
|
|
5
5
|
// --- functions ---------------------------------------------------------------
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
const initQuillEditors = () => {
|
7
|
+
const defaultTheme = 'snow';
|
8
|
+
const defaultToolbar = [
|
9
9
|
['bold', 'italic', 'underline'],
|
10
10
|
['link', 'blockquote', 'code-block'],
|
11
11
|
[{ 'script': 'sub' }, { 'script': 'super' }],
|
@@ -13,59 +13,65 @@
|
|
13
13
|
[{ 'color': [] }, { 'background': [] }],
|
14
14
|
['image'],
|
15
15
|
['clean'],
|
16
|
-
]
|
17
|
-
|
18
|
-
|
16
|
+
];
|
17
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
18
|
+
const registeredPlugins = {};
|
19
19
|
|
20
20
|
for (let i = 0; i < editors.length; i++) {
|
21
|
-
|
22
|
-
|
21
|
+
const content = editors[i].querySelector('[data-aa-quill-content]');
|
22
|
+
const isActive = editors[i].classList.contains('quill-editor--active');
|
23
|
+
|
23
24
|
if (content && !isActive) {
|
24
25
|
// Setup editor options
|
25
|
-
|
26
|
-
|
27
|
-
if (!options.
|
28
|
-
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;
|
29
31
|
|
30
32
|
// Setup plugin options
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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;
|
36
39
|
}
|
37
|
-
|
38
|
-
|
40
|
+
const opts = pluginOptions.image_uploader;
|
41
|
+
|
42
|
+
options.modules.imageUploader = setupImageUploader(opts.server_url, opts.field_name);
|
39
43
|
}
|
40
44
|
|
41
45
|
// Init editor
|
42
|
-
editors[i]['_quill-editor'] = new Quill(content, options)
|
43
|
-
editors[i].classList += ' quill-editor--active'
|
46
|
+
editors[i]['_quill-editor'] = new Quill(content, options);
|
47
|
+
editors[i].classList += ' quill-editor--active';
|
44
48
|
}
|
45
49
|
}
|
46
50
|
|
47
|
-
|
51
|
+
const formtastic = document.querySelector('form.formtastic');
|
52
|
+
|
48
53
|
if (formtastic) {
|
49
54
|
formtastic.onsubmit = () => {
|
50
55
|
for (let i = 0; i < editors.length; i++) {
|
51
|
-
|
56
|
+
const input = editors[i].querySelector('input[type="hidden"]');
|
57
|
+
|
52
58
|
if (editors[i]['_quill-editor'].editor.isBlank()) {
|
53
|
-
input.value = ''
|
59
|
+
input.value = '';
|
54
60
|
} else {
|
55
|
-
input.value = editors[i]['_quill-editor'].root.innerHTML
|
61
|
+
input.value = editors[i]['_quill-editor'].root.innerHTML;
|
56
62
|
}
|
57
63
|
}
|
58
64
|
};
|
59
65
|
}
|
60
|
-
}
|
66
|
+
};
|
61
67
|
|
62
|
-
|
68
|
+
const setupImageUploader = (server_url, field_name) => {
|
63
69
|
return {
|
64
|
-
upload: file => {
|
70
|
+
upload: (file) => {
|
65
71
|
return new Promise((resolve, reject) => {
|
66
|
-
const formData = new FormData()
|
67
|
-
formData.append(field_name || 'file_upload', file)
|
72
|
+
const formData = new FormData();
|
68
73
|
|
74
|
+
formData.append(field_name || 'file_upload', file);
|
69
75
|
fetch(server_url, {
|
70
76
|
body: formData,
|
71
77
|
headers: {
|
@@ -75,13 +81,13 @@
|
|
75
81
|
}).then(response => response.json())
|
76
82
|
.then(result => {
|
77
83
|
if (!result.url) {
|
78
|
-
reject('Upload failed')
|
84
|
+
reject('Upload failed');
|
79
85
|
}
|
80
86
|
resolve(result.url);
|
81
87
|
})
|
82
88
|
.catch(error => {
|
83
|
-
reject('Upload failed')
|
84
|
-
console.error('Error: ', error)
|
89
|
+
reject('Upload failed');
|
90
|
+
console.error('Error: ', error);
|
85
91
|
})
|
86
92
|
})
|
87
93
|
}
|
@@ -90,27 +96,28 @@
|
|
90
96
|
|
91
97
|
// --- public functions --------------------------------------------------------
|
92
98
|
window.getQuillEditors = function() {
|
93
|
-
const editors = document.querySelectorAll('[data-aa-quill-editor]')
|
94
|
-
|
99
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
100
|
+
const list = [];
|
101
|
+
|
102
|
+
editors.forEach(function(editor) { list.push(editor['_quill-editor']) });
|
95
103
|
|
96
|
-
|
97
|
-
return list
|
104
|
+
return list;
|
98
105
|
}
|
99
106
|
|
100
107
|
window.getQuillEditorByIndex = function(index) {
|
101
|
-
const editors = document.querySelectorAll('[data-aa-quill-editor]')
|
108
|
+
const editors = document.querySelectorAll('[data-aa-quill-editor]');
|
102
109
|
|
103
|
-
return (index >= 0 && index < editors.length) ? editors[index]['_quill-editor'] : null
|
110
|
+
return (index >= 0 && index < editors.length) ? editors[index]['_quill-editor'] : null;
|
104
111
|
}
|
105
112
|
|
106
113
|
window.getQuillEditorByElementId = function(id) {
|
107
|
-
const editor = document.querySelector(`[data-aa-quill-editor]#${id}`)
|
114
|
+
const editor = document.querySelector(`[data-aa-quill-editor]#${id}`);
|
108
115
|
|
109
|
-
return editor ? editor['_quill-editor'] : null
|
116
|
+
return editor ? editor['_quill-editor'] : null;
|
110
117
|
}
|
111
118
|
|
112
119
|
// --- events ------------------------------------------------------------------
|
113
|
-
$(document).ready(initQuillEditors)
|
114
|
-
$(document).on('has_many_add:after', '.has_many_container', initQuillEditors)
|
115
|
-
$(document).on('turbolinks:load', initQuillEditors)
|
116
|
-
})()
|
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
|
}
|