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: bf8cb33be21c875ee835f3e8b1fa4cb831ef0d46658122bb29aa0c6aba1d1a54
4
- data.tar.gz: 4ca4db51f40f7c091e6373214131a9352cc931563e77b161a8198a3ed0462361
3
+ metadata.gz: 0e534b11a1b6b972d30195ed12f91cbd07dba00c6fc1f58a9f7bee1cf235cfd3
4
+ data.tar.gz: 01b86170283beea647abadd2d4ec6a5b8bea1d7e211b3492c31085c39f8284d9
5
5
  SHA512:
6
- metadata.gz: b24f32b38c090be210d3d348db347c32daeb46fcdcb205b072d9b57095fbfd657f262f54754f001d46307d91ca9f1f784cd36c8b79ccc3ac89490f9b0d243d42
7
- data.tar.gz: 8ff0c6ddbc5b35da1642166c4d27d72cd2475ba2fba8592855088d2633e78dabe8972cf52b2272962c16104bb1f8114d297adf83bb13fb6b89198e9b4e68332c
6
+ metadata.gz: 25cc3a14fb54ec8d7a1e1479dc144162ace6dbb719ce8b2c4063b197f6290aea9427f55020a6171aab77ef3b1bda9ce5c52c27176aa84f0662f588396b14722e
7
+ data.tar.gz: 5e95a8fb7bc6b6c7c15bab6d06102c7def3bf3da89d319b7b1ecd9ee8c512b2d7d45436dfb30eb0de5bc382374cee491f153be2e47bf9fbf8f7716f44fb9ab5d
@@ -1,91 +1,93 @@
1
- // --- functions ---------------------------------------------------------------
2
- function initQuillEditors() {
3
- var default_theme = 'snow';
4
- var default_toolbar = [
5
- ['bold', 'italic', 'underline'],
6
- ['link', 'blockquote', 'code-block'],
7
- [{ 'script': 'sub'}, { 'script': 'super' }],
8
- [{ 'align': [] }, { list: 'ordered' }, { list: 'bullet' }],
9
- [{ 'color': [] }, { 'background': [] }],
10
- ['image'],
11
- ['clean'],
12
- ];
13
- var editors = document.querySelectorAll('.quill-editor');
14
- var registered_plugins = {};
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
- for(var i = 0; i < editors.length; i++) {
17
- var content = editors[i].querySelector('.quill-editor-content');
18
- var isActive = editors[i].classList.contains('quill-editor--active');
19
- if(content && !isActive) {
20
- // Setup editor options
21
- var options = editors[i].getAttribute('data-options') ? JSON.parse(editors[i].getAttribute('data-options')) : {};
22
- if(!options.theme) options.theme = default_theme;
23
- if(!options.modules) options.modules = {};
24
- if(!options.modules.toolbar) options.modules.toolbar = default_toolbar;
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
- // Setup plugin options
27
- var plugin_options = editors[i].getAttribute('data-plugins') ? JSON.parse(editors[i].getAttribute('data-plugins')) : {};
28
- if(plugin_options.image_uploader && plugin_options.image_uploader.server_url) {
29
- if(!registered_plugins.image_uploader) {
30
- Quill.register('modules/imageUploader', ImageUploader);
31
- registered_plugins.image_uploader = true;
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
- // Init editor
38
- editors[i]['_quill-editor'] = new Quill(content, options);
39
- editors[i].classList += ' quill-editor--active';
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
- var formtastic = document.querySelector('form.formtastic');
44
- if(formtastic) {
45
- formtastic.onsubmit = function() {
46
- for(var i = 0; i < editors.length; i++) {
47
- var input = editors[i].querySelector('input[type="hidden"]');
48
- if (editors[i]['_quill-editor'].editor.isBlank()) {
49
- input.value = '';
50
- } else {
51
- input.value = editors[i]['_quill-editor'].root.innerHTML;
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
- return {
60
- upload: file => {
61
- return new Promise((resolve, reject) => {
62
- const formData = new FormData();
63
- formData.append(field_name || 'file_upload', file);
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
- fetch(server_url, {
66
- body: formData,
67
- headers: {
68
- 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
69
- },
70
- method: 'POST'
71
- }).then(response => response.json())
72
- .then(result => {
73
- resolve(result.url);
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
- .catch(error => {
76
- reject('Upload failed');
77
- console.error('Error: ', error);
78
- });
79
- });
81
+ }
80
82
  }
81
83
  }
82
- }
83
84
 
84
- // --- events ------------------------------------------------------------------
85
- $(document).ready( function() {
86
- initQuillEditors();
87
- });
85
+ // --- events ------------------------------------------------------------------
86
+ $(document).ready(() => {
87
+ initQuillEditors()
88
+ })
88
89
 
89
- $(document).on('has_many_add:after', function() {
90
- initQuillEditors();
91
- });
90
+ $(document).on('has_many_add:after', '.has_many_container', () => {
91
+ initQuillEditors()
92
+ })
93
+ })()
@@ -5,7 +5,7 @@
5
5
  text-align: initial;
6
6
  }
7
7
 
8
- body.active_admin .quill-editor {
8
+ body.active_admin [data-aa-quill-editor] {
9
9
  display: inline-block;
10
10
  width: calc(80% - 2px);
11
11
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module QuillEditor
5
- VERSION = '0.2.10'
5
+ VERSION = '0.2.12'
6
6
  end
7
7
  end
@@ -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(class: 'quill-editor')) do
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, class: 'quill-editor-content') do
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.10
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-05 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin