##// END OF EJS Templates
Added i18n support to the jstoolbar (only english and french are actually translated)....
Jean-Philippe Lang -
r1060:32b9bf0ef265
parent child
Show More
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Gras';
3 jsToolBar.strings['Italic'] = 'Italique';
4 jsToolBar.strings['Underline'] = 'SoulignΓ©';
5 jsToolBar.strings['Deleted'] = 'RayΓ©';
6 jsToolBar.strings['Inline quote'] = 'Citation';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Titre niveau 1';
9 jsToolBar.strings['Heading 2'] = 'Titre niveau 2';
10 jsToolBar.strings['Heading 3'] = 'Titre niveau 3';
11 jsToolBar.strings['Unordered list'] = 'Liste Γ  puces';
12 jsToolBar.strings['Ordered list'] = 'Liste numΓ©rotΓ©e';
13 jsToolBar.strings['Preformatted text'] = 'Texte prΓ©formatΓ©';
14 jsToolBar.strings['Wiki link'] = 'Lien vers une page Wiki';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -1,448 +1,450
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 def link_to_signin
36 36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
37 37 end
38 38
39 39 def link_to_signout
40 40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
41 41 end
42 42
43 43 # Display a link to user's account page
44 44 def link_to_user(user)
45 45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
46 46 end
47 47
48 48 def link_to_issue(issue)
49 49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
50 50 end
51 51
52 52 def toggle_link(name, id, options={})
53 53 onclick = "Element.toggle('#{id}'); "
54 54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
55 55 onclick << "return false;"
56 56 link_to(name, "#", :onclick => onclick)
57 57 end
58 58
59 59 def show_and_goto_link(name, id, options={})
60 60 onclick = "Element.show('#{id}'); "
61 61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
62 62 onclick << "location.href='##{id}-anchor'; "
63 63 onclick << "return false;"
64 64 link_to(name, "#", options.merge(:onclick => onclick))
65 65 end
66 66
67 67 def image_to_function(name, function, html_options = {})
68 68 html_options.symbolize_keys!
69 69 tag(:input, html_options.merge({
70 70 :type => "image", :src => image_path(name),
71 71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
72 72 }))
73 73 end
74 74
75 75 def prompt_to_remote(name, text, param, url, html_options = {})
76 76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
77 77 link_to name, {}, html_options
78 78 end
79 79
80 80 def format_date(date)
81 81 return nil unless date
82 82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
83 83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
84 84 date.strftime(@date_format)
85 85 end
86 86
87 87 def format_time(time, include_date = true)
88 88 return nil unless time
89 89 time = time.to_time if time.is_a?(String)
90 90 zone = User.current.time_zone
91 91 if time.utc?
92 92 local = zone ? zone.adjust(time) : time.getlocal
93 93 else
94 94 local = zone ? zone.adjust(time.getutc) : time
95 95 end
96 96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
97 97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
98 98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
99 99 end
100 100
101 101 def authoring(created, author)
102 102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
103 103 l(:label_added_time_by, author || 'Anonymous', time_tag)
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(('&#171; ' + l(:label_previous)),
122 122 {:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
123 123 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
124 124
125 125 html << (pagination_links_each(paginator, options) do |n|
126 126 link_to_remote(n.to_s,
127 127 {:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
128 128 {:href => url_for(:params => url_param.merge(page_param => n))})
129 129 end || '')
130 130
131 131 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
132 132 {:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
133 133 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
134 134
135 135 unless count.nil?
136 136 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
137 137 end
138 138
139 139 html
140 140 end
141 141
142 142 def per_page_links(selected=nil)
143 143 url_param = params.dup
144 144 url_param.clear if url_param.has_key?(:set_filter)
145 145
146 146 links = Setting.per_page_options_array.collect do |n|
147 147 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
148 148 {:href => url_for(url_param.merge(:per_page => n))})
149 149 end
150 150 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
151 151 end
152 152
153 153 def html_title(*args)
154 154 if args.empty?
155 155 title = []
156 156 title << @project.name if @project
157 157 title += @html_title if @html_title
158 158 title << Setting.app_title
159 159 title.compact.join(' - ')
160 160 else
161 161 @html_title ||= []
162 162 @html_title += args
163 163 end
164 164 end
165 165
166 166 ACCESSKEYS = {:edit => 'e',
167 167 :preview => 'r',
168 168 :quick_search => 'f',
169 169 :search => '4',
170 170 }.freeze unless const_defined?(:ACCESSKEYS)
171 171
172 172 def accesskey(s)
173 173 ACCESSKEYS[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)
189 189 else
190 190 raise ArgumentError, 'invalid arguments to textilizable'
191 191 end
192 192
193 193 # when using an image link, try to use an attachment, if possible
194 194 attachments = options[:attachments]
195 195 if attachments
196 196 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
197 197 style = $1
198 198 filename = $6
199 199 rf = Regexp.new(filename, Regexp::IGNORECASE)
200 200 # search for the picture in attachments
201 201 if found = attachments.detect { |att| att.filename =~ rf }
202 202 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
203 203 "!#{style}#{image_url}!"
204 204 else
205 205 "!#{style}#{filename}!"
206 206 end
207 207 end
208 208 end
209 209
210 210 text = (Setting.text_formatting == 'textile') ?
211 211 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
212 212 simple_format(auto_link(h(text)))
213 213
214 214 # different methods for formatting wiki links
215 215 case options[:wiki_links]
216 216 when :local
217 217 # used for local links to html files
218 218 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
219 219 when :anchor
220 220 # used for single-file wiki export
221 221 format_wiki_link = Proc.new {|project, title| "##{title}" }
222 222 else
223 223 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
224 224 end
225 225
226 226 project = options[:project] || @project
227 227
228 228 # Wiki links
229 229 #
230 230 # Examples:
231 231 # [[mypage]]
232 232 # [[mypage|mytext]]
233 233 # wiki links can refer other project wikis, using project name or identifier:
234 234 # [[project:]] -> wiki starting page
235 235 # [[project:|mytext]]
236 236 # [[project:mypage]]
237 237 # [[project:mypage|mytext]]
238 238 text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m|
239 239 link_project = project
240 240 esc, all, page, title = $1, $2, $3, $5
241 241 if esc.nil?
242 242 if page =~ /^([^\:]+)\:(.*)$/
243 243 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
244 244 page = $2
245 245 title ||= $1 if page.blank?
246 246 end
247 247
248 248 if link_project && link_project.wiki
249 249 # check if page exists
250 250 wiki_page = link_project.wiki.find_page(page)
251 251 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
252 252 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
253 253 else
254 254 # project or wiki doesn't exist
255 255 title || page
256 256 end
257 257 else
258 258 all
259 259 end
260 260 end
261 261
262 262 # Redmine links
263 263 #
264 264 # Examples:
265 265 # Issues:
266 266 # #52 -> Link to issue #52
267 267 # Changesets:
268 268 # r52 -> Link to revision 52
269 269 # Documents:
270 270 # document#17 -> Link to document with id 17
271 271 # document:Greetings -> Link to the document with title "Greetings"
272 272 # document:"Some document" -> Link to the document with title "Some document"
273 273 # Versions:
274 274 # version#3 -> Link to version with id 3
275 275 # version:1.0.0 -> Link to version named "1.0.0"
276 276 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
277 277 # Attachments:
278 278 # attachment:file.zip -> Link to the attachment of the current object named file.zip
279 279 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
280 280 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
281 281 link = nil
282 282 if esc.nil?
283 283 if prefix.nil? && sep == 'r'
284 284 if project && (changeset = project.changesets.find_by_revision(oid))
285 285 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
286 286 :title => truncate(changeset.comments, 100))
287 287 end
288 288 elsif sep == '#'
289 289 oid = oid.to_i
290 290 case prefix
291 291 when nil
292 292 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
293 293 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
294 294 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
295 295 link = content_tag('del', link) if issue.closed?
296 296 end
297 297 when 'document'
298 298 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
299 299 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
300 300 end
301 301 when 'version'
302 302 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
303 303 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
304 304 end
305 305 end
306 306 elsif sep == ':'
307 307 # removes the double quotes if any
308 308 name = oid.gsub(%r{^"(.*)"$}, "\\1")
309 309 case prefix
310 310 when 'document'
311 311 if project && document = project.documents.find_by_title(name)
312 312 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
313 313 end
314 314 when 'version'
315 315 if project && version = project.versions.find_by_name(name)
316 316 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
317 317 end
318 318 when 'attachment'
319 319 if attachments && attachment = attachments.detect {|a| a.filename == name }
320 320 link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
321 321 end
322 322 end
323 323 end
324 324 end
325 325 leading + (link || "#{prefix}#{sep}#{oid}")
326 326 end
327 327
328 328 text
329 329 end
330 330
331 331 # Same as Rails' simple_format helper without using paragraphs
332 332 def simple_format_without_paragraph(text)
333 333 text.to_s.
334 334 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
335 335 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
336 336 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
337 337 end
338 338
339 339 def error_messages_for(object_name, options = {})
340 340 options = options.symbolize_keys
341 341 object = instance_variable_get("@#{object_name}")
342 342 if object && !object.errors.empty?
343 343 # build full_messages here with controller current language
344 344 full_messages = []
345 345 object.errors.each do |attr, msg|
346 346 next if msg.nil?
347 347 msg = msg.first if msg.is_a? Array
348 348 if attr == "base"
349 349 full_messages << l(msg)
350 350 else
351 351 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
352 352 end
353 353 end
354 354 # retrieve custom values error messages
355 355 if object.errors[:custom_values]
356 356 object.custom_values.each do |v|
357 357 v.errors.each do |attr, msg|
358 358 next if msg.nil?
359 359 msg = msg.first if msg.is_a? Array
360 360 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
361 361 end
362 362 end
363 363 end
364 364 content_tag("div",
365 365 content_tag(
366 366 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
367 367 ) +
368 368 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
369 369 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
370 370 )
371 371 else
372 372 ""
373 373 end
374 374 end
375 375
376 376 def lang_options_for_select(blank=true)
377 377 (blank ? [["(auto)", ""]] : []) +
378 378 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
379 379 end
380 380
381 381 def label_tag_for(name, option_tags = nil, options = {})
382 382 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
383 383 content_tag("label", label_text)
384 384 end
385 385
386 386 def labelled_tabular_form_for(name, object, options, &proc)
387 387 options[:html] ||= {}
388 388 options[:html].store :class, "tabular"
389 389 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
390 390 end
391 391
392 392 def check_all_links(form_name)
393 393 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
394 394 " | " +
395 395 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
396 396 end
397 397
398 398 def progress_bar(pcts, options={})
399 399 pcts = [pcts, pcts] unless pcts.is_a?(Array)
400 400 pcts[1] = pcts[1] - pcts[0]
401 401 pcts << (100 - pcts[1] - pcts[0])
402 402 width = options[:width] || '100px;'
403 403 legend = options[:legend] || ''
404 404 content_tag('table',
405 405 content_tag('tr',
406 406 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
407 407 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
408 408 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
409 409 ), :class => 'progress', :style => "width: #{width};") +
410 410 content_tag('p', legend, :class => 'pourcent')
411 411 end
412 412
413 413 def context_menu_link(name, url, options={})
414 414 options[:class] ||= ''
415 415 if options.delete(:selected)
416 416 options[:class] << ' icon-checked disabled'
417 417 options[:disabled] = true
418 418 end
419 419 if options.delete(:disabled)
420 420 options.delete(:method)
421 421 options.delete(:confirm)
422 422 options.delete(:onclick)
423 423 options[:class] << ' disabled'
424 424 url = '#'
425 425 end
426 426 link_to name, url, options
427 427 end
428 428
429 429 def calendar_for(field_id)
430 430 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
431 431 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
432 432 end
433 433
434 434 def wikitoolbar_for(field_id)
435 435 return '' unless Setting.text_formatting == 'textile'
436 javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
436 javascript_include_tag('jstoolbar/jstoolbar') +
437 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
438 javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
437 439 end
438 440
439 441 def content_for(name, content = nil, &block)
440 442 @has_content ||= {}
441 443 @has_content[name] = true
442 444 super(name, content, &block)
443 445 end
444 446
445 447 def has_content?(name)
446 448 (@has_content && @has_content[name]) || false
447 449 end
448 450 end
@@ -1,521 +1,525
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 this.title = title || null;
70 if(typeof jsToolBar.strings == 'undefined') {
71 this.title = title || null;
72 } else {
73 this.title = jsToolBar.strings[title] || title || null;
74 }
71 75 this.fn = fn || function(){};
72 76 this.scope = scope || null;
73 77 this.className = className || null;
74 78 }
75 79 jsButton.prototype.draw = function() {
76 80 if (!this.scope) return null;
77 81
78 82 var button = document.createElement('button');
79 83 button.setAttribute('type','button');
80 84 if (this.className) button.className = this.className;
81 85 button.title = this.title;
82 86 var span = document.createElement('span');
83 87 span.appendChild(document.createTextNode(this.title));
84 88 button.appendChild(span);
85 89
86 90 if (this.icon != undefined) {
87 91 button.style.backgroundImage = 'url('+this.icon+')';
88 92 }
89 93 if (typeof(this.fn) == 'function') {
90 94 var This = this;
91 95 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
92 96 }
93 97 return button;
94 98 }
95 99
96 100 function jsSpace(id) {
97 101 this.id = id || null;
98 102 this.width = null;
99 103 }
100 104 jsSpace.prototype.draw = function() {
101 105 var span = document.createElement('span');
102 106 if (this.id) span.id = this.id;
103 107 span.appendChild(document.createTextNode(String.fromCharCode(160)));
104 108 span.className = 'jstSpacer';
105 109 if (this.width) span.style.marginRight = this.width+'px';
106 110
107 111 return span;
108 112 }
109 113
110 114 function jsCombo(title, options, scope, fn, className) {
111 115 this.title = title || null;
112 116 this.options = options || null;
113 117 this.scope = scope || null;
114 118 this.fn = fn || function(){};
115 119 this.className = className || null;
116 120 }
117 121 jsCombo.prototype.draw = function() {
118 122 if (!this.scope || !this.options) return null;
119 123
120 124 var select = document.createElement('select');
121 125 if (this.className) select.className = className;
122 126 select.title = this.title;
123 127
124 128 for (var o in this.options) {
125 129 //var opt = this.options[o];
126 130 var option = document.createElement('option');
127 131 option.value = o;
128 132 option.appendChild(document.createTextNode(this.options[o]));
129 133 select.appendChild(option);
130 134 }
131 135
132 136 var This = this;
133 137 select.onchange = function() {
134 138 try {
135 139 This.fn.call(This.scope, this.value);
136 140 } catch (e) { alert(e); }
137 141
138 142 return false;
139 143 }
140 144
141 145 return select;
142 146 }
143 147
144 148
145 149 jsToolBar.prototype = {
146 150 base_url: '',
147 151 mode: 'wiki',
148 152 elements: {},
149 153
150 154 getMode: function() {
151 155 return this.mode;
152 156 },
153 157
154 158 setMode: function(mode) {
155 159 this.mode = mode || 'wiki';
156 160 },
157 161
158 162 switchMode: function(mode) {
159 163 mode = mode || 'wiki';
160 164 this.draw(mode);
161 165 },
162 166
163 167 button: function(toolName) {
164 168 var tool = this.elements[toolName];
165 169 if (typeof tool.fn[this.mode] != 'function') return null;
166 170 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
167 171 if (tool.icon != undefined) b.icon = tool.icon;
168 172 return b;
169 173 },
170 174 space: function(toolName) {
171 175 var tool = new jsSpace(toolName)
172 176 if (this.elements[toolName].width !== undefined)
173 177 tool.width = this.elements[toolName].width;
174 178 return tool;
175 179 },
176 180 combo: function(toolName) {
177 181 var tool = this.elements[toolName];
178 182 var length = tool[this.mode].list.length;
179 183
180 184 if (typeof tool[this.mode].fn != 'function' || length == 0) {
181 185 return null;
182 186 } else {
183 187 var options = {};
184 188 for (var i=0; i < length; i++) {
185 189 var opt = tool[this.mode].list[i];
186 190 options[opt] = tool.options[opt];
187 191 }
188 192 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
189 193 }
190 194 },
191 195 draw: function(mode) {
192 196 this.setMode(mode);
193 197
194 198 // Empty toolbar
195 199 while (this.toolbar.hasChildNodes()) {
196 200 this.toolbar.removeChild(this.toolbar.firstChild)
197 201 }
198 202 this.toolNodes = {}; // vide les raccourcis DOM/**/
199 203
200 204 // Draw toolbar elements
201 205 var b, tool, newTool;
202 206
203 207 for (var i in this.elements) {
204 208 b = this.elements[i];
205 209
206 210 var disabled =
207 211 b.type == undefined || b.type == ''
208 212 || (b.disabled != undefined && b.disabled)
209 213 || (b.context != undefined && b.context != null && b.context != this.context);
210 214
211 215 if (!disabled && typeof this[b.type] == 'function') {
212 216 tool = this[b.type](i);
213 217 if (tool) newTool = tool.draw();
214 218 if (newTool) {
215 219 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
216 220 this.toolbar.appendChild(newTool);
217 221 }
218 222 }
219 223 }
220 224 },
221 225
222 226 singleTag: function(stag,etag) {
223 227 stag = stag || null;
224 228 etag = etag || stag;
225 229
226 230 if (!stag || !etag) { return; }
227 231
228 232 this.encloseSelection(stag,etag);
229 233 },
230 234
231 235 encloseLineSelection: function(prefix, suffix, fn) {
232 236 this.textarea.focus();
233 237
234 238 prefix = prefix || '';
235 239 suffix = suffix || '';
236 240
237 241 var start, end, sel, scrollPos, subst, res;
238 242
239 243 if (typeof(document["selection"]) != "undefined") {
240 244 sel = document.selection.createRange().text;
241 245 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
242 246 start = this.textarea.selectionStart;
243 247 end = this.textarea.selectionEnd;
244 248 scrollPos = this.textarea.scrollTop;
245 249 // go to the start of the line
246 250 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
247 251 // go to the end of the line
248 252 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
249 253 sel = this.textarea.value.substring(start, end);
250 254 }
251 255
252 256 if (sel.match(/ $/)) { // exclude ending space char, if any
253 257 sel = sel.substring(0, sel.length - 1);
254 258 suffix = suffix + " ";
255 259 }
256 260
257 261 if (typeof(fn) == 'function') {
258 262 res = (sel) ? fn.call(this,sel) : fn('');
259 263 } else {
260 264 res = (sel) ? sel : '';
261 265 }
262 266
263 267 subst = prefix + res + suffix;
264 268
265 269 if (typeof(document["selection"]) != "undefined") {
266 270 document.selection.createRange().text = subst;
267 271 var range = this.textarea.createTextRange();
268 272 range.collapse(false);
269 273 range.move('character', -suffix.length);
270 274 range.select();
271 275 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
272 276 this.textarea.value = this.textarea.value.substring(0, start) + subst +
273 277 this.textarea.value.substring(end);
274 278 if (sel) {
275 279 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
276 280 } else {
277 281 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
278 282 }
279 283 this.textarea.scrollTop = scrollPos;
280 284 }
281 285 },
282 286
283 287 encloseSelection: function(prefix, suffix, fn) {
284 288 this.textarea.focus();
285 289
286 290 prefix = prefix || '';
287 291 suffix = suffix || '';
288 292
289 293 var start, end, sel, scrollPos, subst, res;
290 294
291 295 if (typeof(document["selection"]) != "undefined") {
292 296 sel = document.selection.createRange().text;
293 297 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
294 298 start = this.textarea.selectionStart;
295 299 end = this.textarea.selectionEnd;
296 300 scrollPos = this.textarea.scrollTop;
297 301 sel = this.textarea.value.substring(start, end);
298 302 }
299 303
300 304 if (sel.match(/ $/)) { // exclude ending space char, if any
301 305 sel = sel.substring(0, sel.length - 1);
302 306 suffix = suffix + " ";
303 307 }
304 308
305 309 if (typeof(fn) == 'function') {
306 310 res = (sel) ? fn.call(this,sel) : fn('');
307 311 } else {
308 312 res = (sel) ? sel : '';
309 313 }
310 314
311 315 subst = prefix + res + suffix;
312 316
313 317 if (typeof(document["selection"]) != "undefined") {
314 318 document.selection.createRange().text = subst;
315 319 var range = this.textarea.createTextRange();
316 320 range.collapse(false);
317 321 range.move('character', -suffix.length);
318 322 range.select();
319 323 // this.textarea.caretPos -= suffix.length;
320 324 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
321 325 this.textarea.value = this.textarea.value.substring(0, start) + subst +
322 326 this.textarea.value.substring(end);
323 327 if (sel) {
324 328 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
325 329 } else {
326 330 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
327 331 }
328 332 this.textarea.scrollTop = scrollPos;
329 333 }
330 334 },
331 335
332 336 stripBaseURL: function(url) {
333 337 if (this.base_url != '') {
334 338 var pos = url.indexOf(this.base_url);
335 339 if (pos == 0) {
336 340 url = url.substr(this.base_url.length);
337 341 }
338 342 }
339 343
340 344 return url;
341 345 }
342 346 };
343 347
344 348 /** Resizer
345 349 -------------------------------------------------------- */
346 350 jsToolBar.prototype.resizeSetStartH = function() {
347 351 this.dragStartH = this.textarea.offsetHeight + 0;
348 352 };
349 353 jsToolBar.prototype.resizeDragStart = function(event) {
350 354 var This = this;
351 355 this.dragStartY = event.clientY;
352 356 this.resizeSetStartH();
353 357 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
354 358 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
355 359 };
356 360
357 361 jsToolBar.prototype.resizeDragMove = function(event) {
358 362 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
359 363 };
360 364
361 365 jsToolBar.prototype.resizeDragStop = function(event) {
362 366 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
363 367 document.removeEventListener('mouseup', this.dragStopHdlr, false);
364 368 };
365 369
366 370 // Elements definition ------------------------------------
367 371
368 372 // strong
369 373 jsToolBar.prototype.elements.strong = {
370 374 type: 'button',
371 title: 'Strong emphasis',
375 title: 'Strong',
372 376 fn: {
373 377 wiki: function() { this.singleTag('*') }
374 378 }
375 379 }
376 380
377 381 // em
378 382 jsToolBar.prototype.elements.em = {
379 383 type: 'button',
380 title: 'Emphasis',
384 title: 'Italic',
381 385 fn: {
382 386 wiki: function() { this.singleTag("_") }
383 387 }
384 388 }
385 389
386 390 // ins
387 391 jsToolBar.prototype.elements.ins = {
388 392 type: 'button',
389 title: 'Inserted',
393 title: 'Underline',
390 394 fn: {
391 395 wiki: function() { this.singleTag('+') }
392 396 }
393 397 }
394 398
395 399 // del
396 400 jsToolBar.prototype.elements.del = {
397 401 type: 'button',
398 402 title: 'Deleted',
399 403 fn: {
400 404 wiki: function() { this.singleTag('-') }
401 405 }
402 406 }
403 407
404 408 // quote
405 409 jsToolBar.prototype.elements.quote = {
406 410 type: 'button',
407 411 title: 'Inline quote',
408 412 fn: {
409 413 wiki: function() { this.singleTag('??') }
410 414 }
411 415 }
412 416
413 417 // code
414 418 jsToolBar.prototype.elements.code = {
415 419 type: 'button',
416 420 title: 'Code',
417 421 fn: {
418 422 wiki: function() { this.singleTag('@') }
419 423 }
420 424 }
421 425
422 426 // spacer
423 427 jsToolBar.prototype.elements.space1 = {type: 'space'}
424 428
425 429 // headings
426 430 jsToolBar.prototype.elements.h1 = {
427 431 type: 'button',
428 432 title: 'Heading 1',
429 433 fn: {
430 434 wiki: function() {
431 435 this.encloseLineSelection('h1. ', '',function(str) {
432 436 str = str.replace(/^h\d+\.\s+/, '')
433 437 return str;
434 438 });
435 439 }
436 440 }
437 441 }
438 442 jsToolBar.prototype.elements.h2 = {
439 443 type: 'button',
440 444 title: 'Heading 2',
441 445 fn: {
442 446 wiki: function() {
443 447 this.encloseLineSelection('h2. ', '',function(str) {
444 448 str = str.replace(/^h\d+\.\s+/, '')
445 449 return str;
446 450 });
447 451 }
448 452 }
449 453 }
450 454 jsToolBar.prototype.elements.h3 = {
451 455 type: 'button',
452 456 title: 'Heading 3',
453 457 fn: {
454 458 wiki: function() {
455 459 this.encloseLineSelection('h3. ', '',function(str) {
456 460 str = str.replace(/^h\d+\.\s+/, '')
457 461 return str;
458 462 });
459 463 }
460 464 }
461 465 }
462 466
463 467 // spacer
464 468 jsToolBar.prototype.elements.space2 = {type: 'space'}
465 469
466 470 // ul
467 471 jsToolBar.prototype.elements.ul = {
468 472 type: 'button',
469 473 title: 'Unordered list',
470 474 fn: {
471 475 wiki: function() {
472 476 this.encloseLineSelection('','',function(str) {
473 477 str = str.replace(/\r/g,'');
474 478 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
475 479 });
476 480 }
477 481 }
478 482 }
479 483
480 484 // ol
481 485 jsToolBar.prototype.elements.ol = {
482 486 type: 'button',
483 487 title: 'Ordered list',
484 488 fn: {
485 489 wiki: function() {
486 490 this.encloseLineSelection('','',function(str) {
487 491 str = str.replace(/\r/g,'');
488 492 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
489 493 });
490 494 }
491 495 }
492 496 }
493 497
494 498 // pre
495 499 jsToolBar.prototype.elements.pre = {
496 500 type: 'button',
497 501 title: 'Preformatted text',
498 502 fn: {
499 503 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
500 504 }
501 505 }
502 506
503 507 // spacer
504 508 jsToolBar.prototype.elements.space3 = {type: 'space'}
505 509
506 510 // wiki page
507 511 jsToolBar.prototype.elements.link = {
508 512 type: 'button',
509 title: 'Wiki Page Link',
513 title: 'Wiki link',
510 514 fn: {
511 515 wiki: function() { this.encloseSelection("[[", "]]") }
512 516 }
513 517 }
514 518 // image
515 519 jsToolBar.prototype.elements.img = {
516 520 type: 'button',
517 title: 'Inline image',
521 title: 'Image',
518 522 fn: {
519 523 wiki: function() { this.encloseSelection("!", "!") }
520 524 }
521 525 }
General Comments 0
You need to be logged in to leave comments. Login now