@@ -1,461 +1,466 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module ApplicationHelper |
|
19 | 19 | include Redmine::WikiFormatting::Macros::Definitions |
|
20 | 20 | |
|
21 | 21 | def current_role |
|
22 | 22 | @current_role ||= User.current.role_for_project(@project) |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | # Return true if user is authorized for controller/action, otherwise false |
|
26 | 26 | def authorize_for(controller, action) |
|
27 | 27 | User.current.allowed_to?({:controller => controller, :action => action}, @project) |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | # Display a link if user is authorized |
|
31 | 31 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
32 | 32 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | # Display a link to user's account page |
|
36 | 36 | def link_to_user(user) |
|
37 | 37 | user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous' |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def link_to_issue(issue) |
|
41 | 41 | link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def toggle_link(name, id, options={}) |
|
45 | 45 | onclick = "Element.toggle('#{id}'); " |
|
46 | 46 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
47 | 47 | onclick << "return false;" |
|
48 | 48 | link_to(name, "#", :onclick => onclick) |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def show_and_goto_link(name, id, options={}) |
|
52 | 52 | onclick = "Element.show('#{id}'); " |
|
53 | 53 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
54 | 54 | onclick << "Element.scrollTo('#{id}'); " |
|
55 | 55 | onclick << "return false;" |
|
56 | 56 | link_to(name, "#", options.merge(:onclick => onclick)) |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def image_to_function(name, function, html_options = {}) |
|
60 | 60 | html_options.symbolize_keys! |
|
61 | 61 | tag(:input, html_options.merge({ |
|
62 | 62 | :type => "image", :src => image_path(name), |
|
63 | 63 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" |
|
64 | 64 | })) |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def prompt_to_remote(name, text, param, url, html_options = {}) |
|
68 | 68 | html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;" |
|
69 | 69 | link_to name, {}, html_options |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def format_date(date) |
|
73 | 73 | return nil unless date |
|
74 | 74 | # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed) |
|
75 | 75 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
76 | 76 | date.strftime(@date_format) |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def format_time(time, include_date = true) |
|
80 | 80 | return nil unless time |
|
81 | 81 | time = time.to_time if time.is_a?(String) |
|
82 | 82 | zone = User.current.time_zone |
|
83 | 83 | if time.utc? |
|
84 | 84 | local = zone ? zone.adjust(time) : time.getlocal |
|
85 | 85 | else |
|
86 | 86 | local = zone ? zone.adjust(time.getutc) : time |
|
87 | 87 | end |
|
88 | 88 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
89 | 89 | @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) |
|
90 | 90 | include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def html_hours(text) |
|
94 | 94 | text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>') |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def authoring(created, author) |
|
98 | 98 | time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) |
|
99 | 99 | l(:label_added_time_by, author || 'Anonymous', time_tag) |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def l_or_humanize(s) |
|
103 | 103 | l_has_string?("label_#{s}".to_sym) ? l("label_#{s}".to_sym) : s.to_s.humanize |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def day_name(day) |
|
107 | 107 | l(:general_day_names).split(',')[day-1] |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def month_name(month) |
|
111 | 111 | l(:actionview_datehelper_select_month_names).split(',')[month-1] |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def pagination_links_full(paginator, count=nil, options={}) |
|
115 | 115 | page_param = options.delete(:page_param) || :page |
|
116 | 116 | url_param = params.dup |
|
117 | 117 | # don't reuse params if filters are present |
|
118 | 118 | url_param.clear if url_param.has_key?(:set_filter) |
|
119 | 119 | |
|
120 | 120 | html = '' |
|
121 | 121 | html << link_to_remote(('« ' + l(:label_previous)), |
|
122 | 122 | {:update => 'content', |
|
123 | 123 | :url => url_param.merge(page_param => paginator.current.previous), |
|
124 | 124 | :complete => 'window.scrollTo(0,0)'}, |
|
125 | 125 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous |
|
126 | 126 | |
|
127 | 127 | html << (pagination_links_each(paginator, options) do |n| |
|
128 | 128 | link_to_remote(n.to_s, |
|
129 | 129 | {:url => {:params => url_param.merge(page_param => n)}, |
|
130 | 130 | :update => 'content', |
|
131 | 131 | :complete => 'window.scrollTo(0,0)'}, |
|
132 | 132 | {:href => url_for(:params => url_param.merge(page_param => n))}) |
|
133 | 133 | end || '') |
|
134 | 134 | |
|
135 | 135 | html << ' ' + link_to_remote((l(:label_next) + ' »'), |
|
136 | 136 | {:update => 'content', |
|
137 | 137 | :url => url_param.merge(page_param => paginator.current.next), |
|
138 | 138 | :complete => 'window.scrollTo(0,0)'}, |
|
139 | 139 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next |
|
140 | 140 | |
|
141 | 141 | unless count.nil? |
|
142 | 142 | html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ') |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | html |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | def per_page_links(selected=nil) |
|
149 | 149 | url_param = params.dup |
|
150 | 150 | url_param.clear if url_param.has_key?(:set_filter) |
|
151 | 151 | |
|
152 | 152 | links = Setting.per_page_options_array.collect do |n| |
|
153 | 153 | n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)}, |
|
154 | 154 | {:href => url_for(url_param.merge(:per_page => n))}) |
|
155 | 155 | end |
|
156 | 156 | links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def html_title(*args) |
|
160 | 160 | if args.empty? |
|
161 | 161 | title = [] |
|
162 | 162 | title << @project.name if @project |
|
163 | 163 | title += @html_title if @html_title |
|
164 | 164 | title << Setting.app_title |
|
165 | 165 | title.compact.join(' - ') |
|
166 | 166 | else |
|
167 | 167 | @html_title ||= [] |
|
168 | 168 | @html_title += args |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def accesskey(s) |
|
173 | 173 | Redmine::AccessKeys.key_for s |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | # Formats text according to system settings. |
|
177 | 177 | # 2 ways to call this method: |
|
178 | 178 | # * with a String: textilizable(text, options) |
|
179 | 179 | # * with an object and one of its attribute: textilizable(issue, :description, options) |
|
180 | 180 | def textilizable(*args) |
|
181 | 181 | options = args.last.is_a?(Hash) ? args.pop : {} |
|
182 | 182 | case args.size |
|
183 | 183 | when 1 |
|
184 | 184 | obj = nil |
|
185 | 185 | text = args.shift |
|
186 | 186 | when 2 |
|
187 | 187 | obj = args.shift |
|
188 | 188 | text = obj.send(args.shift).to_s |
|
189 | 189 | else |
|
190 | 190 | raise ArgumentError, 'invalid arguments to textilizable' |
|
191 | 191 | end |
|
192 | 192 | return '' if text.blank? |
|
193 | 193 | |
|
194 | 194 | only_path = options.delete(:only_path) == false ? false : true |
|
195 | 195 | |
|
196 | 196 | # when using an image link, try to use an attachment, if possible |
|
197 | 197 | attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) |
|
198 | 198 | |
|
199 | 199 | if attachments |
|
200 | 200 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m| |
|
201 | 201 | style = $1 |
|
202 | 202 | filename = $6 |
|
203 | 203 | rf = Regexp.new(filename, Regexp::IGNORECASE) |
|
204 | 204 | # search for the picture in attachments |
|
205 | 205 | if found = attachments.detect { |att| att.filename =~ rf } |
|
206 | 206 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found.id |
|
207 | 207 | "!#{style}#{image_url}!" |
|
208 | 208 | else |
|
209 | 209 | "!#{style}#{filename}!" |
|
210 | 210 | end |
|
211 | 211 | end |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | text = (Setting.text_formatting == 'textile') ? |
|
215 | 215 | Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : |
|
216 | 216 | simple_format(auto_link(h(text))) |
|
217 | 217 | |
|
218 | 218 | # different methods for formatting wiki links |
|
219 | 219 | case options[:wiki_links] |
|
220 | 220 | when :local |
|
221 | 221 | # used for local links to html files |
|
222 | 222 | format_wiki_link = Proc.new {|project, title| "#{title}.html" } |
|
223 | 223 | when :anchor |
|
224 | 224 | # used for single-file wiki export |
|
225 | 225 | format_wiki_link = Proc.new {|project, title| "##{title}" } |
|
226 | 226 | else |
|
227 | 227 | format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) } |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
|
231 | 231 | |
|
232 | 232 | # Wiki links |
|
233 | 233 | # |
|
234 | 234 | # Examples: |
|
235 | 235 | # [[mypage]] |
|
236 | 236 | # [[mypage|mytext]] |
|
237 | 237 | # wiki links can refer other project wikis, using project name or identifier: |
|
238 | 238 | # [[project:]] -> wiki starting page |
|
239 | 239 | # [[project:|mytext]] |
|
240 | 240 | # [[project:mypage]] |
|
241 | 241 | # [[project:mypage|mytext]] |
|
242 | 242 | text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m| |
|
243 | 243 | link_project = project |
|
244 | 244 | esc, all, page, title = $1, $2, $3, $5 |
|
245 | 245 | if esc.nil? |
|
246 | 246 | if page =~ /^([^\:]+)\:(.*)$/ |
|
247 | 247 | link_project = Project.find_by_name($1) || Project.find_by_identifier($1) |
|
248 | 248 | page = $2 |
|
249 | 249 | title ||= $1 if page.blank? |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | if link_project && link_project.wiki |
|
253 | 253 | # check if page exists |
|
254 | 254 | wiki_page = link_project.wiki.find_page(page) |
|
255 | 255 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), |
|
256 | 256 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
257 | 257 | else |
|
258 | 258 | # project or wiki doesn't exist |
|
259 | 259 | title || page |
|
260 | 260 | end |
|
261 | 261 | else |
|
262 | 262 | all |
|
263 | 263 | end |
|
264 | 264 | end |
|
265 | 265 | |
|
266 | 266 | # Redmine links |
|
267 | 267 | # |
|
268 | 268 | # Examples: |
|
269 | 269 | # Issues: |
|
270 | 270 | # #52 -> Link to issue #52 |
|
271 | 271 | # Changesets: |
|
272 | 272 | # r52 -> Link to revision 52 |
|
273 | 273 | # Documents: |
|
274 | 274 | # document#17 -> Link to document with id 17 |
|
275 | 275 | # document:Greetings -> Link to the document with title "Greetings" |
|
276 | 276 | # document:"Some document" -> Link to the document with title "Some document" |
|
277 | 277 | # Versions: |
|
278 | 278 | # version#3 -> Link to version with id 3 |
|
279 | 279 | # version:1.0.0 -> Link to version named "1.0.0" |
|
280 | 280 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" |
|
281 | 281 | # Attachments: |
|
282 | 282 | # attachment:file.zip -> Link to the attachment of the current object named file.zip |
|
283 | 283 | text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m| |
|
284 | 284 | leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 |
|
285 | 285 | link = nil |
|
286 | 286 | if esc.nil? |
|
287 | 287 | if prefix.nil? && sep == 'r' |
|
288 | 288 | if project && (changeset = project.changesets.find_by_revision(oid)) |
|
289 | 289 | link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, |
|
290 | 290 | :class => 'changeset', |
|
291 | 291 | :title => truncate(changeset.comments, 100)) |
|
292 | 292 | end |
|
293 | 293 | elsif sep == '#' |
|
294 | 294 | oid = oid.to_i |
|
295 | 295 | case prefix |
|
296 | 296 | when nil |
|
297 | 297 | if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current)) |
|
298 | 298 | link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, |
|
299 | 299 | :class => 'issue', |
|
300 | 300 | :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})") |
|
301 | 301 | link = content_tag('del', link) if issue.closed? |
|
302 | 302 | end |
|
303 | 303 | when 'document' |
|
304 | 304 | if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
305 | 305 | link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
|
306 | 306 | :class => 'document' |
|
307 | 307 | end |
|
308 | 308 | when 'version' |
|
309 | 309 | if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
310 | 310 | link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
|
311 | 311 | :class => 'version' |
|
312 | 312 | end |
|
313 | 313 | end |
|
314 | 314 | elsif sep == ':' |
|
315 | 315 | # removes the double quotes if any |
|
316 | 316 | name = oid.gsub(%r{^"(.*)"$}, "\\1") |
|
317 | 317 | case prefix |
|
318 | 318 | when 'document' |
|
319 | 319 | if project && document = project.documents.find_by_title(name) |
|
320 | 320 | link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
|
321 | 321 | :class => 'document' |
|
322 | 322 | end |
|
323 | 323 | when 'version' |
|
324 | 324 | if project && version = project.versions.find_by_name(name) |
|
325 | 325 | link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
|
326 | 326 | :class => 'version' |
|
327 | 327 | end |
|
328 | 328 | when 'attachment' |
|
329 | 329 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
330 | 330 | link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, |
|
331 | 331 | :class => 'attachment' |
|
332 | 332 | end |
|
333 | 333 | end |
|
334 | 334 | end |
|
335 | 335 | end |
|
336 | 336 | leading + (link || "#{prefix}#{sep}#{oid}") |
|
337 | 337 | end |
|
338 | 338 | |
|
339 | 339 | text |
|
340 | 340 | end |
|
341 | 341 | |
|
342 | 342 | # Same as Rails' simple_format helper without using paragraphs |
|
343 | 343 | def simple_format_without_paragraph(text) |
|
344 | 344 | text.to_s. |
|
345 | 345 | gsub(/\r\n?/, "\n"). # \r\n and \r -> \n |
|
346 | 346 | gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br |
|
347 | 347 | gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br |
|
348 | 348 | end |
|
349 | 349 | |
|
350 | 350 | def error_messages_for(object_name, options = {}) |
|
351 | 351 | options = options.symbolize_keys |
|
352 | 352 | object = instance_variable_get("@#{object_name}") |
|
353 | 353 | if object && !object.errors.empty? |
|
354 | 354 | # build full_messages here with controller current language |
|
355 | 355 | full_messages = [] |
|
356 | 356 | object.errors.each do |attr, msg| |
|
357 | 357 | next if msg.nil? |
|
358 | 358 | msg = msg.first if msg.is_a? Array |
|
359 | 359 | if attr == "base" |
|
360 | 360 | full_messages << l(msg) |
|
361 | 361 | else |
|
362 | 362 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" |
|
363 | 363 | end |
|
364 | 364 | end |
|
365 | 365 | # retrieve custom values error messages |
|
366 | 366 | if object.errors[:custom_values] |
|
367 | 367 | object.custom_values.each do |v| |
|
368 | 368 | v.errors.each do |attr, msg| |
|
369 | 369 | next if msg.nil? |
|
370 | 370 | msg = msg.first if msg.is_a? Array |
|
371 | 371 | full_messages << "« " + v.custom_field.name + " » " + l(msg) |
|
372 | 372 | end |
|
373 | 373 | end |
|
374 | 374 | end |
|
375 | 375 | content_tag("div", |
|
376 | 376 | content_tag( |
|
377 | 377 | options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":" |
|
378 | 378 | ) + |
|
379 | 379 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), |
|
380 | 380 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" |
|
381 | 381 | ) |
|
382 | 382 | else |
|
383 | 383 | "" |
|
384 | 384 | end |
|
385 | 385 | end |
|
386 | 386 | |
|
387 | 387 | def lang_options_for_select(blank=true) |
|
388 | 388 | (blank ? [["(auto)", ""]] : []) + |
|
389 | 389 | GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last } |
|
390 | 390 | end |
|
391 | 391 | |
|
392 | 392 | def label_tag_for(name, option_tags = nil, options = {}) |
|
393 | 393 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
394 | 394 | content_tag("label", label_text) |
|
395 | 395 | end |
|
396 | 396 | |
|
397 | 397 | def labelled_tabular_form_for(name, object, options, &proc) |
|
398 | 398 | options[:html] ||= {} |
|
399 | 399 | options[:html][:class] = 'tabular' unless options[:html].has_key?(:class) |
|
400 | 400 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) |
|
401 | 401 | end |
|
402 | 402 | |
|
403 | 403 | def check_all_links(form_name) |
|
404 | 404 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
405 | 405 | " | " + |
|
406 | 406 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
407 | 407 | end |
|
408 | 408 | |
|
409 | 409 | def progress_bar(pcts, options={}) |
|
410 | 410 | pcts = [pcts, pcts] unless pcts.is_a?(Array) |
|
411 | 411 | pcts[1] = pcts[1] - pcts[0] |
|
412 | 412 | pcts << (100 - pcts[1] - pcts[0]) |
|
413 | 413 | width = options[:width] || '100px;' |
|
414 | 414 | legend = options[:legend] || '' |
|
415 | 415 | content_tag('table', |
|
416 | 416 | content_tag('tr', |
|
417 | 417 | (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') + |
|
418 | 418 | (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') + |
|
419 | 419 | (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '') |
|
420 | 420 | ), :class => 'progress', :style => "width: #{width};") + |
|
421 | 421 | content_tag('p', legend, :class => 'pourcent') |
|
422 | 422 | end |
|
423 | 423 | |
|
424 | 424 | def context_menu_link(name, url, options={}) |
|
425 | 425 | options[:class] ||= '' |
|
426 | 426 | if options.delete(:selected) |
|
427 | 427 | options[:class] << ' icon-checked disabled' |
|
428 | 428 | options[:disabled] = true |
|
429 | 429 | end |
|
430 | 430 | if options.delete(:disabled) |
|
431 | 431 | options.delete(:method) |
|
432 | 432 | options.delete(:confirm) |
|
433 | 433 | options.delete(:onclick) |
|
434 | 434 | options[:class] << ' disabled' |
|
435 | 435 | url = '#' |
|
436 | 436 | end |
|
437 | 437 | link_to name, url, options |
|
438 | 438 | end |
|
439 | 439 | |
|
440 | 440 | def calendar_for(field_id) |
|
441 | 441 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + |
|
442 | 442 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") |
|
443 | 443 | end |
|
444 | 444 | |
|
445 | 445 | def wikitoolbar_for(field_id) |
|
446 | 446 | return '' unless Setting.text_formatting == 'textile' |
|
447 | ||
|
448 | help_link = l(:setting_text_formatting) + ': ' + | |
|
449 | link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'), | |
|
450 | :onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;") | |
|
451 | ||
|
447 | 452 | javascript_include_tag('jstoolbar/jstoolbar') + |
|
448 | 453 | javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") + |
|
449 | javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();") | |
|
454 | javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();") | |
|
450 | 455 | end |
|
451 | 456 | |
|
452 | 457 | def content_for(name, content = nil, &block) |
|
453 | 458 | @has_content ||= {} |
|
454 | 459 | @has_content[name] = true |
|
455 | 460 | super(name, content, &block) |
|
456 | 461 | end |
|
457 | 462 | |
|
458 | 463 | def has_content?(name) |
|
459 | 464 | (@has_content && @has_content[name]) || false |
|
460 | 465 | end |
|
461 | 466 | end |
@@ -1,30 +1,26 | |||
|
1 | 1 | <h2><%= @page.pretty_title %></h2> |
|
2 | 2 | |
|
3 | 3 | <% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> |
|
4 | 4 | <%= f.hidden_field :version %> |
|
5 | 5 | <%= error_messages_for 'content' %> |
|
6 | <div class="contextual"> | |
|
7 | <%= l(:setting_text_formatting) %>: | |
|
8 | <%= link_to l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'), | |
|
9 | :onclick => "window.open('#{ compute_public_path('wiki_syntax', 'help', 'html') }', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;" %> | |
|
10 | </div> | |
|
6 | ||
|
11 | 7 | <p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p> |
|
12 | 8 | <p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p> |
|
13 | 9 | <p><%= submit_tag l(:button_save) %> |
|
14 | 10 | <%= link_to_remote l(:label_preview), |
|
15 | 11 | { :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, |
|
16 | 12 | :method => 'post', |
|
17 | 13 | :update => 'preview', |
|
18 | 14 | :with => "Form.serialize('wiki_form')", |
|
19 | 15 | :complete => "Element.scrollTo('preview')" |
|
20 | 16 | }, :accesskey => accesskey(:preview) %></p> |
|
21 | 17 | <%= wikitoolbar_for 'content_text' %> |
|
22 | 18 | <% end %> |
|
23 | 19 | |
|
24 | 20 | <div id="preview" class="wiki"></div> |
|
25 | 21 | |
|
26 | 22 | <% content_for :header_tags do %> |
|
27 | 23 | <%= stylesheet_link_tag 'scm' %> |
|
28 | 24 | <% end %> |
|
29 | 25 | |
|
30 | 26 | <% html_title @page.pretty_title %> |
@@ -1,59 +1,64 | |||
|
1 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
2 | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|
3 | 3 | <head> |
|
4 | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
5 | 5 | <meta http-equiv="Content-Style-Type" content="text/css" /> |
|
6 | 6 | <title>Wiki formatting</title> |
|
7 | <link rel="stylesheet" href="html.css" type="text/css" /> | |
|
8 | 7 | <style type="text/css"> |
|
9 | 8 | h1 { font-family: Verdana, sans-serif; font-size: 14px; text-align: center; color: #444; } |
|
10 |
|
|
|
9 | body { font-family: Verdana, sans-serif; font-size: 12px; color: #444; } | |
|
10 | table th { padding-top: 1em; } | |
|
11 | 11 | table td { vertical-align: top; background-color: #f5f5f5; height: 2em; vertical-align: middle;} |
|
12 | 12 | table td code { font-size: 1.2em; } |
|
13 | 13 | table td h1 { font-size: 1.8em; text-align: left; } |
|
14 | 14 | table td h2 { font-size: 1.4em; text-align: left; } |
|
15 | 15 | table td h3 { font-size: 1.2em; text-align: left; } |
|
16 | 16 | |
|
17 | 17 | </style> |
|
18 | 18 | </head> |
|
19 | 19 | <body> |
|
20 | 20 | |
|
21 | 21 | <h1>Wiki Syntax Quick Reference</h1> |
|
22 | 22 | |
|
23 | 23 | <table width="100%"> |
|
24 | 24 | <tr><th colspan="3">Font Styles</th></tr> |
|
25 | 25 | <tr><th><img src="../../images/jstoolbar/bt_strong.png" style="border: 1px solid #bbb;" alt="Strong" /></th><td width="50%">*Strong*</td><td width="50%"><strong>Strong</strong></td></tr> |
|
26 | 26 | <tr><th><img src="../../images/jstoolbar/bt_em.png" style="border: 1px solid #bbb;" alt="Italic" /></th><td>_Italic_</td><td><em>Italic</em></td></tr> |
|
27 | 27 | <tr><th><img src="../../images/jstoolbar/bt_ins.png" style="border: 1px solid #bbb;" alt="Underline" /></th><td>+Underline+</td><td><ins>Underline</ins></td></tr> |
|
28 | 28 | <tr><th><img src="../../images/jstoolbar/bt_del.png" style="border: 1px solid #bbb;" alt="Deleted" /></th><td>-Deleted-</td><td><del>Deleted</del></td></tr> |
|
29 | 29 | <tr><th></th><td>??Quote??</td><td><cite>Quote</cite></td></tr> |
|
30 | 30 | <tr><th><img src="../../images/jstoolbar/bt_code.png" style="border: 1px solid #bbb;" alt="Inline Code" /></th><td>@Inline Code@</td><td><code>Inline Code</code></td></tr> |
|
31 | 31 | <tr><th><img src="../../images/jstoolbar/bt_pre.png" style="border: 1px solid #bbb;" alt="Preformatted text" /></th><td><pre><br /> lines<br /> of code<br /></pre></td><td> |
|
32 | 32 | <pre> |
|
33 | 33 | lines |
|
34 | 34 | of code |
|
35 | 35 | </pre> |
|
36 | 36 | </td></tr> |
|
37 | 37 | |
|
38 | 38 | <tr><th colspan="3">Lists</th></tr> |
|
39 | 39 | <tr><th><img src="../../images/jstoolbar/bt_ul.png" style="border: 1px solid #bbb;" alt="Unordered list" /></th><td>* Item 1<br />* Item 2</td><td><ul><li>Item 1</li><li>Item 2</li></ul></td></tr> |
|
40 | 40 | <tr><th><img src="../../images/jstoolbar/bt_ol.png" style="border: 1px solid #bbb;" alt="Ordered list" /></th><td># Item 1<br /># Item 2</td><td><ol><li>Item 1</li><li>Item 2</li></ol></td></tr> |
|
41 | 41 | |
|
42 | 42 | <tr><th colspan="3">Headings</th></tr> |
|
43 | 43 | <tr><th><img src="../../images/jstoolbar/bt_h1.png" style="border: 1px solid #bbb;" alt="Heading 1" /></th><td>h1. Title 1</td><td><h1>Title 1</h1></td></tr> |
|
44 | 44 | <tr><th><img src="../../images/jstoolbar/bt_h2.png" style="border: 1px solid #bbb;" alt="Heading 2" /></th><td>h2. Title 2</td><td><h2>Title 2</h2></td></tr> |
|
45 | 45 | <tr><th><img src="../../images/jstoolbar/bt_h3.png" style="border: 1px solid #bbb;" alt="Heading 3" /></th><td>h3. Title 3</td><td><h3>Title 3</h3></td></tr> |
|
46 | 46 | |
|
47 | 47 | <tr><th colspan="3">Links</th></tr> |
|
48 | 48 | <tr><th></th><td>http://foo.bar</td><td><a href="#">http://foo.bar</a></td></tr> |
|
49 | <tr><th></th><td>"Foo":http://foo.bar</td><td><a href="#">Foo</a></td></tr> | |
|
50 | ||
|
51 | <tr><th colspan="3">Redmine links</th></tr> | |
|
49 | 52 | <tr><th><img src="../../images/jstoolbar/bt_link.png" style="border: 1px solid #bbb;" alt="Link to a Wiki page" /></th><td>[[Wiki page]]</td><td><a href="#">Wiki page</a></td></tr> |
|
50 | 53 | <tr><th></th><td>Issue #12</td><td>Issue <a href="#">#12</a></td></tr> |
|
51 | 54 | <tr><th></th><td>Revision r43</td><td>Revision <a href="#">r43</a></td></tr> |
|
52 | 55 | |
|
53 | 56 | <tr><th colspan="3">Inline images</th></tr> |
|
54 | 57 | <tr><th><img src="../../images/jstoolbar/bt_img.png" style="border: 1px solid #bbb;" alt="Image" /></th><td>!<em>image_url</em>!</td><td></td></tr> |
|
55 | 58 | <tr><th></th><td>!<em>attached_image</em>!</td><td></td></tr> |
|
56 | 59 | </table> |
|
57 | 60 | |
|
61 | <p><a href="http://www.redmine.org/wiki/redmine/RedmineWikiFormatting" onclick="window.open('http://www.redmine.org/wiki/redmine/RedmineWikiFormatting', '', ''); return false;">More Information</a></p> | |
|
62 | ||
|
58 | 63 | </body> |
|
59 | 64 | </html> |
@@ -1,517 +1,528 | |||
|
1 | 1 | /* ***** BEGIN LICENSE BLOCK ***** |
|
2 | 2 | * This file is part of DotClear. |
|
3 | 3 | * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All |
|
4 | 4 | * rights reserved. |
|
5 | 5 | * |
|
6 | 6 | * DotClear is free software; you can redistribute it and/or modify |
|
7 | 7 | * it under the terms of the GNU General Public License as published by |
|
8 | 8 | * the Free Software Foundation; either version 2 of the License, or |
|
9 | 9 | * (at your option) any later version. |
|
10 | 10 | * |
|
11 | 11 | * DotClear is distributed in the hope that it will be useful, |
|
12 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | * GNU General Public License for more details. |
|
15 | 15 | * |
|
16 | 16 | * You should have received a copy of the GNU General Public License |
|
17 | 17 | * along with DotClear; if not, write to the Free Software |
|
18 | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | 19 | * |
|
20 | 20 | * ***** END LICENSE BLOCK ***** |
|
21 | 21 | */ |
|
22 | 22 | |
|
23 | 23 | /* Modified by JP LANG for textile formatting */ |
|
24 | 24 | |
|
25 | 25 | function jsToolBar(textarea) { |
|
26 | 26 | if (!document.createElement) { return; } |
|
27 | 27 | |
|
28 | 28 | if (!textarea) { return; } |
|
29 | 29 | |
|
30 | 30 | if ((typeof(document["selection"]) == "undefined") |
|
31 | 31 | && (typeof(textarea["setSelectionRange"]) == "undefined")) { |
|
32 | 32 | return; |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | this.textarea = textarea; |
|
36 | 36 | |
|
37 | 37 | this.editor = document.createElement('div'); |
|
38 | 38 | this.editor.className = 'jstEditor'; |
|
39 | 39 | |
|
40 | 40 | this.textarea.parentNode.insertBefore(this.editor,this.textarea); |
|
41 | 41 | this.editor.appendChild(this.textarea); |
|
42 | 42 | |
|
43 | 43 | this.toolbar = document.createElement("div"); |
|
44 | 44 | this.toolbar.className = 'jstElements'; |
|
45 | 45 | this.editor.parentNode.insertBefore(this.toolbar,this.editor); |
|
46 | 46 | |
|
47 | 47 | // Dragable resizing (only for gecko) |
|
48 | 48 | if (this.editor.addEventListener) |
|
49 | 49 | { |
|
50 | 50 | this.handle = document.createElement('div'); |
|
51 | 51 | this.handle.className = 'jstHandle'; |
|
52 | 52 | var dragStart = this.resizeDragStart; |
|
53 | 53 | var This = this; |
|
54 | 54 | this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false); |
|
55 | 55 | // fix memory leak in Firefox (bug #241518) |
|
56 | 56 | window.addEventListener('unload',function() { |
|
57 | 57 | var del = This.handle.parentNode.removeChild(This.handle); |
|
58 | 58 | delete(This.handle); |
|
59 | 59 | },false); |
|
60 | 60 | |
|
61 | 61 | this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | this.context = null; |
|
65 | 65 | this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni |
|
66 | 66 | // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils. |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | function jsButton(title, fn, scope, className) { |
|
70 | 70 | if(typeof jsToolBar.strings == 'undefined') { |
|
71 | 71 | this.title = title || null; |
|
72 | 72 | } else { |
|
73 | 73 | this.title = jsToolBar.strings[title] || title || null; |
|
74 | 74 | } |
|
75 | 75 | this.fn = fn || function(){}; |
|
76 | 76 | this.scope = scope || null; |
|
77 | 77 | this.className = className || null; |
|
78 | 78 | } |
|
79 | 79 | jsButton.prototype.draw = function() { |
|
80 | 80 | if (!this.scope) return null; |
|
81 | 81 | |
|
82 | 82 | var button = document.createElement('button'); |
|
83 | 83 | button.setAttribute('type','button'); |
|
84 | 84 | button.tabIndex = 200; |
|
85 | 85 | if (this.className) button.className = this.className; |
|
86 | 86 | button.title = this.title; |
|
87 | 87 | var span = document.createElement('span'); |
|
88 | 88 | span.appendChild(document.createTextNode(this.title)); |
|
89 | 89 | button.appendChild(span); |
|
90 | 90 | |
|
91 | 91 | if (this.icon != undefined) { |
|
92 | 92 | button.style.backgroundImage = 'url('+this.icon+')'; |
|
93 | 93 | } |
|
94 | 94 | if (typeof(this.fn) == 'function') { |
|
95 | 95 | var This = this; |
|
96 | 96 | button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; }; |
|
97 | 97 | } |
|
98 | 98 | return button; |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | function jsSpace(id) { |
|
102 | 102 | this.id = id || null; |
|
103 | 103 | this.width = null; |
|
104 | 104 | } |
|
105 | 105 | jsSpace.prototype.draw = function() { |
|
106 | 106 | var span = document.createElement('span'); |
|
107 | 107 | if (this.id) span.id = this.id; |
|
108 | 108 | span.appendChild(document.createTextNode(String.fromCharCode(160))); |
|
109 | 109 | span.className = 'jstSpacer'; |
|
110 | 110 | if (this.width) span.style.marginRight = this.width+'px'; |
|
111 | 111 | |
|
112 | 112 | return span; |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | function jsCombo(title, options, scope, fn, className) { |
|
116 | 116 | this.title = title || null; |
|
117 | 117 | this.options = options || null; |
|
118 | 118 | this.scope = scope || null; |
|
119 | 119 | this.fn = fn || function(){}; |
|
120 | 120 | this.className = className || null; |
|
121 | 121 | } |
|
122 | 122 | jsCombo.prototype.draw = function() { |
|
123 | 123 | if (!this.scope || !this.options) return null; |
|
124 | 124 | |
|
125 | 125 | var select = document.createElement('select'); |
|
126 | 126 | if (this.className) select.className = className; |
|
127 | 127 | select.title = this.title; |
|
128 | 128 | |
|
129 | 129 | for (var o in this.options) { |
|
130 | 130 | //var opt = this.options[o]; |
|
131 | 131 | var option = document.createElement('option'); |
|
132 | 132 | option.value = o; |
|
133 | 133 | option.appendChild(document.createTextNode(this.options[o])); |
|
134 | 134 | select.appendChild(option); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | var This = this; |
|
138 | 138 | select.onchange = function() { |
|
139 | 139 | try { |
|
140 | 140 | This.fn.call(This.scope, this.value); |
|
141 | 141 | } catch (e) { alert(e); } |
|
142 | 142 | |
|
143 | 143 | return false; |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | return select; |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | |
|
150 | 150 | jsToolBar.prototype = { |
|
151 | 151 | base_url: '', |
|
152 | 152 | mode: 'wiki', |
|
153 | 153 | elements: {}, |
|
154 | help_link: '', | |
|
154 | 155 | |
|
155 | 156 | getMode: function() { |
|
156 | 157 | return this.mode; |
|
157 | 158 | }, |
|
158 | 159 | |
|
159 | 160 | setMode: function(mode) { |
|
160 | 161 | this.mode = mode || 'wiki'; |
|
161 | 162 | }, |
|
162 | 163 | |
|
163 | 164 | switchMode: function(mode) { |
|
164 | 165 | mode = mode || 'wiki'; |
|
165 | 166 | this.draw(mode); |
|
166 | 167 | }, |
|
167 | 168 | |
|
169 | setHelpLink: function(link) { | |
|
170 | this.help_link = link; | |
|
171 | }, | |
|
172 | ||
|
168 | 173 | button: function(toolName) { |
|
169 | 174 | var tool = this.elements[toolName]; |
|
170 | 175 | if (typeof tool.fn[this.mode] != 'function') return null; |
|
171 | 176 | var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName); |
|
172 | 177 | if (tool.icon != undefined) b.icon = tool.icon; |
|
173 | 178 | return b; |
|
174 | 179 | }, |
|
175 | 180 | space: function(toolName) { |
|
176 | 181 | var tool = new jsSpace(toolName) |
|
177 | 182 | if (this.elements[toolName].width !== undefined) |
|
178 | 183 | tool.width = this.elements[toolName].width; |
|
179 | 184 | return tool; |
|
180 | 185 | }, |
|
181 | 186 | combo: function(toolName) { |
|
182 | 187 | var tool = this.elements[toolName]; |
|
183 | 188 | var length = tool[this.mode].list.length; |
|
184 | 189 | |
|
185 | 190 | if (typeof tool[this.mode].fn != 'function' || length == 0) { |
|
186 | 191 | return null; |
|
187 | 192 | } else { |
|
188 | 193 | var options = {}; |
|
189 | 194 | for (var i=0; i < length; i++) { |
|
190 | 195 | var opt = tool[this.mode].list[i]; |
|
191 | 196 | options[opt] = tool.options[opt]; |
|
192 | 197 | } |
|
193 | 198 | return new jsCombo(tool.title, options, this, tool[this.mode].fn); |
|
194 | 199 | } |
|
195 | 200 | }, |
|
196 | 201 | draw: function(mode) { |
|
197 | 202 | this.setMode(mode); |
|
198 | 203 | |
|
199 | 204 | // Empty toolbar |
|
200 | 205 | while (this.toolbar.hasChildNodes()) { |
|
201 | 206 | this.toolbar.removeChild(this.toolbar.firstChild) |
|
202 | 207 | } |
|
203 | 208 | this.toolNodes = {}; // vide les raccourcis DOM/**/ |
|
204 | ||
|
209 | ||
|
210 | var h = document.createElement('div'); | |
|
211 | h.className = 'help' | |
|
212 | h.innerHTML = this.help_link; | |
|
213 | '<a href="/help/wiki_syntax.html" onclick="window.open(\'/help/wiki_syntax.html\', \'\', \'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\'); return false;">Aide</a>'; | |
|
214 | this.toolbar.appendChild(h); | |
|
215 | ||
|
205 | 216 | // Draw toolbar elements |
|
206 | 217 | var b, tool, newTool; |
|
207 | 218 | |
|
208 | 219 | for (var i in this.elements) { |
|
209 | 220 | b = this.elements[i]; |
|
210 | 221 | |
|
211 | 222 | var disabled = |
|
212 | 223 | b.type == undefined || b.type == '' |
|
213 | 224 | || (b.disabled != undefined && b.disabled) |
|
214 | 225 | || (b.context != undefined && b.context != null && b.context != this.context); |
|
215 | 226 | |
|
216 | 227 | if (!disabled && typeof this[b.type] == 'function') { |
|
217 | 228 | tool = this[b.type](i); |
|
218 | 229 | if (tool) newTool = tool.draw(); |
|
219 | 230 | if (newTool) { |
|
220 | 231 | this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur |
|
221 | 232 | this.toolbar.appendChild(newTool); |
|
222 | 233 | } |
|
223 | 234 | } |
|
224 | 235 | } |
|
225 | 236 | }, |
|
226 | 237 | |
|
227 | 238 | singleTag: function(stag,etag) { |
|
228 | 239 | stag = stag || null; |
|
229 | 240 | etag = etag || stag; |
|
230 | 241 | |
|
231 | 242 | if (!stag || !etag) { return; } |
|
232 | 243 | |
|
233 | 244 | this.encloseSelection(stag,etag); |
|
234 | 245 | }, |
|
235 | 246 | |
|
236 | 247 | encloseLineSelection: function(prefix, suffix, fn) { |
|
237 | 248 | this.textarea.focus(); |
|
238 | 249 | |
|
239 | 250 | prefix = prefix || ''; |
|
240 | 251 | suffix = suffix || ''; |
|
241 | 252 | |
|
242 | 253 | var start, end, sel, scrollPos, subst, res; |
|
243 | 254 | |
|
244 | 255 | if (typeof(document["selection"]) != "undefined") { |
|
245 | 256 | sel = document.selection.createRange().text; |
|
246 | 257 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
247 | 258 | start = this.textarea.selectionStart; |
|
248 | 259 | end = this.textarea.selectionEnd; |
|
249 | 260 | scrollPos = this.textarea.scrollTop; |
|
250 | 261 | // go to the start of the line |
|
251 | 262 | start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length; |
|
252 | 263 | // go to the end of the line |
|
253 | 264 | end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length; |
|
254 | 265 | sel = this.textarea.value.substring(start, end); |
|
255 | 266 | } |
|
256 | 267 | |
|
257 | 268 | if (sel.match(/ $/)) { // exclude ending space char, if any |
|
258 | 269 | sel = sel.substring(0, sel.length - 1); |
|
259 | 270 | suffix = suffix + " "; |
|
260 | 271 | } |
|
261 | 272 | |
|
262 | 273 | if (typeof(fn) == 'function') { |
|
263 | 274 | res = (sel) ? fn.call(this,sel) : fn(''); |
|
264 | 275 | } else { |
|
265 | 276 | res = (sel) ? sel : ''; |
|
266 | 277 | } |
|
267 | 278 | |
|
268 | 279 | subst = prefix + res + suffix; |
|
269 | 280 | |
|
270 | 281 | if (typeof(document["selection"]) != "undefined") { |
|
271 | 282 | document.selection.createRange().text = subst; |
|
272 | 283 | var range = this.textarea.createTextRange(); |
|
273 | 284 | range.collapse(false); |
|
274 | 285 | range.move('character', -suffix.length); |
|
275 | 286 | range.select(); |
|
276 | 287 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
277 | 288 | this.textarea.value = this.textarea.value.substring(0, start) + subst + |
|
278 | 289 | this.textarea.value.substring(end); |
|
279 | 290 | if (sel) { |
|
280 | 291 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); |
|
281 | 292 | } else { |
|
282 | 293 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); |
|
283 | 294 | } |
|
284 | 295 | this.textarea.scrollTop = scrollPos; |
|
285 | 296 | } |
|
286 | 297 | }, |
|
287 | 298 | |
|
288 | 299 | encloseSelection: function(prefix, suffix, fn) { |
|
289 | 300 | this.textarea.focus(); |
|
290 | 301 | |
|
291 | 302 | prefix = prefix || ''; |
|
292 | 303 | suffix = suffix || ''; |
|
293 | 304 | |
|
294 | 305 | var start, end, sel, scrollPos, subst, res; |
|
295 | 306 | |
|
296 | 307 | if (typeof(document["selection"]) != "undefined") { |
|
297 | 308 | sel = document.selection.createRange().text; |
|
298 | 309 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
299 | 310 | start = this.textarea.selectionStart; |
|
300 | 311 | end = this.textarea.selectionEnd; |
|
301 | 312 | scrollPos = this.textarea.scrollTop; |
|
302 | 313 | sel = this.textarea.value.substring(start, end); |
|
303 | 314 | } |
|
304 | 315 | |
|
305 | 316 | if (sel.match(/ $/)) { // exclude ending space char, if any |
|
306 | 317 | sel = sel.substring(0, sel.length - 1); |
|
307 | 318 | suffix = suffix + " "; |
|
308 | 319 | } |
|
309 | 320 | |
|
310 | 321 | if (typeof(fn) == 'function') { |
|
311 | 322 | res = (sel) ? fn.call(this,sel) : fn(''); |
|
312 | 323 | } else { |
|
313 | 324 | res = (sel) ? sel : ''; |
|
314 | 325 | } |
|
315 | 326 | |
|
316 | 327 | subst = prefix + res + suffix; |
|
317 | 328 | |
|
318 | 329 | if (typeof(document["selection"]) != "undefined") { |
|
319 | 330 | document.selection.createRange().text = subst; |
|
320 | 331 | var range = this.textarea.createTextRange(); |
|
321 | 332 | range.collapse(false); |
|
322 | 333 | range.move('character', -suffix.length); |
|
323 | 334 | range.select(); |
|
324 | 335 | // this.textarea.caretPos -= suffix.length; |
|
325 | 336 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
326 | 337 | this.textarea.value = this.textarea.value.substring(0, start) + subst + |
|
327 | 338 | this.textarea.value.substring(end); |
|
328 | 339 | if (sel) { |
|
329 | 340 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); |
|
330 | 341 | } else { |
|
331 | 342 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); |
|
332 | 343 | } |
|
333 | 344 | this.textarea.scrollTop = scrollPos; |
|
334 | 345 | } |
|
335 | 346 | }, |
|
336 | 347 | |
|
337 | 348 | stripBaseURL: function(url) { |
|
338 | 349 | if (this.base_url != '') { |
|
339 | 350 | var pos = url.indexOf(this.base_url); |
|
340 | 351 | if (pos == 0) { |
|
341 | 352 | url = url.substr(this.base_url.length); |
|
342 | 353 | } |
|
343 | 354 | } |
|
344 | 355 | |
|
345 | 356 | return url; |
|
346 | 357 | } |
|
347 | 358 | }; |
|
348 | 359 | |
|
349 | 360 | /** Resizer |
|
350 | 361 | -------------------------------------------------------- */ |
|
351 | 362 | jsToolBar.prototype.resizeSetStartH = function() { |
|
352 | 363 | this.dragStartH = this.textarea.offsetHeight + 0; |
|
353 | 364 | }; |
|
354 | 365 | jsToolBar.prototype.resizeDragStart = function(event) { |
|
355 | 366 | var This = this; |
|
356 | 367 | this.dragStartY = event.clientY; |
|
357 | 368 | this.resizeSetStartH(); |
|
358 | 369 | document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false); |
|
359 | 370 | document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false); |
|
360 | 371 | }; |
|
361 | 372 | |
|
362 | 373 | jsToolBar.prototype.resizeDragMove = function(event) { |
|
363 | 374 | this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; |
|
364 | 375 | }; |
|
365 | 376 | |
|
366 | 377 | jsToolBar.prototype.resizeDragStop = function(event) { |
|
367 | 378 | document.removeEventListener('mousemove', this.dragMoveHdlr, false); |
|
368 | 379 | document.removeEventListener('mouseup', this.dragStopHdlr, false); |
|
369 | 380 | }; |
|
370 | 381 | |
|
371 | 382 | // Elements definition ------------------------------------ |
|
372 | 383 | |
|
373 | 384 | // strong |
|
374 | 385 | jsToolBar.prototype.elements.strong = { |
|
375 | 386 | type: 'button', |
|
376 | 387 | title: 'Strong', |
|
377 | 388 | fn: { |
|
378 | 389 | wiki: function() { this.singleTag('*') } |
|
379 | 390 | } |
|
380 | 391 | } |
|
381 | 392 | |
|
382 | 393 | // em |
|
383 | 394 | jsToolBar.prototype.elements.em = { |
|
384 | 395 | type: 'button', |
|
385 | 396 | title: 'Italic', |
|
386 | 397 | fn: { |
|
387 | 398 | wiki: function() { this.singleTag("_") } |
|
388 | 399 | } |
|
389 | 400 | } |
|
390 | 401 | |
|
391 | 402 | // ins |
|
392 | 403 | jsToolBar.prototype.elements.ins = { |
|
393 | 404 | type: 'button', |
|
394 | 405 | title: 'Underline', |
|
395 | 406 | fn: { |
|
396 | 407 | wiki: function() { this.singleTag('+') } |
|
397 | 408 | } |
|
398 | 409 | } |
|
399 | 410 | |
|
400 | 411 | // del |
|
401 | 412 | jsToolBar.prototype.elements.del = { |
|
402 | 413 | type: 'button', |
|
403 | 414 | title: 'Deleted', |
|
404 | 415 | fn: { |
|
405 | 416 | wiki: function() { this.singleTag('-') } |
|
406 | 417 | } |
|
407 | 418 | } |
|
408 | 419 | |
|
409 | 420 | // code |
|
410 | 421 | jsToolBar.prototype.elements.code = { |
|
411 | 422 | type: 'button', |
|
412 | 423 | title: 'Code', |
|
413 | 424 | fn: { |
|
414 | 425 | wiki: function() { this.singleTag('@') } |
|
415 | 426 | } |
|
416 | 427 | } |
|
417 | 428 | |
|
418 | 429 | // spacer |
|
419 | 430 | jsToolBar.prototype.elements.space1 = {type: 'space'} |
|
420 | 431 | |
|
421 | 432 | // headings |
|
422 | 433 | jsToolBar.prototype.elements.h1 = { |
|
423 | 434 | type: 'button', |
|
424 | 435 | title: 'Heading 1', |
|
425 | 436 | fn: { |
|
426 | 437 | wiki: function() { |
|
427 | 438 | this.encloseLineSelection('h1. ', '',function(str) { |
|
428 | 439 | str = str.replace(/^h\d+\.\s+/, '') |
|
429 | 440 | return str; |
|
430 | 441 | }); |
|
431 | 442 | } |
|
432 | 443 | } |
|
433 | 444 | } |
|
434 | 445 | jsToolBar.prototype.elements.h2 = { |
|
435 | 446 | type: 'button', |
|
436 | 447 | title: 'Heading 2', |
|
437 | 448 | fn: { |
|
438 | 449 | wiki: function() { |
|
439 | 450 | this.encloseLineSelection('h2. ', '',function(str) { |
|
440 | 451 | str = str.replace(/^h\d+\.\s+/, '') |
|
441 | 452 | return str; |
|
442 | 453 | }); |
|
443 | 454 | } |
|
444 | 455 | } |
|
445 | 456 | } |
|
446 | 457 | jsToolBar.prototype.elements.h3 = { |
|
447 | 458 | type: 'button', |
|
448 | 459 | title: 'Heading 3', |
|
449 | 460 | fn: { |
|
450 | 461 | wiki: function() { |
|
451 | 462 | this.encloseLineSelection('h3. ', '',function(str) { |
|
452 | 463 | str = str.replace(/^h\d+\.\s+/, '') |
|
453 | 464 | return str; |
|
454 | 465 | }); |
|
455 | 466 | } |
|
456 | 467 | } |
|
457 | 468 | } |
|
458 | 469 | |
|
459 | 470 | // spacer |
|
460 | 471 | jsToolBar.prototype.elements.space2 = {type: 'space'} |
|
461 | 472 | |
|
462 | 473 | // ul |
|
463 | 474 | jsToolBar.prototype.elements.ul = { |
|
464 | 475 | type: 'button', |
|
465 | 476 | title: 'Unordered list', |
|
466 | 477 | fn: { |
|
467 | 478 | wiki: function() { |
|
468 | 479 | this.encloseLineSelection('','',function(str) { |
|
469 | 480 | str = str.replace(/\r/g,''); |
|
470 | 481 | return str.replace(/(\n|^)[#-]?\s*/g,"$1* "); |
|
471 | 482 | }); |
|
472 | 483 | } |
|
473 | 484 | } |
|
474 | 485 | } |
|
475 | 486 | |
|
476 | 487 | // ol |
|
477 | 488 | jsToolBar.prototype.elements.ol = { |
|
478 | 489 | type: 'button', |
|
479 | 490 | title: 'Ordered list', |
|
480 | 491 | fn: { |
|
481 | 492 | wiki: function() { |
|
482 | 493 | this.encloseLineSelection('','',function(str) { |
|
483 | 494 | str = str.replace(/\r/g,''); |
|
484 | 495 | return str.replace(/(\n|^)[*-]?\s*/g,"$1# "); |
|
485 | 496 | }); |
|
486 | 497 | } |
|
487 | 498 | } |
|
488 | 499 | } |
|
489 | 500 | |
|
490 | 501 | // pre |
|
491 | 502 | jsToolBar.prototype.elements.pre = { |
|
492 | 503 | type: 'button', |
|
493 | 504 | title: 'Preformatted text', |
|
494 | 505 | fn: { |
|
495 | 506 | wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') } |
|
496 | 507 | } |
|
497 | 508 | } |
|
498 | 509 | |
|
499 | 510 | // spacer |
|
500 | 511 | jsToolBar.prototype.elements.space3 = {type: 'space'} |
|
501 | 512 | |
|
502 | 513 | // wiki page |
|
503 | 514 | jsToolBar.prototype.elements.link = { |
|
504 | 515 | type: 'button', |
|
505 | 516 | title: 'Wiki link', |
|
506 | 517 | fn: { |
|
507 | 518 | wiki: function() { this.encloseSelection("[[", "]]") } |
|
508 | 519 | } |
|
509 | 520 | } |
|
510 | 521 | // image |
|
511 | 522 | jsToolBar.prototype.elements.img = { |
|
512 | 523 | type: 'button', |
|
513 | 524 | title: 'Image', |
|
514 | 525 | fn: { |
|
515 | 526 | wiki: function() { this.encloseSelection("!", "!") } |
|
516 | 527 | } |
|
517 | 528 | } |
@@ -1,93 +1,95 | |||
|
1 | 1 | .jstEditor { |
|
2 | 2 | padding-left: 0px; |
|
3 | 3 | } |
|
4 | 4 | .jstEditor textarea, .jstEditor iframe { |
|
5 | 5 | margin: 0; |
|
6 | 6 | } |
|
7 | 7 | |
|
8 | 8 | .jstHandle { |
|
9 | 9 | height: 10px; |
|
10 | 10 | font-size: 0.1em; |
|
11 | 11 | cursor: s-resize; |
|
12 | 12 | /*background: transparent url(img/resizer.png) no-repeat 45% 50%;*/ |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 15 | .jstElements { |
|
16 | 16 | padding: 3px 3px; |
|
17 | 17 | } |
|
18 | 18 | |
|
19 | 19 | .jstElements button { |
|
20 | 20 | margin-right : 6px; |
|
21 | 21 | width : 24px; |
|
22 | 22 | height: 24px; |
|
23 | 23 | padding: 4px; |
|
24 | 24 | border-style: solid; |
|
25 | 25 | border-width: 1px; |
|
26 | 26 | border-color: #ddd; |
|
27 | 27 | background-color : #f7f7f7; |
|
28 | 28 | background-position : 50% 50%; |
|
29 | 29 | background-repeat: no-repeat; |
|
30 | 30 | } |
|
31 | 31 | .jstElements button:hover { |
|
32 | 32 | border-color : #000; |
|
33 | 33 | } |
|
34 | 34 | .jstElements button span { |
|
35 | 35 | display : none; |
|
36 | 36 | } |
|
37 | 37 | .jstElements span { |
|
38 | 38 | display : inline; |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | .jstSpacer { |
|
42 | 42 | width : 0px; |
|
43 | 43 | font-size: 1px; |
|
44 | 44 | margin-right: 4px; |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | .jstElements .help { float: right; margin-right: 1em; padding-top: 8px; font-size: 0.9em; } | |
|
48 | ||
|
47 | 49 | /* Buttons |
|
48 | 50 | -------------------------------------------------------- */ |
|
49 | 51 | .jstb_strong { |
|
50 | 52 | background-image: url(../images/jstoolbar/bt_strong.png); |
|
51 | 53 | } |
|
52 | 54 | .jstb_em { |
|
53 | 55 | background-image: url(../images/jstoolbar/bt_em.png); |
|
54 | 56 | } |
|
55 | 57 | .jstb_ins { |
|
56 | 58 | background-image: url(../images/jstoolbar/bt_ins.png); |
|
57 | 59 | } |
|
58 | 60 | .jstb_del { |
|
59 | 61 | background-image: url(../images/jstoolbar/bt_del.png); |
|
60 | 62 | } |
|
61 | 63 | .jstb_quote { |
|
62 | 64 | background-image: url(../images/jstoolbar/bt_quote.png); |
|
63 | 65 | } |
|
64 | 66 | .jstb_code { |
|
65 | 67 | background-image: url(../images/jstoolbar/bt_code.png); |
|
66 | 68 | } |
|
67 | 69 | .jstb_br { |
|
68 | 70 | background-image: url(../images/jstoolbar/bt_br.png); |
|
69 | 71 | } |
|
70 | 72 | .jstb_h1 { |
|
71 | 73 | background-image: url(../images/jstoolbar/bt_h1.png); |
|
72 | 74 | } |
|
73 | 75 | .jstb_h2 { |
|
74 | 76 | background-image: url(../images/jstoolbar/bt_h2.png); |
|
75 | 77 | } |
|
76 | 78 | .jstb_h3 { |
|
77 | 79 | background-image: url(../images/jstoolbar/bt_h3.png); |
|
78 | 80 | } |
|
79 | 81 | .jstb_ul { |
|
80 | 82 | background-image: url(../images/jstoolbar/bt_ul.png); |
|
81 | 83 | } |
|
82 | 84 | .jstb_ol { |
|
83 | 85 | background-image: url(../images/jstoolbar/bt_ol.png); |
|
84 | 86 | } |
|
85 | 87 | .jstb_pre { |
|
86 | 88 | background-image: url(../images/jstoolbar/bt_pre.png); |
|
87 | 89 | } |
|
88 | 90 | .jstb_link { |
|
89 | 91 | background-image: url(../images/jstoolbar/bt_link.png); |
|
90 | 92 | } |
|
91 | 93 | .jstb_img { |
|
92 | 94 | background-image: url(../images/jstoolbar/bt_img.png); |
|
93 | 95 | } |
General Comments 0
You need to be logged in to leave comments.
Login now