Class: Wysiwyg::MainController

Inherits:
Volt::ModelController
  • Object
show all
Defined in:
app/wysiwyg/controllers/main_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#quillObject (readonly)

Returns the value of attribute quill.



3
4
5
# File 'app/wysiwyg/controllers/main_controller.rb', line 3

def quill
  @quill
end

Instance Method Details

#before_index_removeObject



35
36
37
# File 'app/wysiwyg/controllers/main_controller.rb', line 35

def before_index_remove
  @computation.stop
end

#index_readyObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/wysiwyg/controllers/main_controller.rb', line 5

def index_ready
  @updating_attribute = false
  %x{
    var quill = new Quill('.quill-editor', {
      modules: {
        'toolbar': {
          container: '.toolbar-container'
        },
        'link-tooltip': true,
        'image-tooltip': true
      },
      styles: false,
      theme: 'snow'
    });
    #{@quill} = quill

    quill.on('text-change', function(){
      if (!self.updating_editor) {
        #{@updating_attribute = true }
        #{new_text = nil ; puts 'updating'}
        new_text = quill.getHTML();
        #{ attrs.text = new_text }
        setImmediate(function(){ #{ @updating_attribute = false } });
      }
    });
  }

  @computation = -> { update_text(attrs.text) }.watch!
end

#update_text(new_text) ⇒ Object



39
40
41
42
43
44
45
46
# File 'app/wysiwyg/controllers/main_controller.rb', line 39

def update_text(new_text)
  unless @updating_attribute
    @updating_editor = true
    puts 'updating text'
     `#{quill}.setHTML(#{new_text || ''})`
    @updating_editor = false
  end
end