/
helper.rb
179 lines (171 loc) · 8.98 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
# Redmine Wysiwyg Textile Editor
#
# P.J.Lawrence October 2010
#
module RedmineWysiwygTextile
module Helper
unloadable
def wikitoolbar_for(field_id)
if (field_id=='content_text')
# only for wiki pages for now
wikitoolbar_for_wysiwyg(field_id)
else
wikitoolbar_for_non_wysiwyg(field_id)
end
end
def wikitoolbar_for_non_wysiwyg(field_id)
# Is there a simple way to link to a public resource?
url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), url,
:onclick => "window.open(\"#{ url }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/textile') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag("var wikiToolbar = new jsToolBar($('#{field_id}')); wikiToolbar.setHelpLink('#{help_link}'); wikiToolbar.draw();")
end
def wikitoolbar_for_wysiwyg(field_id)
file = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), file,
:onclick => "window.open(\"#{file}\", \"\", \"resizable=yes, location=no, width=800, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
# tinymce and jstoolbar
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/textile') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_include_tag('/tinymce/jscripts/tiny_mce/tiny_mce.js', :plugin => 'redmine_wysiwyg_textile') +
javascript_tag("
var tinyenabled=false;
function setuptinymce() {
tinyMCE.init({
mode : 'specific_textareas',
editor_selector : 'wiki-edit',
formats : {strikethrough : {inline : 'del'},
underline : {inline : 'ins'} },
theme : 'advanced',
plugins : 'table',
theme_advanced_buttons1: 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect',
theme_advanced_buttons3_add : 'tablecontrols',
table_styles : 'Header 1=header1;Header 2=header2;Header 3=header3',
table_cell_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1',
table_row_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1',
table_cell_limit : 100,
table_row_limit : 5,
table_col_limit : 5,
theme_advanced_toolbar_location : 'top',
theme_advanced_toolbar_align : 'left',
theme_advanced_resizing : true
});
}
function toggleEditor(id,DisplayTiny) {
if (DisplayTiny==1 && tinyenabled==false) {
new Ajax.Request('/convert/wysiwygtotextiletohtml', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
setuptinymce();
tinyenabled=true;
the_jstoolbar.toolbar.style.display = 'none';
PreviewElem.onclick=function(){ UpdatePreviewHtml(); }
return;
}
if (!tinyMCE.get(id)) {
if (DisplayTiny==1) {
new Ajax.Request('/convert/wysiwygtotextiletohtml', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
the_jstoolbar.toolbar.style.display = 'none';
tinyMCE.execCommand('mceAddControl', false, id);
PreviewElem.onclick=function(){ UpdatePreviewHtml(); }
}
}
else {
if (DisplayTiny==0) {
tinyMCE.execCommand('mceRemoveControl', false, id);
new Ajax.Request('/convert/wysiwygtohtmltotextile', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
the_jstoolbar.toolbar.style.display = 'block';
PreviewElem.onclick=function(){ eval(TheTextilePreviewFunction) }
}
}
}
function UpdateFile(TheText) {
var text1 = document.getElementById('#{field_id}');
text1.value = TheText.responseText;
if (tinyenabled==true) {
tinyMCE.get('#{field_id}').setContent(TheText.responseText);
}
return true;
}
") +
javascript_tag("
function Tinymcesubmit(id) {
if (tinyMCE.get(id)) {
tinyMCE.execCommand('mceRemoveControl', false, id);
new Ajax.Request('/convert/wysiwygtohtmltotextile', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
the_jstoolbar.toolbar.style.display = 'block';
}
}
function AddWikiformSubmit(textarea) {
var aTextArea=document.getElementById(textarea);
if (aTextArea) {
aform=aTextArea.form;
if (aform) {
aform.onsubmit=function(){return Tinymcesubmit(textarea);};
}
}
}
") +
javascript_tag("
var ThePreviewFunction=null;
var TheTextilePreviewFunction=null;
var PreviewElem=null;
function UpdatePreviewTextile(TheText) {
var text2 = document.getElementById('#{:preview}');
text2.innerHTML = TheText.responseText;
var text3=TheText.responseText;
text3 ='content%5Btext%5D='+escape(text3);
eval(ThePreviewFunction);
return (false);
}
function UpdatePreviewHtml() {
var TheText;
if (tinyenabled==true) {
TheText = tinyMCE.get('#{field_id}').getContent();
TheText ='content%5Btext%5D='+escape(TheText);
new Ajax.Request('/convert/wysiwygtohtmltotextile', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdatePreviewTextile(request)}, parameters:TheText});
}
return (false);
}
function GetPreviewFunction(textarea) {
var elemlist = document.getElementsByName(\"commit\")
var elem=elemlist[0]
do {
elem = elem.nextSibling;
if (elem) {
if (elem.nodeName.toLowerCase() == \"a\") {
if (elem.onclick.toString().match(/Ajax.Updater.+preview/)){
PreviewElem=elem;
TheTextilePreviewFunction=PreviewElem.onclick.toString();
TheTextilePreviewFunction=TheTextilePreviewFunction.replace(\"function onclick(event)\", \"\");
TheTextilePreviewFunction=TheTextilePreviewFunction.replace(\"function anonymous()\", \"\");
TheTextilePreviewFunction=TheTextilePreviewFunction.replace(\"return false;\", \"\");
ThePreviewFunction= TheTextilePreviewFunction.replace(\"Form.serialize(\\\"wiki_form\\\")\", \"text3\");
ThePreviewFunction= ThePreviewFunction.replace(\"Form.serialize(\\'wiki_form\\')\", 'text3');
break;
}
}
}
} while (elem);
}
") +
"<form>
<Input type = radio Name = \"textilewysiwyg\" CHECKED onClick=\"javascript:toggleEditor('#{field_id}',0)\">textile
<Input type = radio Name = \"textilewysiwyg\" onClick=\"javascript:toggleEditor('#{field_id}',1)\">wysiwyg
</form>
<div id='workarea' class='wiki'></div>" +
javascript_tag("var the_jstoolbar = new jsToolBar($('#{field_id}')); the_jstoolbar.setHelpLink('#{help_link}'); the_jstoolbar.draw();GetPreviewFunction('#{field_id}');AddWikiformSubmit('#{field_id}');")
end
def initial_page_content(page)
"h1. #{ERB::Util.html_escape page.pretty_title}"
end
def heads_for_wiki_formatter
stylesheet_link_tag('jstoolbar')
end
end
end