effective_bootstrap 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/effective_editor/initialize.js.coffee +32 -12
- data/app/assets/stylesheets/effective_editor/overrides.scss +1 -0
- data/app/helpers/effective_editor_helper.rb +23 -3
- data/app/helpers/effective_form_builder_helper.rb +1 -1
- data/app/models/effective/form_builder.rb +1 -0
- data/app/models/effective/form_inputs/editor.rb +23 -10
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dcabe6562a28a9ad9845025ee4ba974ca38c846
|
4
|
+
data.tar.gz: 8b022529edf57d27fd3507dab9029c0242297acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3626fa1ca74154ace16f44e117d0ebef60ec2d9e68dad9d87bbb1f5b10b5fefca5855683cfd9ec2fa981c1028fb4ec2873e1552a3d73936bb6fbf8bc46c612f5
|
7
|
+
data.tar.gz: 7d17e33751e29a7cbc81e94a7afcb74dd4bef5634a333d1e8a360d724490b80b28728f8f79dde48712e26b4f8066c00888cde0c61c5a4d32698cd8d0c1327c39
|
@@ -3,23 +3,32 @@
|
|
3
3
|
(this.EffectiveBootstrap || {}).effective_editor = ($element, options) ->
|
4
4
|
editor = '#' + $element.attr('id') + '_editor'
|
5
5
|
|
6
|
-
|
7
|
-
delete options['
|
6
|
+
content_mode = options['content_mode']
|
7
|
+
delete options['content_mode']
|
8
8
|
|
9
|
-
quill = new Quill(editor, options)
|
9
|
+
quill = new Quill($element.siblings(editor).get(0), options)
|
10
10
|
content = $element.val() || ''
|
11
11
|
|
12
12
|
if content.length > 0
|
13
|
-
if content.startsWith('{')
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
if content.startsWith('{')
|
14
|
+
quill.setContents(JSON.parse(content))
|
15
|
+
else if content_mode == 'code'
|
16
|
+
quill.setText(content)
|
17
|
+
else if content.startsWith('<')
|
18
|
+
quill.pasteHTML(content)
|
19
|
+
else
|
20
|
+
quill.setText(content)
|
21
|
+
|
22
|
+
if content_mode == 'code'
|
23
|
+
quill.formatText(0, quill.getLength(), 'code-block', true)
|
24
|
+
quill.on 'text-change', -> $element.val(quill.getText())
|
25
|
+
else if content_mode == 'html'
|
26
|
+
quill.on 'text-change', ->
|
20
27
|
html = $(editor).children('.ql-editor').html()
|
21
28
|
html = '' if html == '<p><br></p>' || html == '<p></p>'
|
22
29
|
$element.val(html)
|
30
|
+
else
|
31
|
+
quill.on 'text-change', -> $element.val(JSON.stringify(quill.getContents()))
|
23
32
|
|
24
33
|
$element.on 'quill:focus', (event) -> quill.focus()
|
25
34
|
|
@@ -27,7 +36,18 @@
|
|
27
36
|
(this.EffectiveBootstrap || {}).effective_editor_tag = ($element, options) ->
|
28
37
|
quill = new Quill('#' + $element.attr('id'), options)
|
29
38
|
|
30
|
-
content = ($element.attr('data-
|
39
|
+
content = ($element.attr('data-content') || '')
|
40
|
+
content_mode = $element.data('input-js-options')['content_mode']
|
31
41
|
|
32
42
|
if content.length > 0
|
33
|
-
if content.startsWith('{')
|
43
|
+
if content.startsWith('{')
|
44
|
+
quill.setContents(JSON.parse(content))
|
45
|
+
else if content_mode == 'code'
|
46
|
+
quill.setText(content)
|
47
|
+
else if content.startsWith('<')
|
48
|
+
quill.pasteHTML(content)
|
49
|
+
else
|
50
|
+
quill.setText(content)
|
51
|
+
|
52
|
+
if content_mode == 'code'
|
53
|
+
quill.formatText(0, quill.getLength(), 'code-block', true)
|
@@ -1,9 +1,29 @@
|
|
1
1
|
module EffectiveEditorHelper
|
2
2
|
|
3
|
-
def effective_editor_tag(
|
4
|
-
|
3
|
+
def effective_editor_tag(content, options = {})
|
4
|
+
content = content.presence || '{}'
|
5
5
|
|
6
|
-
|
6
|
+
content_mode = (
|
7
|
+
if options.delete(:delta)
|
8
|
+
:delta
|
9
|
+
elsif options.delete(:html)
|
10
|
+
:html
|
11
|
+
elsif options.delete(:code)
|
12
|
+
:code
|
13
|
+
else
|
14
|
+
:delta
|
15
|
+
end
|
16
|
+
)
|
17
|
+
|
18
|
+
input_js = {
|
19
|
+
method_name: 'effective_editor_tag',
|
20
|
+
theme: 'snow',
|
21
|
+
readOnly: true,
|
22
|
+
content_mode: content_mode,
|
23
|
+
modules: { toolbar: false, syntax: (content_mode == :code) }
|
24
|
+
}
|
25
|
+
|
26
|
+
content_tag(:div, '', id: "ql-#{content.object_id}", class: 'effective_editor_content ql-effective', data: { 'input-js-options': input_js, 'content': content })
|
7
27
|
end
|
8
28
|
|
9
29
|
end
|
@@ -5,7 +5,7 @@ module EffectiveFormBuilderHelper
|
|
5
5
|
|
6
6
|
# Compute the default ID
|
7
7
|
subject = Array(options[:scope] || options[:model]).last
|
8
|
-
class_name = subject.class.name.
|
8
|
+
class_name = subject.class.name.underscore
|
9
9
|
|
10
10
|
html_id = if subject.kind_of?(Symbol)
|
11
11
|
subject.to_s
|
@@ -5,7 +5,7 @@ module Effective
|
|
5
5
|
def build_input(&block)
|
6
6
|
content = value.presence || (capture(&block) if block_given?)
|
7
7
|
|
8
|
-
@builder.
|
8
|
+
@builder.super_text_area(name, (options[:input] || {}).merge(autocomplete: 'off')) +
|
9
9
|
content_tag(:div, '', class: 'ql-effective', id: unique_id + '_editor')
|
10
10
|
end
|
11
11
|
|
@@ -14,11 +14,18 @@ module Effective
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def input_js_options
|
17
|
-
{
|
17
|
+
{
|
18
|
+
modules: { toolbar: toolbar, syntax: (content_mode == :code) },
|
19
|
+
theme: 'snow',
|
20
|
+
placeholder: "Add #{name.to_s.pluralize}...",
|
21
|
+
content_mode: content_mode
|
22
|
+
}
|
18
23
|
end
|
19
24
|
|
20
25
|
# Commented out 'Full' toolbar options because currently we don't want headers / source / code options
|
21
26
|
def toolbar
|
27
|
+
return false if content_mode == :code
|
28
|
+
|
22
29
|
[
|
23
30
|
# [{'header': [1, 2, 3, 4, false] }],
|
24
31
|
['bold', 'italic', 'underline'],
|
@@ -28,14 +35,20 @@ module Effective
|
|
28
35
|
]
|
29
36
|
end
|
30
37
|
|
31
|
-
def
|
32
|
-
return @
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def content_mode # default false
|
39
|
+
return @content_mode unless @content_mode.nil?
|
40
|
+
|
41
|
+
@content_mode = (
|
42
|
+
if options.delete(:delta)
|
43
|
+
:delta
|
44
|
+
elsif options.delete(:html)
|
45
|
+
:html
|
46
|
+
elsif options.delete(:code)
|
47
|
+
:code
|
48
|
+
else
|
49
|
+
:delta
|
50
|
+
end
|
51
|
+
)
|
39
52
|
end
|
40
53
|
|
41
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|