Skip to content

Commit e281679

Browse files
author
Cerem Cem ASLAN
committed
added Quill editor as rich-text component
1 parent adccf08 commit e281679

File tree

5 files changed

+286
-27
lines changed

5 files changed

+286
-27
lines changed

components/index.ls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ require! './icon'
6060
require! './btn'
6161
require! './s-input'
6262
require! './accordion'
63+
require! './rich-text'
6364

6465

6566
# decorators

components/rich-text/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import "quill/dist/quill.core.css";
2+
@import "quill/dist/quill.snow.css";
3+
4+
.ql-container {
5+
overflow-x: scroll;
6+
height: 500px; /* whatever you what */
7+
}

components/rich-text/index.ls

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require! 'quill': Quill
2+
3+
Ractive.components['rich-text'] = Ractive.extend do
4+
template: '''
5+
<div id="quilleditor_{{_guid}}" class="{{class}}"></div>
6+
'''
7+
onrender: ->
8+
options = {
9+
modules: {
10+
toolbar: [
11+
[{ header: [1, 2, 3, 4, 5, 6, false] }],
12+
['bold', 'italic', 'underline','strike'],
13+
['image', 'code-block'],
14+
['link'],
15+
[{ 'script': 'sub'}, { 'script': 'super' }],
16+
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
17+
[{ 'indent': '-1'}, { 'indent': '+1' }], # outdent/indent
18+
[{ 'direction': 'rtl' }], # text direction
19+
[{ 'size': ['small', false, 'large', 'huge'] }], # custom dropdown
20+
[{ 'color': [] }, { 'background': [] }], # dropdown with defaults from theme
21+
[{ 'font': [] }],
22+
[{ align: '' }, { align: 'center' }, { align: 'right' }, { align: 'justify' }]
23+
['clean'] # remove formatting button
24+
]
25+
},
26+
placeholder: @get('placeholder'),
27+
theme: 'snow'
28+
};
29+
30+
editor = new Quill('#quilleditor_' + @_guid, options)
31+
32+
observer = @observe 'value', (_new) ->
33+
editor.clipboard.dangerouslyPasteHTML 0, _new
34+
35+
editor.on 'text-change', (delta, oldDelta, source) ~>
36+
if source is \user
37+
observer.silence!
38+
@set 'value', editor.root.innerHTML
39+
observer.resume!
40+
41+
data: ->
42+
value: ""
43+
placeholder: ""

0 commit comments

Comments
 (0)