##// END OF EJS Templates
Added tabindex property on wiki toolbar buttons and 'new category' link....
Jean-Philippe Lang -
r1073:d5b9dedca229
parent child
Show More
@@ -1,58 +1,58
1 <%= error_messages_for 'issue' %>
1 <%= error_messages_for 'issue' %>
2 <div class="box">
2 <div class="box">
3
3
4 <% if @issue.new_record? %>
4 <% if @issue.new_record? %>
5 <p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p>
5 <p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p>
6 <%= observe_field :issue_tracker_id, :url => { :action => :new },
6 <%= observe_field :issue_tracker_id, :url => { :action => :new },
7 :update => :content,
7 :update => :content,
8 :with => "Form.serialize('issue-form')" %>
8 :with => "Form.serialize('issue-form')" %>
9 <% end %>
9 <% end %>
10
10
11 <div class="splitcontentleft">
11 <div class="splitcontentleft">
12 <% if @issue.new_record? %>
12 <% if @issue.new_record? %>
13 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
13 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
14 <% else %>
14 <% else %>
15 <p><label><%= l(:field_status) %></label> <%= @issue.status.name %></p>
15 <p><label><%= l(:field_status) %></label> <%= @issue.status.name %></p>
16 <% end %>
16 <% end %>
17
17
18 <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p>
18 <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p>
19 <p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
19 <p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
20 <p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
20 <p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
21 <%= prompt_to_remote(l(:label_issue_category_new),
21 <%= prompt_to_remote(l(:label_issue_category_new),
22 l(:label_issue_category_new), 'category[name]',
22 l(:label_issue_category_new), 'category[name]',
23 {:controller => 'projects', :action => 'add_issue_category', :id => @project},
23 {:controller => 'projects', :action => 'add_issue_category', :id => @project},
24 :class => 'small') if authorize_for('projects', 'add_issue_category') %></p>
24 :class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p>
25 </div>
25 </div>
26
26
27 <div class="splitcontentright">
27 <div class="splitcontentright">
28 <p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p>
28 <p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p>
29 <p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %></p>
29 <p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %></p>
30 <p><%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %></p>
30 <p><%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %></p>
31 <p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
31 <p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
32 </div>
32 </div>
33
33
34 <p><%= f.text_field :subject, :size => 80, :required => true %></p>
34 <p><%= f.text_field :subject, :size => 80, :required => true %></p>
35 <p><%= f.text_area :description, :required => true,
35 <p><%= f.text_area :description, :required => true,
36 :cols => 60,
36 :cols => 60,
37 :rows => (@issue.description.blank? ? 10 : [[10, @issue.description.length / 50].max, 100].min),
37 :rows => (@issue.description.blank? ? 10 : [[10, @issue.description.length / 50].max, 100].min),
38 :accesskey => accesskey(:edit),
38 :accesskey => accesskey(:edit),
39 :class => 'wiki-edit' %></p>
39 :class => 'wiki-edit' %></p>
40 <p><%= f.select :fixed_version_id, (@project.versions.sort.collect {|v| [v.name, v.id]}), { :include_blank => true } %></p>
40 <p><%= f.select :fixed_version_id, (@project.versions.sort.collect {|v| [v.name, v.id]}), { :include_blank => true } %></p>
41
41
42 <%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %>
42 <%= render :partial => 'form_custom_fields', :locals => {:values => @custom_values} %>
43
43
44 <% if @issue.new_record? %>
44 <% if @issue.new_record? %>
45 <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
45 <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>
46 <%= image_to_function "add.png", "addFileField();return false" %></label>
46 <%= image_to_function "add.png", "addFileField();return false" %></label>
47 <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
47 <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
48 <% end %>
48 <% end %>
49 </div>
49 </div>
50
50
51 <%= wikitoolbar_for 'issue_description' %>
51 <%= wikitoolbar_for 'issue_description' %>
52
52
53 <% content_for :header_tags do %>
53 <% content_for :header_tags do %>
54 <%= javascript_include_tag 'calendar/calendar' %>
54 <%= javascript_include_tag 'calendar/calendar' %>
55 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
55 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
56 <%= javascript_include_tag 'calendar/calendar-setup' %>
56 <%= javascript_include_tag 'calendar/calendar-setup' %>
57 <%= stylesheet_link_tag 'calendar' %>
57 <%= stylesheet_link_tag 'calendar' %>
58 <% end %>
58 <% end %>
@@ -1,525 +1,526
1 /* ***** BEGIN LICENSE BLOCK *****
1 /* ***** BEGIN LICENSE BLOCK *****
2 * This file is part of DotClear.
2 * This file is part of DotClear.
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
4 * rights reserved.
4 * rights reserved.
5 *
5 *
6 * DotClear is free software; you can redistribute it and/or modify
6 * DotClear is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
9 * (at your option) any later version.
10 *
10 *
11 * DotClear is distributed in the hope that it will be useful,
11 * DotClear is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
14 * GNU General Public License for more details.
15 *
15 *
16 * You should have received a copy of the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with DotClear; if not, write to the Free Software
17 * along with DotClear; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
19 *
20 * ***** END LICENSE BLOCK *****
20 * ***** END LICENSE BLOCK *****
21 */
21 */
22
22
23 /* Modified by JP LANG for textile formatting */
23 /* Modified by JP LANG for textile formatting */
24
24
25 function jsToolBar(textarea) {
25 function jsToolBar(textarea) {
26 if (!document.createElement) { return; }
26 if (!document.createElement) { return; }
27
27
28 if (!textarea) { return; }
28 if (!textarea) { return; }
29
29
30 if ((typeof(document["selection"]) == "undefined")
30 if ((typeof(document["selection"]) == "undefined")
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
32 return;
32 return;
33 }
33 }
34
34
35 this.textarea = textarea;
35 this.textarea = textarea;
36
36
37 this.editor = document.createElement('div');
37 this.editor = document.createElement('div');
38 this.editor.className = 'jstEditor';
38 this.editor.className = 'jstEditor';
39
39
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
41 this.editor.appendChild(this.textarea);
41 this.editor.appendChild(this.textarea);
42
42
43 this.toolbar = document.createElement("div");
43 this.toolbar = document.createElement("div");
44 this.toolbar.className = 'jstElements';
44 this.toolbar.className = 'jstElements';
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
46
46
47 // Dragable resizing (only for gecko)
47 // Dragable resizing (only for gecko)
48 if (this.editor.addEventListener)
48 if (this.editor.addEventListener)
49 {
49 {
50 this.handle = document.createElement('div');
50 this.handle = document.createElement('div');
51 this.handle.className = 'jstHandle';
51 this.handle.className = 'jstHandle';
52 var dragStart = this.resizeDragStart;
52 var dragStart = this.resizeDragStart;
53 var This = this;
53 var This = this;
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
55 // fix memory leak in Firefox (bug #241518)
55 // fix memory leak in Firefox (bug #241518)
56 window.addEventListener('unload',function() {
56 window.addEventListener('unload',function() {
57 var del = This.handle.parentNode.removeChild(This.handle);
57 var del = This.handle.parentNode.removeChild(This.handle);
58 delete(This.handle);
58 delete(This.handle);
59 },false);
59 },false);
60
60
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
62 }
62 }
63
63
64 this.context = null;
64 this.context = null;
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
67 }
67 }
68
68
69 function jsButton(title, fn, scope, className) {
69 function jsButton(title, fn, scope, className) {
70 if(typeof jsToolBar.strings == 'undefined') {
70 if(typeof jsToolBar.strings == 'undefined') {
71 this.title = title || null;
71 this.title = title || null;
72 } else {
72 } else {
73 this.title = jsToolBar.strings[title] || title || null;
73 this.title = jsToolBar.strings[title] || title || null;
74 }
74 }
75 this.fn = fn || function(){};
75 this.fn = fn || function(){};
76 this.scope = scope || null;
76 this.scope = scope || null;
77 this.className = className || null;
77 this.className = className || null;
78 }
78 }
79 jsButton.prototype.draw = function() {
79 jsButton.prototype.draw = function() {
80 if (!this.scope) return null;
80 if (!this.scope) return null;
81
81
82 var button = document.createElement('button');
82 var button = document.createElement('button');
83 button.setAttribute('type','button');
83 button.setAttribute('type','button');
84 button.tabIndex = 200;
84 if (this.className) button.className = this.className;
85 if (this.className) button.className = this.className;
85 button.title = this.title;
86 button.title = this.title;
86 var span = document.createElement('span');
87 var span = document.createElement('span');
87 span.appendChild(document.createTextNode(this.title));
88 span.appendChild(document.createTextNode(this.title));
88 button.appendChild(span);
89 button.appendChild(span);
89
90
90 if (this.icon != undefined) {
91 if (this.icon != undefined) {
91 button.style.backgroundImage = 'url('+this.icon+')';
92 button.style.backgroundImage = 'url('+this.icon+')';
92 }
93 }
93 if (typeof(this.fn) == 'function') {
94 if (typeof(this.fn) == 'function') {
94 var This = this;
95 var This = this;
95 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
96 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
96 }
97 }
97 return button;
98 return button;
98 }
99 }
99
100
100 function jsSpace(id) {
101 function jsSpace(id) {
101 this.id = id || null;
102 this.id = id || null;
102 this.width = null;
103 this.width = null;
103 }
104 }
104 jsSpace.prototype.draw = function() {
105 jsSpace.prototype.draw = function() {
105 var span = document.createElement('span');
106 var span = document.createElement('span');
106 if (this.id) span.id = this.id;
107 if (this.id) span.id = this.id;
107 span.appendChild(document.createTextNode(String.fromCharCode(160)));
108 span.appendChild(document.createTextNode(String.fromCharCode(160)));
108 span.className = 'jstSpacer';
109 span.className = 'jstSpacer';
109 if (this.width) span.style.marginRight = this.width+'px';
110 if (this.width) span.style.marginRight = this.width+'px';
110
111
111 return span;
112 return span;
112 }
113 }
113
114
114 function jsCombo(title, options, scope, fn, className) {
115 function jsCombo(title, options, scope, fn, className) {
115 this.title = title || null;
116 this.title = title || null;
116 this.options = options || null;
117 this.options = options || null;
117 this.scope = scope || null;
118 this.scope = scope || null;
118 this.fn = fn || function(){};
119 this.fn = fn || function(){};
119 this.className = className || null;
120 this.className = className || null;
120 }
121 }
121 jsCombo.prototype.draw = function() {
122 jsCombo.prototype.draw = function() {
122 if (!this.scope || !this.options) return null;
123 if (!this.scope || !this.options) return null;
123
124
124 var select = document.createElement('select');
125 var select = document.createElement('select');
125 if (this.className) select.className = className;
126 if (this.className) select.className = className;
126 select.title = this.title;
127 select.title = this.title;
127
128
128 for (var o in this.options) {
129 for (var o in this.options) {
129 //var opt = this.options[o];
130 //var opt = this.options[o];
130 var option = document.createElement('option');
131 var option = document.createElement('option');
131 option.value = o;
132 option.value = o;
132 option.appendChild(document.createTextNode(this.options[o]));
133 option.appendChild(document.createTextNode(this.options[o]));
133 select.appendChild(option);
134 select.appendChild(option);
134 }
135 }
135
136
136 var This = this;
137 var This = this;
137 select.onchange = function() {
138 select.onchange = function() {
138 try {
139 try {
139 This.fn.call(This.scope, this.value);
140 This.fn.call(This.scope, this.value);
140 } catch (e) { alert(e); }
141 } catch (e) { alert(e); }
141
142
142 return false;
143 return false;
143 }
144 }
144
145
145 return select;
146 return select;
146 }
147 }
147
148
148
149
149 jsToolBar.prototype = {
150 jsToolBar.prototype = {
150 base_url: '',
151 base_url: '',
151 mode: 'wiki',
152 mode: 'wiki',
152 elements: {},
153 elements: {},
153
154
154 getMode: function() {
155 getMode: function() {
155 return this.mode;
156 return this.mode;
156 },
157 },
157
158
158 setMode: function(mode) {
159 setMode: function(mode) {
159 this.mode = mode || 'wiki';
160 this.mode = mode || 'wiki';
160 },
161 },
161
162
162 switchMode: function(mode) {
163 switchMode: function(mode) {
163 mode = mode || 'wiki';
164 mode = mode || 'wiki';
164 this.draw(mode);
165 this.draw(mode);
165 },
166 },
166
167
167 button: function(toolName) {
168 button: function(toolName) {
168 var tool = this.elements[toolName];
169 var tool = this.elements[toolName];
169 if (typeof tool.fn[this.mode] != 'function') return null;
170 if (typeof tool.fn[this.mode] != 'function') return null;
170 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
171 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
171 if (tool.icon != undefined) b.icon = tool.icon;
172 if (tool.icon != undefined) b.icon = tool.icon;
172 return b;
173 return b;
173 },
174 },
174 space: function(toolName) {
175 space: function(toolName) {
175 var tool = new jsSpace(toolName)
176 var tool = new jsSpace(toolName)
176 if (this.elements[toolName].width !== undefined)
177 if (this.elements[toolName].width !== undefined)
177 tool.width = this.elements[toolName].width;
178 tool.width = this.elements[toolName].width;
178 return tool;
179 return tool;
179 },
180 },
180 combo: function(toolName) {
181 combo: function(toolName) {
181 var tool = this.elements[toolName];
182 var tool = this.elements[toolName];
182 var length = tool[this.mode].list.length;
183 var length = tool[this.mode].list.length;
183
184
184 if (typeof tool[this.mode].fn != 'function' || length == 0) {
185 if (typeof tool[this.mode].fn != 'function' || length == 0) {
185 return null;
186 return null;
186 } else {
187 } else {
187 var options = {};
188 var options = {};
188 for (var i=0; i < length; i++) {
189 for (var i=0; i < length; i++) {
189 var opt = tool[this.mode].list[i];
190 var opt = tool[this.mode].list[i];
190 options[opt] = tool.options[opt];
191 options[opt] = tool.options[opt];
191 }
192 }
192 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
193 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
193 }
194 }
194 },
195 },
195 draw: function(mode) {
196 draw: function(mode) {
196 this.setMode(mode);
197 this.setMode(mode);
197
198
198 // Empty toolbar
199 // Empty toolbar
199 while (this.toolbar.hasChildNodes()) {
200 while (this.toolbar.hasChildNodes()) {
200 this.toolbar.removeChild(this.toolbar.firstChild)
201 this.toolbar.removeChild(this.toolbar.firstChild)
201 }
202 }
202 this.toolNodes = {}; // vide les raccourcis DOM/**/
203 this.toolNodes = {}; // vide les raccourcis DOM/**/
203
204
204 // Draw toolbar elements
205 // Draw toolbar elements
205 var b, tool, newTool;
206 var b, tool, newTool;
206
207
207 for (var i in this.elements) {
208 for (var i in this.elements) {
208 b = this.elements[i];
209 b = this.elements[i];
209
210
210 var disabled =
211 var disabled =
211 b.type == undefined || b.type == ''
212 b.type == undefined || b.type == ''
212 || (b.disabled != undefined && b.disabled)
213 || (b.disabled != undefined && b.disabled)
213 || (b.context != undefined && b.context != null && b.context != this.context);
214 || (b.context != undefined && b.context != null && b.context != this.context);
214
215
215 if (!disabled && typeof this[b.type] == 'function') {
216 if (!disabled && typeof this[b.type] == 'function') {
216 tool = this[b.type](i);
217 tool = this[b.type](i);
217 if (tool) newTool = tool.draw();
218 if (tool) newTool = tool.draw();
218 if (newTool) {
219 if (newTool) {
219 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
220 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
220 this.toolbar.appendChild(newTool);
221 this.toolbar.appendChild(newTool);
221 }
222 }
222 }
223 }
223 }
224 }
224 },
225 },
225
226
226 singleTag: function(stag,etag) {
227 singleTag: function(stag,etag) {
227 stag = stag || null;
228 stag = stag || null;
228 etag = etag || stag;
229 etag = etag || stag;
229
230
230 if (!stag || !etag) { return; }
231 if (!stag || !etag) { return; }
231
232
232 this.encloseSelection(stag,etag);
233 this.encloseSelection(stag,etag);
233 },
234 },
234
235
235 encloseLineSelection: function(prefix, suffix, fn) {
236 encloseLineSelection: function(prefix, suffix, fn) {
236 this.textarea.focus();
237 this.textarea.focus();
237
238
238 prefix = prefix || '';
239 prefix = prefix || '';
239 suffix = suffix || '';
240 suffix = suffix || '';
240
241
241 var start, end, sel, scrollPos, subst, res;
242 var start, end, sel, scrollPos, subst, res;
242
243
243 if (typeof(document["selection"]) != "undefined") {
244 if (typeof(document["selection"]) != "undefined") {
244 sel = document.selection.createRange().text;
245 sel = document.selection.createRange().text;
245 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
246 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
246 start = this.textarea.selectionStart;
247 start = this.textarea.selectionStart;
247 end = this.textarea.selectionEnd;
248 end = this.textarea.selectionEnd;
248 scrollPos = this.textarea.scrollTop;
249 scrollPos = this.textarea.scrollTop;
249 // go to the start of the line
250 // go to the start of the line
250 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
251 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
251 // go to the end of the line
252 // go to the end of the line
252 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
253 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
253 sel = this.textarea.value.substring(start, end);
254 sel = this.textarea.value.substring(start, end);
254 }
255 }
255
256
256 if (sel.match(/ $/)) { // exclude ending space char, if any
257 if (sel.match(/ $/)) { // exclude ending space char, if any
257 sel = sel.substring(0, sel.length - 1);
258 sel = sel.substring(0, sel.length - 1);
258 suffix = suffix + " ";
259 suffix = suffix + " ";
259 }
260 }
260
261
261 if (typeof(fn) == 'function') {
262 if (typeof(fn) == 'function') {
262 res = (sel) ? fn.call(this,sel) : fn('');
263 res = (sel) ? fn.call(this,sel) : fn('');
263 } else {
264 } else {
264 res = (sel) ? sel : '';
265 res = (sel) ? sel : '';
265 }
266 }
266
267
267 subst = prefix + res + suffix;
268 subst = prefix + res + suffix;
268
269
269 if (typeof(document["selection"]) != "undefined") {
270 if (typeof(document["selection"]) != "undefined") {
270 document.selection.createRange().text = subst;
271 document.selection.createRange().text = subst;
271 var range = this.textarea.createTextRange();
272 var range = this.textarea.createTextRange();
272 range.collapse(false);
273 range.collapse(false);
273 range.move('character', -suffix.length);
274 range.move('character', -suffix.length);
274 range.select();
275 range.select();
275 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
276 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
276 this.textarea.value = this.textarea.value.substring(0, start) + subst +
277 this.textarea.value = this.textarea.value.substring(0, start) + subst +
277 this.textarea.value.substring(end);
278 this.textarea.value.substring(end);
278 if (sel) {
279 if (sel) {
279 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
280 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
280 } else {
281 } else {
281 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
282 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
282 }
283 }
283 this.textarea.scrollTop = scrollPos;
284 this.textarea.scrollTop = scrollPos;
284 }
285 }
285 },
286 },
286
287
287 encloseSelection: function(prefix, suffix, fn) {
288 encloseSelection: function(prefix, suffix, fn) {
288 this.textarea.focus();
289 this.textarea.focus();
289
290
290 prefix = prefix || '';
291 prefix = prefix || '';
291 suffix = suffix || '';
292 suffix = suffix || '';
292
293
293 var start, end, sel, scrollPos, subst, res;
294 var start, end, sel, scrollPos, subst, res;
294
295
295 if (typeof(document["selection"]) != "undefined") {
296 if (typeof(document["selection"]) != "undefined") {
296 sel = document.selection.createRange().text;
297 sel = document.selection.createRange().text;
297 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
298 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
298 start = this.textarea.selectionStart;
299 start = this.textarea.selectionStart;
299 end = this.textarea.selectionEnd;
300 end = this.textarea.selectionEnd;
300 scrollPos = this.textarea.scrollTop;
301 scrollPos = this.textarea.scrollTop;
301 sel = this.textarea.value.substring(start, end);
302 sel = this.textarea.value.substring(start, end);
302 }
303 }
303
304
304 if (sel.match(/ $/)) { // exclude ending space char, if any
305 if (sel.match(/ $/)) { // exclude ending space char, if any
305 sel = sel.substring(0, sel.length - 1);
306 sel = sel.substring(0, sel.length - 1);
306 suffix = suffix + " ";
307 suffix = suffix + " ";
307 }
308 }
308
309
309 if (typeof(fn) == 'function') {
310 if (typeof(fn) == 'function') {
310 res = (sel) ? fn.call(this,sel) : fn('');
311 res = (sel) ? fn.call(this,sel) : fn('');
311 } else {
312 } else {
312 res = (sel) ? sel : '';
313 res = (sel) ? sel : '';
313 }
314 }
314
315
315 subst = prefix + res + suffix;
316 subst = prefix + res + suffix;
316
317
317 if (typeof(document["selection"]) != "undefined") {
318 if (typeof(document["selection"]) != "undefined") {
318 document.selection.createRange().text = subst;
319 document.selection.createRange().text = subst;
319 var range = this.textarea.createTextRange();
320 var range = this.textarea.createTextRange();
320 range.collapse(false);
321 range.collapse(false);
321 range.move('character', -suffix.length);
322 range.move('character', -suffix.length);
322 range.select();
323 range.select();
323 // this.textarea.caretPos -= suffix.length;
324 // this.textarea.caretPos -= suffix.length;
324 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
325 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
325 this.textarea.value = this.textarea.value.substring(0, start) + subst +
326 this.textarea.value = this.textarea.value.substring(0, start) + subst +
326 this.textarea.value.substring(end);
327 this.textarea.value.substring(end);
327 if (sel) {
328 if (sel) {
328 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
329 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
329 } else {
330 } else {
330 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
331 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
331 }
332 }
332 this.textarea.scrollTop = scrollPos;
333 this.textarea.scrollTop = scrollPos;
333 }
334 }
334 },
335 },
335
336
336 stripBaseURL: function(url) {
337 stripBaseURL: function(url) {
337 if (this.base_url != '') {
338 if (this.base_url != '') {
338 var pos = url.indexOf(this.base_url);
339 var pos = url.indexOf(this.base_url);
339 if (pos == 0) {
340 if (pos == 0) {
340 url = url.substr(this.base_url.length);
341 url = url.substr(this.base_url.length);
341 }
342 }
342 }
343 }
343
344
344 return url;
345 return url;
345 }
346 }
346 };
347 };
347
348
348 /** Resizer
349 /** Resizer
349 -------------------------------------------------------- */
350 -------------------------------------------------------- */
350 jsToolBar.prototype.resizeSetStartH = function() {
351 jsToolBar.prototype.resizeSetStartH = function() {
351 this.dragStartH = this.textarea.offsetHeight + 0;
352 this.dragStartH = this.textarea.offsetHeight + 0;
352 };
353 };
353 jsToolBar.prototype.resizeDragStart = function(event) {
354 jsToolBar.prototype.resizeDragStart = function(event) {
354 var This = this;
355 var This = this;
355 this.dragStartY = event.clientY;
356 this.dragStartY = event.clientY;
356 this.resizeSetStartH();
357 this.resizeSetStartH();
357 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
358 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
358 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
359 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
359 };
360 };
360
361
361 jsToolBar.prototype.resizeDragMove = function(event) {
362 jsToolBar.prototype.resizeDragMove = function(event) {
362 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
363 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
363 };
364 };
364
365
365 jsToolBar.prototype.resizeDragStop = function(event) {
366 jsToolBar.prototype.resizeDragStop = function(event) {
366 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
367 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
367 document.removeEventListener('mouseup', this.dragStopHdlr, false);
368 document.removeEventListener('mouseup', this.dragStopHdlr, false);
368 };
369 };
369
370
370 // Elements definition ------------------------------------
371 // Elements definition ------------------------------------
371
372
372 // strong
373 // strong
373 jsToolBar.prototype.elements.strong = {
374 jsToolBar.prototype.elements.strong = {
374 type: 'button',
375 type: 'button',
375 title: 'Strong',
376 title: 'Strong',
376 fn: {
377 fn: {
377 wiki: function() { this.singleTag('*') }
378 wiki: function() { this.singleTag('*') }
378 }
379 }
379 }
380 }
380
381
381 // em
382 // em
382 jsToolBar.prototype.elements.em = {
383 jsToolBar.prototype.elements.em = {
383 type: 'button',
384 type: 'button',
384 title: 'Italic',
385 title: 'Italic',
385 fn: {
386 fn: {
386 wiki: function() { this.singleTag("_") }
387 wiki: function() { this.singleTag("_") }
387 }
388 }
388 }
389 }
389
390
390 // ins
391 // ins
391 jsToolBar.prototype.elements.ins = {
392 jsToolBar.prototype.elements.ins = {
392 type: 'button',
393 type: 'button',
393 title: 'Underline',
394 title: 'Underline',
394 fn: {
395 fn: {
395 wiki: function() { this.singleTag('+') }
396 wiki: function() { this.singleTag('+') }
396 }
397 }
397 }
398 }
398
399
399 // del
400 // del
400 jsToolBar.prototype.elements.del = {
401 jsToolBar.prototype.elements.del = {
401 type: 'button',
402 type: 'button',
402 title: 'Deleted',
403 title: 'Deleted',
403 fn: {
404 fn: {
404 wiki: function() { this.singleTag('-') }
405 wiki: function() { this.singleTag('-') }
405 }
406 }
406 }
407 }
407
408
408 // quote
409 // quote
409 jsToolBar.prototype.elements.quote = {
410 jsToolBar.prototype.elements.quote = {
410 type: 'button',
411 type: 'button',
411 title: 'Inline quote',
412 title: 'Inline quote',
412 fn: {
413 fn: {
413 wiki: function() { this.singleTag('??') }
414 wiki: function() { this.singleTag('??') }
414 }
415 }
415 }
416 }
416
417
417 // code
418 // code
418 jsToolBar.prototype.elements.code = {
419 jsToolBar.prototype.elements.code = {
419 type: 'button',
420 type: 'button',
420 title: 'Code',
421 title: 'Code',
421 fn: {
422 fn: {
422 wiki: function() { this.singleTag('@') }
423 wiki: function() { this.singleTag('@') }
423 }
424 }
424 }
425 }
425
426
426 // spacer
427 // spacer
427 jsToolBar.prototype.elements.space1 = {type: 'space'}
428 jsToolBar.prototype.elements.space1 = {type: 'space'}
428
429
429 // headings
430 // headings
430 jsToolBar.prototype.elements.h1 = {
431 jsToolBar.prototype.elements.h1 = {
431 type: 'button',
432 type: 'button',
432 title: 'Heading 1',
433 title: 'Heading 1',
433 fn: {
434 fn: {
434 wiki: function() {
435 wiki: function() {
435 this.encloseLineSelection('h1. ', '',function(str) {
436 this.encloseLineSelection('h1. ', '',function(str) {
436 str = str.replace(/^h\d+\.\s+/, '')
437 str = str.replace(/^h\d+\.\s+/, '')
437 return str;
438 return str;
438 });
439 });
439 }
440 }
440 }
441 }
441 }
442 }
442 jsToolBar.prototype.elements.h2 = {
443 jsToolBar.prototype.elements.h2 = {
443 type: 'button',
444 type: 'button',
444 title: 'Heading 2',
445 title: 'Heading 2',
445 fn: {
446 fn: {
446 wiki: function() {
447 wiki: function() {
447 this.encloseLineSelection('h2. ', '',function(str) {
448 this.encloseLineSelection('h2. ', '',function(str) {
448 str = str.replace(/^h\d+\.\s+/, '')
449 str = str.replace(/^h\d+\.\s+/, '')
449 return str;
450 return str;
450 });
451 });
451 }
452 }
452 }
453 }
453 }
454 }
454 jsToolBar.prototype.elements.h3 = {
455 jsToolBar.prototype.elements.h3 = {
455 type: 'button',
456 type: 'button',
456 title: 'Heading 3',
457 title: 'Heading 3',
457 fn: {
458 fn: {
458 wiki: function() {
459 wiki: function() {
459 this.encloseLineSelection('h3. ', '',function(str) {
460 this.encloseLineSelection('h3. ', '',function(str) {
460 str = str.replace(/^h\d+\.\s+/, '')
461 str = str.replace(/^h\d+\.\s+/, '')
461 return str;
462 return str;
462 });
463 });
463 }
464 }
464 }
465 }
465 }
466 }
466
467
467 // spacer
468 // spacer
468 jsToolBar.prototype.elements.space2 = {type: 'space'}
469 jsToolBar.prototype.elements.space2 = {type: 'space'}
469
470
470 // ul
471 // ul
471 jsToolBar.prototype.elements.ul = {
472 jsToolBar.prototype.elements.ul = {
472 type: 'button',
473 type: 'button',
473 title: 'Unordered list',
474 title: 'Unordered list',
474 fn: {
475 fn: {
475 wiki: function() {
476 wiki: function() {
476 this.encloseLineSelection('','',function(str) {
477 this.encloseLineSelection('','',function(str) {
477 str = str.replace(/\r/g,'');
478 str = str.replace(/\r/g,'');
478 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
479 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
479 });
480 });
480 }
481 }
481 }
482 }
482 }
483 }
483
484
484 // ol
485 // ol
485 jsToolBar.prototype.elements.ol = {
486 jsToolBar.prototype.elements.ol = {
486 type: 'button',
487 type: 'button',
487 title: 'Ordered list',
488 title: 'Ordered list',
488 fn: {
489 fn: {
489 wiki: function() {
490 wiki: function() {
490 this.encloseLineSelection('','',function(str) {
491 this.encloseLineSelection('','',function(str) {
491 str = str.replace(/\r/g,'');
492 str = str.replace(/\r/g,'');
492 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
493 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
493 });
494 });
494 }
495 }
495 }
496 }
496 }
497 }
497
498
498 // pre
499 // pre
499 jsToolBar.prototype.elements.pre = {
500 jsToolBar.prototype.elements.pre = {
500 type: 'button',
501 type: 'button',
501 title: 'Preformatted text',
502 title: 'Preformatted text',
502 fn: {
503 fn: {
503 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
504 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
504 }
505 }
505 }
506 }
506
507
507 // spacer
508 // spacer
508 jsToolBar.prototype.elements.space3 = {type: 'space'}
509 jsToolBar.prototype.elements.space3 = {type: 'space'}
509
510
510 // wiki page
511 // wiki page
511 jsToolBar.prototype.elements.link = {
512 jsToolBar.prototype.elements.link = {
512 type: 'button',
513 type: 'button',
513 title: 'Wiki link',
514 title: 'Wiki link',
514 fn: {
515 fn: {
515 wiki: function() { this.encloseSelection("[[", "]]") }
516 wiki: function() { this.encloseSelection("[[", "]]") }
516 }
517 }
517 }
518 }
518 // image
519 // image
519 jsToolBar.prototype.elements.img = {
520 jsToolBar.prototype.elements.img = {
520 type: 'button',
521 type: 'button',
521 title: 'Image',
522 title: 'Image',
522 fn: {
523 fn: {
523 wiki: function() { this.encloseSelection("!", "!") }
524 wiki: function() { this.encloseSelection("!", "!") }
524 }
525 }
525 }
526 }
General Comments 0
You need to be logged in to leave comments. Login now