-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathwysihtml5_input.rb
More file actions
297 lines (282 loc) · 12.4 KB
/
Copy pathwysihtml5_input.rb
File metadata and controls
297 lines (282 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
module Formtastic
module Inputs
class Wysihtml5Input < Formtastic::Inputs::TextInput
COMMANDS_PRESET = {
barebone: [ :bold, :italic, :link, :source ],
basic: [ :bold, :italic, :ul, :ol, :link, :image, :source ],
all: [ :bold, :italic, :underline, :ul, :ol, :outdent, :indent, :link, :image, :video, :source ]
}
BLOCKS_PRESET = {
barebone: [ :p ],
basic: [ :h3, :h4, :h5, :p ],
all: [ :h1, :h2, :h3, :h4, :h5, :h6, :p ]
}
HEIGHT_PRESET = {
tiny: 70,
small: 90,
medium: 170,
large: 350,
huge: 450
}
def toolbar_blocks
blocks = options[:blocks] || input_html_options[:blocks] || :basic
if !blocks.is_a? Array
blocks = BLOCKS_PRESET[blocks.to_sym]
end
if blocks.any?
template.content_tag(:li) do
template.content_tag(:div, class: "editor-command blocks-selector") do
template.content_tag(:span, I18n.t("wysihtml5.block_style")) <<
template.content_tag(:ul) do
blocks.map do |block|
template.content_tag(:li) do
template.content_tag(
:a,
I18n.t("wysihtml5.blocks.#{block}", default: block.to_s.titleize),
href: "javascript:void(0);",
data: {
wysihtml5_command: 'formatBlock',
wysihtml5_command_value: block
})
end
end.join.html_safe
end
end
end
else
"".html_safe
end
end
def toolbar_commands
command_groups = [
[ :bold, :italic, :underline ],
[ :ul, :ol, :outdent, :indent ],
[ :link ],
[ :image ],
[ :video ],
[ :source ]
]
command_mapper = {
link: 'createLink',
image: 'insertImage',
video: 'insertVideo',
ul: 'insertUnorderedList',
ol: 'insertOrderedList',
source: 'change_view'
}
toolbar_commands = options[:commands] || input_html_options[:commands] || :basic
if !toolbar_commands.is_a? Array
toolbar_commands = COMMANDS_PRESET[toolbar_commands.to_sym]
end
command_groups.map do |group|
commands = ''
group.each do |command|
if toolbar_commands.include? command
wysihtml5_command = command_mapper[command.to_sym] || command.to_s
title = I18n.t("wysihtml5.command.#{command}", default: command.to_s.titleize)
commands << template.content_tag(
:a,
href: "javascript:void(0)",
class: "editor-command #{command}",
title: title,
data: (command == :source ? {wysihtml5_action: wysihtml5_command} : { wysihtml5_command: wysihtml5_command })
) do
template.content_tag(:span, title)
end
end
end
if commands.present?
template.content_tag(:li, commands.html_safe)
else
nil
end
end.compact.join.html_safe
end
def toolbar
template.content_tag(:ul, id: "#{input_html_options[:id]}-toolbar", class: "toolbar") do
toolbar_blocks << toolbar_commands
end << toolbar_dialogs
end
def to_html
height = options[:height] || input_html_options[:height] || :medium
if !height.is_a? Integer
height = HEIGHT_PRESET[height.to_sym]
end
opts = { style: "height: #{height}px" }
input_wrapping do
label_html <<
template.content_tag(:div, class: 'activeadmin-wysihtml5') do
toolbar <<
builder.text_area(method, input_html_options.merge(opts))
end
end
end
def toolbar_dialogs
html = <<-HTML
<div class="activeadmin-wysihtml5-modal modal-link">
<div class="modal-title">
#{I18n.t("wysihtml5.dialog.link.dialog_title")}
</div>
<div class="modal-content">
<ul class="tabs">
<li><a data-tab-handle="1" href="#modal-link-url">#{I18n.t("wysihtml5.dialog.link.url_title")}</a></li>
<li><a data-tab-handle="1" href="#modal-link-email">#{I18n.t("wysihtml5.dialog.link.email_title")}</a></li>
<li><a data-tab-handle="1" href="#modal-link-anchor">#{I18n.t("wysihtml5.dialog.link.anchor_title")}</a></li>
</ul>
<div data-tab="1" id="modal-link-url">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.url")}</label>
<input type="text" name="url" placeholder="http://">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.text")}</label>
<input type="text" name="text" placeholder="#{I18n.t("wysihtml5.dialog.link.your_text_here")}">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.title")}</label>
<input type="text" name="title">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.rel")}</label>
<input type="text" name="rel">
</div>
<div class="input boolean">
<label>
<input type="checkbox" name="blank" /> #{I18n.t("wysihtml5.dialog.link.blank")}
</label>
</div>
</div>
<div data-tab="1" id="modal-link-email">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.email")}</label>
<input type="text" name="email" placeholder="your@email.com">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.text")}</label>
<input type="text" name="text" placeholder="#{I18n.t("wysihtml5.dialog.link.your_text_here")}">
</div>
</div>
<div data-tab="1" id="modal-link-anchor">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.anchor")}</label>
<input type="text" name="anchor" placeholder="#{I18n.t("wysihtml5.dialog.link.anchor_name")}">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.link.text")}</label>
<input type="text" name="text" placeholder="#{I18n.t("wysihtml5.dialog.link.your_text_here")}">
</div>
</div>
</div>
<div class="modal-footer">
<a data-modal="close" data-action="cancel" class="button">#{I18n.t("wysihtml5.dialog.cancel")}</a>
<a data-modal="close" data-action="save" class="button primary">#{I18n.t("wysihtml5.dialog.ok")}</a>
</div>
</div>
<div class="activeadmin-wysihtml5-modal modal-image">
<div class="modal-title">
#{I18n.t("wysihtml5.dialog.image.dialog_title")}
</div>
<div class="modal-content">
<ul class="tabs">
<li><a data-tab-handle="1" href="#modal-image-url">#{I18n.t("wysihtml5.dialog.image.url_title")}</a></li>
<li><a data-tab-handle="1" href="#modal-image-gallery">#{I18n.t("wysihtml5.dialog.image.gallery_title")}</a></li>
<li><a data-tab-handle="1" href="#modal-image-upload">#{I18n.t("wysihtml5.dialog.image.upload_title")}</a></li>
</ul>
<div data-tab="1" id="modal-image-url">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.image.url")}</label>
<input type="text" name="url" placeholder="http://" />
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.image.alt")}</label>
<input type="text" name="alt" />
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.image.title")}</label>
<input type="text" name="title" />
</div>
<div class="input select">
<label>#{I18n.t("wysihtml5.dialog.image.alignment")}</label>
<select name="alignment">
<option value="">#{I18n.t("wysihtml5.dialog.image.default")}</option>
<option value="wysiwyg-float-left">#{I18n.t("wysihtml5.dialog.image.left")}</option>
<option value="wysiwyg-float-right">#{I18n.t("wysihtml5.dialog.image.right")}</option>
</select>
</div>
</div>
<div data-tab="1" id="modal-image-upload">
<div class="asset-uploader"></div>
</div>
<div data-tab="1" id="modal-image-gallery">
<div class="assets-container">
<ul></ul>
</div>
<div class="optional-inputs">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.image.alt")}</label>
<input type="text" name="alt" />
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.image.title")}</label>
<input type="text" name="title" />
</div>
<div class="input radio">
<div class="asset_scale_selection">
<label>#{I18n.t("wysihtml5.dialog.image.scale")}</label>
<label class="option"><input value="full" type="radio" name="scale" checked="checked" /> 100%</label>
<label class="option"><input value="three_quarters" type="radio" name="scale" /> 75%</label>
<label class="option"><input value="half" type="radio" name="scale" /> 50%</label>
<label class="option"><input value="one_quarter" type="radio" name="scale" /> 25%</label>
</div>
</div>
<div class="input select">
<label>#{I18n.t("wysihtml5.dialog.image.alignment")}</label>
<select name="alignment">
<option value="">default</option>
<option value="wysiwyg-float-left">#{I18n.t("wysihtml5.dialog.image.left")}</option>
<option value="wysiwyg-float-right">#{I18n.t("wysihtml5.dialog.image.right")}</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a data-modal="close" data-action="cancel" class="button">#{I18n.t("wysihtml5.dialog.cancel")}</a>
<a data-modal="close" data-action="save" class="button primary">#{I18n.t("wysihtml5.dialog.ok")}</a>
</div>
</div>
<div class="activeadmin-wysihtml5-modal modal-video">
<div class="modal-title">
#{I18n.t("wysihtml5.dialog.video.dialog_title")}
</div>
<div class="modal-content">
<div data-tab="1" id="modal-video-url">
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.video.url")}</label>
<input type="text" name="url" placeholder="http://www.youtube.com/watch?v=oHg5SJYRHA0">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.video.title")}</label>
<input type="text" name="title" placeholder="#{I18n.t("wysihtml5.dialog.video.your_text_here")}">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.video.width")}</label>
<input type="text" name="width" value="560">
</div>
<div class="input string">
<label>#{I18n.t("wysihtml5.dialog.video.height")}</label>
<input type="text" name="height" value="315">
</div>
</div>
</div>
<div class="modal-footer">
<a data-modal="close" data-action="cancel" class="button">#{I18n.t("wysihtml5.dialog.cancel")}</a>
<a data-modal="close" data-action="save" class="button primary">#{I18n.t("wysihtml5.dialog.ok")}</a>
</div>
</div>
HTML
html.html_safe
end
end
end
end