1
|
module RedmineCkeditor::WikiFormatting
|
2
|
module Helper
|
3
|
def replace_editor(field_id)
|
4
|
javascript_tag <<-EOT
|
5
|
(function() {
|
6
|
CKEDITOR.config.contentsCss = "#{stylesheet_path "application"}";
|
7
|
CKEDITOR.config.bodyClass = "wiki";
|
8
|
CKEDITOR.config.toolbar = #{RedmineCkeditorSetting.toolbar.inspect};
|
9
|
CKEDITOR.config.language = "#{current_language.to_s.downcase}";
|
10
|
|
11
|
var textarea = $('#{field_id}');
|
12
|
textarea.parentNode.insertBefore(document.createElement('br'), textarea);
|
13
|
Event.observe(document, "dom:loaded", function() {
|
14
|
var editor = CKEDITOR.replace(textarea,
|
15
|
{
|
16
|
on:
|
17
|
{
|
18
|
instanceReady : function(ev)
|
19
|
{
|
20
|
var writer = this.dataProcessor.writer;
|
21
|
var tags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li'];
|
22
|
for (i = tags.size() - 1; i >= 0; --i)
|
23
|
{
|
24
|
writer.setRules(tags[i], { breakAfterOpen : false });
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
});
|
29
|
|
30
|
|
31
|
//#Joshua //2012.10.12
|
32
|
var ckfinderpath = "/ckfinder/";
|
33
|
//console.log(ckfinderpath);
|
34
|
CKFinder.setupCKEditor( editor, ckfinderpath ) ;
|
35
|
|
36
|
|
37
|
|
38
|
var submit = Form.getInputs(textarea.form, "submit").first();
|
39
|
if (submit) {
|
40
|
submit.nextSiblings().each(function(elem) {
|
41
|
if (elem.nodeName.toLowerCase() != "a") return;
|
42
|
if (elem.onclick.toString().match(/Ajax.Updater.+preview/)){
|
43
|
Element.hide(elem);
|
44
|
return $break;
|
45
|
}
|
46
|
});
|
47
|
}
|
48
|
}, false);
|
49
|
})();
|
50
|
EOT
|
51
|
end
|
52
|
|
53
|
def overwrite_functions
|
54
|
javascript_tag <<-EOT
|
55
|
function showAndScrollTo(id, focus) {
|
56
|
Element.show(id);
|
57
|
Element.scrollTo(id);
|
58
|
if (focus != null) Form.Element.focus(CKEDITOR.instances[focus]);
|
59
|
}
|
60
|
EOT
|
61
|
end
|
62
|
|
63
|
def wikitoolbar_for(field_id)
|
64
|
|
65
|
#//Joshua //2012.10.12
|
66
|
'<script type="text/javascript" src="/ckfinder/ckfinder.js"></script>' +
|
67
|
|
68
|
|
69
|
javascript_include_tag(Redmine::Utils.relative_url_root +
|
70
|
'/plugin_assets/redmine_ckeditor/javascripts/ckeditor/ckeditor') +
|
71
|
replace_editor(field_id) +
|
72
|
overwrite_functions
|
73
|
end
|
74
|
|
75
|
def initial_page_content(page)
|
76
|
"<h1>#{ERB::Util.html_escape page.pretty_title}</h1>"
|
77
|
end
|
78
|
|
79
|
def heads_for_wiki_formatter
|
80
|
end
|
81
|
end
|
82
|
end
|