cirandas.net

ref: master

app/helpers/tinymce_helper.rb


 1
 2
 3
 4
 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module TinymceHelper
  include MacrosHelper

  def tinymce_js
    output = ''
    output += javascript_include_tag 'tinymce/js/tinymce/tinymce.js'
    output += javascript_include_tag 'tinymce/js/tinymce/jquery.tinymce.min.js'
    output += javascript_include_tag 'tinymce.js'
    output += include_macro_js_files.to_s
    output.html_safe
  end

  def tinymce_init_js options = {}
    options.merge! :document_base_url => top_url,
      :content_css => "/stylesheets/tinymce.css,#{macro_css_files}",
      :plugins => %w[compat3x advlist autolink lists link image charmap print preview hr anchor pagebreak
        searchreplace wordcount visualblocks visualchars code fullscreen
        insertdatetime media nonbreaking save table contextmenu directionality
        emoticons template paste textcolor colorpicker textpattern],
      :image_advtab => true,
      :language => tinymce_language,
      :selector => '.' + current_editor(options[:mode])

    options[:toolbar1] = toolbar1(options[:mode])
    options[:menubar] = menubar(options[:mode])
    options[:toolbar2] = toolbar2(options[:mode])

    options[:macros_setup] = macros_with_buttons.map do |macro|
      <<-EOS
        ed.addButton('#{macro.identifier}', {
          title: #{macro_title(macro).to_json},
          onclick: #{generate_macro_config_dialog macro},
          image : '#{macro.configuration[:icon_path]}'
        });
      EOS
    end

    apply_etherpadlite_options options

    #cleanup non tinymce options
    options = options.except :mode

    "noosfero.tinymce.init(#{options.to_json})".html_safe
  end

  def apply_etherpadlite_options options
    return if options[:mode] == 'simple'
    return unless environment.tinymce_plugin_etherpadlite_padServerUrl.present?
    options.merge! :plugin_etherpadlite_padServerUrl => environment.tinymce_plugin_etherpadlite_padServerUrl,
      :plugin_etherpadlite_padNamesPrefix => environment.default_hostname,
      :plugin_etherpadlite_padWidth => environment.tinymce_plugin_etherpadlite_padWidth,
      :plugin_etherpadlite_padHeight => environment.tinymce_plugin_etherpadlite_padHeight
    options[:plugins] << "etherpadlite"
    options[:toolbar2] += " | etherpadlite" if options[:toolbar2]
  end

  def menubar mode
    if mode =='restricted' || mode == 'simple'
      return false
    end
    return 'edit insert view tools'
  end

  def toolbar1 mode
    if mode == 'restricted'
      return "bold italic underline | link"
    end
    return "fullscreen | insertfile undo redo | copy paste | bold italic underline | styleselect fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
  end

  def toolbar2 mode
    if mode.blank?
      toolbar2 = 'print preview code media | table'
      toolbar2 += ' | macros'
      macros_with_buttons.each do |macro|
        toolbar2 += " #{macro.identifier}"
      end
      return toolbar2
    end
  end

end