1
|
module RedmineCkeditor::WikiFormatting
|
2
|
module Helper
|
3
|
def replace_editor(field_id)
|
4
|
javascript_tag <<-EOT
|
5
|
//#King //2013.09.18
|
6
|
if(!window._ckfinderLoaded) {
|
7
|
document.write('<script src="/ckfinder/ckfinder.js?r=' + Math.random() + '" type="text/javascript"><' + '/script>');
|
8
|
window._ckfinderLoaded = true;
|
9
|
}
|
10
|
|
11
|
$(document).ready(function() {
|
12
|
$(":submit").siblings("a").each(function() {
|
13
|
var a = $(this);
|
14
|
if (a.attr("onclick").indexOf("preview") >= 0) a.hide();
|
15
|
});
|
16
|
|
17
|
var id = '#{field_id}';
|
18
|
var textarea = document.getElementById(id);
|
19
|
if (!textarea) return;
|
20
|
|
21
|
var editor = CKEDITOR.replace(textarea, {
|
22
|
on: {
|
23
|
instanceReady : function(ev) {
|
24
|
var writer = this.dataProcessor.writer;
|
25
|
$.each(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li'],
|
26
|
function() {
|
27
|
writer.setRules(this, { breakAfterOpen : false });
|
28
|
}
|
29
|
);
|
30
|
}
|
31
|
}
|
32
|
});
|
33
|
|
34
|
|
35
|
//#Joshua //2012.10.12
|
36
|
//#King //2013.09.18
|
37
|
var ckfinderpath = "/ckfinder/";
|
38
|
//console.log(ckfinderpath);
|
39
|
CKFinder.setupCKEditor( editor, ckfinderpath ) ;
|
40
|
|
41
|
/*$.getScript("/ckfinder/ckfinder.js", function() {
|
42
|
...
|
43
|
var submit = Form.getInputs(textarea.form, "submit").first();
|
44
|
if (submit) {
|
45
|
submit.nextSiblings().each(function(elem) {
|
46
|
if (elem.nodeName.toLowerCase() != "a") return;
|
47
|
if (elem.onclick.toString().match(/Ajax.Updater.+preview/)){
|
48
|
Element.hide(elem);
|
49
|
return $break;
|
50
|
}
|
51
|
});
|
52
|
}
|
53
|
});*/
|
54
|
|
55
|
|
56
|
// fire change event
|
57
|
RedmineCkeditor.intervalId[id] =
|
58
|
setInterval(function(){ textarea.value = editor.getData(); }, 1000);
|
59
|
});
|
60
|
EOT
|
61
|
end
|
62
|
|
63
|
def set_config
|
64
|
javascript_tag <<-EOT
|
65
|
CKEDITOR.config.contentsCss = "#{stylesheet_path "application"}";
|
66
|
CKEDITOR.config.bodyClass = "wiki";
|
67
|
CKEDITOR.config.toolbar = #{RedmineCkeditorSetting.toolbar.inspect};
|
68
|
CKEDITOR.config.language = "#{current_language.to_s.downcase}";
|
69
|
|
70
|
var RedmineCkeditor = {
|
71
|
intervalId: {}
|
72
|
};
|
73
|
EOT
|
74
|
end
|
75
|
|
76
|
def overwrite_functions
|
77
|
javascript_tag <<-EOT
|
78
|
function showAndScrollTo(id, focus) {
|
79
|
var elem = $("#" + id);
|
80
|
elem.show();
|
81
|
if (focus != null) CKEDITOR.instances[focus].focus();
|
82
|
$('html, body').animate({scrollTop: elem.offset().top}, 100);
|
83
|
}
|
84
|
|
85
|
function destroyEditor(id) {
|
86
|
clearInterval(RedmineCkeditor.intervalId[id])
|
87
|
if (CKEDITOR.instances[id]) CKEDITOR.instances[id].destroy();
|
88
|
}
|
89
|
EOT
|
90
|
end
|
91
|
|
92
|
def initial_setup
|
93
|
javascript_include_tag('ckeditor/ckeditor', :plugin => 'redmine_ckeditor') + set_config + overwrite_functions
|
94
|
end
|
95
|
|
96
|
def wikitoolbar_for(field_id)
|
97
|
if params[:format] == "js"
|
98
|
replace_editor(field_id)
|
99
|
else
|
100
|
initial_setup + replace_editor(field_id)
|
101
|
end
|
102
|
end
|
103
|
|
104
|
def initial_page_content(page)
|
105
|
"<h1>#{ERB::Util.html_escape page.pretty_title}</h1>"
|
106
|
end
|
107
|
|
108
|
def heads_for_wiki_formatter
|
109
|
end
|
110
|
end
|
111
|
end
|