tiny_mce.rhtml
3.7 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<% extend MacrosHelper %>
<%= javascript_include_tag 'tinymce/jscripts/tiny_mce/tiny_mce.js' %>
<%= include_macro_js_files %>
<script type="text/javascript">
var myplugins = "searchreplace,print,table,contextmenu,-macrosPlugin";
var first_line, second_line;
var mode = '<%= mode ||= false %>'
<% if mode %>
first_line = "fontsizeselect,bold,italic,underline,bullist,numlist,justifyleft,justifycenter,justifyright,link,unlink"
second_line = ""
<% else %>
first_line = "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,forecolor,fontsizeselect,formatselect"
second_line = "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code,macros"
<% macros_with_buttons.each do |macro| %>
second_line += ',<%=macro.identifier %>'
<% end %>
<% end %>
if (tinymce.isIE) {
// the paste plugin is only useful in Internet Explorer
myplugins = "paste," + myplugins;
}
tinymce.create('tinymce.plugins.MacrosPlugin', {
createControl: function(n, cm) {
switch (n) {
case 'macros':
<% unless macros_in_menu.empty? %>
var c = cm.createMenuButton('macros', {
title : 'Macros',
image : '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png',
icons : false
});
<% macros_in_menu.each do |macro| %>
c.onRenderMenu.add(function(c, m) {
m.add({
title: <%= macro_title(macro).to_json %>,
onclick: <%= generate_macro_config_dialog(macro) %>
});
});
<% end %>
// Return the new menu button instance
return c;
<% end %>
}
return null;
}
});
// Register plugin with a short name
tinymce.PluginManager.add('macrosPlugin', tinymce.plugins.MacrosPlugin);
tinyMCE.init({
mode : "textareas",
editor_selector : "mceEditor",
theme : "advanced",
relative_urls : false,
remove_script_host : false,
document_base_url : <%= environment.top_url.to_json %>,
plugins: myplugins,
theme_advanced_toolbar_location : "top",
theme_advanced_layout_manager: 'SimpleLayout',
theme_advanced_buttons1 : first_line,
theme_advanced_buttons2 : second_line,
theme_advanced_buttons3 : "",
theme_advanced_blockformats :"p,address,pre,h2,h3,h4,h5,h6",
paste_auto_cleanup_on_paste : true,
paste_insert_word_content_callback : "convertWord",
paste_use_dialog: false,
apply_source_formatting : true,
extended_valid_elements : "applet[style|archive|codebase|code|height|width],comment,iframe[src|style|allowtransparency|frameborder|width|height|scrolling],embed[title|src|type|height|width],audio[controls|autoplay],video[controls|autoplay],source[src|type]",
content_css: '/stylesheets/tinymce.css,<%= macro_css_files %>',
language: <%= tinymce_language.inspect %>,
entity_encoding: 'raw',
setup : function(ed) {
<% macros_with_buttons.each do |macro| %>
ed.addButton('<%= macro.identifier %>', {
title: <%= macro_title(macro).to_json %>,
onclick: <%= generate_macro_config_dialog(macro) %>,
image : '<%= macro.configuration[:icon_path]%>'
});
<% end %>
}
});
function convertWord(type, content) {
switch (type) {
// Gets executed before the built in logic performes it's cleanups
case "before":
//content = content.toLowerCase(); // Some dummy logic
break;
// Gets executed after the built in logic performes it's cleanups
case "after":
content = content.replace(/<!--\s*-->/, '');
break;
}
return content;
}
</script>