activeadmin_quill_editor 0.2.10 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e534b11a1b6b972d30195ed12f91cbd07dba00c6fc1f58a9f7bee1cf235cfd3
|
4
|
+
data.tar.gz: 01b86170283beea647abadd2d4ec6a5b8bea1d7e211b3492c31085c39f8284d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25cc3a14fb54ec8d7a1e1479dc144162ace6dbb719ce8b2c4063b197f6290aea9427f55020a6171aab77ef3b1bda9ce5c52c27176aa84f0662f588396b14722e
|
7
|
+
data.tar.gz: 5e95a8fb7bc6b6c7c15bab6d06102c7def3bf3da89d319b7b1ecd9ee8c512b2d7d45436dfb30eb0de5bc382374cee491f153be2e47bf9fbf8f7716f44fb9ab5d
|
@@ -1,91 +1,93 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
(function () {
|
2
|
+
// --- functions ---------------------------------------------------------------
|
3
|
+
function initQuillEditors() {
|
4
|
+
let default_theme = 'snow'
|
5
|
+
let default_toolbar = [
|
6
|
+
['bold', 'italic', 'underline'],
|
7
|
+
['link', 'blockquote', 'code-block'],
|
8
|
+
[{ 'script': 'sub' }, { 'script': 'super' }],
|
9
|
+
[{ 'align': [] }, { list: 'ordered' }, { list: 'bullet' }],
|
10
|
+
[{ 'color': [] }, { 'background': [] }],
|
11
|
+
['image'],
|
12
|
+
['clean'],
|
13
|
+
]
|
14
|
+
let editors = document.querySelectorAll('[data-aa-quill-editor]')
|
15
|
+
let registered_plugins = {}
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
for (let i = 0; i < editors.length; i++) {
|
18
|
+
let content = editors[i].querySelector('[data-aa-quill-content]')
|
19
|
+
let isActive = editors[i].classList.contains('quill-editor--active')
|
20
|
+
if (content && !isActive) {
|
21
|
+
// Setup editor options
|
22
|
+
let options = editors[i].getAttribute('data-options') ? JSON.parse(editors[i].getAttribute('data-options')) : {}
|
23
|
+
if (!options.theme) options.theme = default_theme
|
24
|
+
if (!options.modules) options.modules = {}
|
25
|
+
if (!options.modules.toolbar) options.modules.toolbar = default_toolbar
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
// Setup plugin options
|
28
|
+
let plugin_options = editors[i].getAttribute('data-plugins') ? JSON.parse(editors[i].getAttribute('data-plugins')) : {}
|
29
|
+
if (plugin_options.image_uploader && plugin_options.image_uploader.server_url) {
|
30
|
+
if (!registered_plugins.image_uploader) {
|
31
|
+
Quill.register('modules/imageUploader', ImageUploader)
|
32
|
+
registered_plugins.image_uploader = true
|
33
|
+
}
|
34
|
+
let opts = plugin_options.image_uploader
|
35
|
+
options.modules.imageUploader = setupImageUploader(opts.server_url, opts.field_name)
|
32
36
|
}
|
33
|
-
var opts = plugin_options.image_uploader;
|
34
|
-
options.modules.imageUploader = setupImageUploader(opts.server_url, opts.field_name);
|
35
|
-
}
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
// Init editor
|
39
|
+
editors[i]['_quill-editor'] = new Quill(content, options)
|
40
|
+
editors[i].classList += ' quill-editor--active'
|
41
|
+
}
|
40
42
|
}
|
41
|
-
}
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
let formtastic = document.querySelector('form.formtastic')
|
45
|
+
if (formtastic) {
|
46
|
+
formtastic.onsubmit = () => {
|
47
|
+
for (let i = 0; i < editors.length; i++) {
|
48
|
+
let input = editors[i].querySelector('input[type="hidden"]')
|
49
|
+
if (editors[i]['_quill-editor'].editor.isBlank()) {
|
50
|
+
input.value = ''
|
51
|
+
} else {
|
52
|
+
input.value = editors[i]['_quill-editor'].root.innerHTML
|
53
|
+
}
|
52
54
|
}
|
53
|
-
}
|
54
|
-
}
|
55
|
+
};
|
56
|
+
}
|
55
57
|
}
|
56
|
-
}
|
57
58
|
|
58
|
-
function setupImageUploader(server_url, field_name) {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
function setupImageUploader(server_url, field_name) {
|
60
|
+
return {
|
61
|
+
upload: file => {
|
62
|
+
return new Promise((resolve, reject) => {
|
63
|
+
const formData = new FormData()
|
64
|
+
formData.append(field_name || 'file_upload', file)
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
fetch(server_url, {
|
67
|
+
body: formData,
|
68
|
+
headers: {
|
69
|
+
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
70
|
+
},
|
71
|
+
method: 'POST'
|
72
|
+
}).then(response => response.json())
|
73
|
+
.then(result => {
|
74
|
+
resolve(result.url);
|
75
|
+
})
|
76
|
+
.catch(error => {
|
77
|
+
reject('Upload failed')
|
78
|
+
console.error('Error: ', error)
|
79
|
+
})
|
74
80
|
})
|
75
|
-
|
76
|
-
reject('Upload failed');
|
77
|
-
console.error('Error: ', error);
|
78
|
-
});
|
79
|
-
});
|
81
|
+
}
|
80
82
|
}
|
81
83
|
}
|
82
|
-
}
|
83
84
|
|
84
|
-
// --- events ------------------------------------------------------------------
|
85
|
-
$(document).ready(
|
86
|
-
|
87
|
-
})
|
85
|
+
// --- events ------------------------------------------------------------------
|
86
|
+
$(document).ready(() => {
|
87
|
+
initQuillEditors()
|
88
|
+
})
|
88
89
|
|
89
|
-
$(document).on('has_many_add:after',
|
90
|
-
|
91
|
-
})
|
90
|
+
$(document).on('has_many_add:after', '.has_many_container', () => {
|
91
|
+
initQuillEditors()
|
92
|
+
})
|
93
|
+
})()
|
@@ -6,9 +6,9 @@ module Formtastic
|
|
6
6
|
def to_html
|
7
7
|
input_wrapping do
|
8
8
|
label_html <<
|
9
|
-
template.content_tag(:div, input_html_options.merge(
|
9
|
+
template.content_tag(:div, input_html_options.merge('data-aa-quill-editor': '1')) do
|
10
10
|
builder.hidden_field(input_name) <<
|
11
|
-
template.content_tag(:div,
|
11
|
+
template.content_tag(:div, 'data-aa-quill-content': '1') do
|
12
12
|
object.send(method).try :html_safe
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_quill_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|