Sha256: 315aa8aac7dd54431c0f96a831f0ee936a08c01ee15eaccf62b3c5a4c176bbe2

Contents?: true

Size: 1.87 KB

Versions: 64

Compression:

Stored size: 1.87 KB

Contents

# https://quilljs.com/docs/download/
# https://github.com/quilljs/quill
(this.EffectiveBootstrap || {}).effective_editor = ($element, options) ->
  editor = '#' + $element.attr('id') + '_editor'

  content_mode = options['content_mode']
  delete options['content_mode']

  quill = new Quill($element.siblings(editor).get(0), options)
  content = $element.val() || ''

  if content.length > 0
    if content.startsWith('{')
      quill.setContents(JSON.parse(content))
    else if content_mode == 'code'
      quill.setText(content)
    else if content.startsWith('<')
      quill.pasteHTML(content)
    else
      quill.setText(content)

  if content_mode == 'code'
    quill.formatText(0, quill.getLength(), 'code-block', true)

    quill.on 'text-change', ->
      $element.val(quill.getText())
      $element.trigger('change')
  else if content_mode == 'html'
    quill.on 'text-change', ->
      html = $(editor).children('.ql-editor').html()
      html = '' if html == '<p><br></p>' || html == '<p></p>'
      $element.val(html)
      $element.trigger('change')
  else
    quill.on 'text-change', ->
      $element.val(JSON.stringify(quill.getContents()))
      $element.trigger('change')

  $element.on 'quill:focus', (event) -> quill.focus()

# This is the read only region. Always delta.
(this.EffectiveBootstrap || {}).effective_editor_tag = ($element, options) ->
  quill = new Quill('#' + $element.attr('id'), options)

  content = ($element.attr('data-content') || '')
  content_mode = $element.data('input-js-options')['content_mode']

  if content.length > 0
    if content.startsWith('{')
      quill.setContents(JSON.parse(content))
    else if content_mode == 'code'
      quill.setText(content)
    else if content.startsWith('<')
      quill.pasteHTML(content)
    else
      quill.setText(content)

  if content_mode == 'code'
    quill.formatText(0, quill.getLength(), 'code-block', true)

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
effective_bootstrap-0.6.11 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.10 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.9 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.8 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.7 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.6 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.5 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.4 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.3 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.2 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.1 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.6.0 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.20 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.19 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.18 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.17 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.16 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.15 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.14 app/assets/javascripts/effective_editor/initialize.js.coffee
effective_bootstrap-0.5.13 app/assets/javascripts/effective_editor/initialize.js.coffee