2 confirm_confirm_confirm = () ->
\r
4 editor = window.PettanrEditor
\r
5 WritingFormat = window.PettanrWritingFormat
\r
6 WritingFormat.load($('#writing_formats'))
\r
7 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
8 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
9 for n, v of SpeechBalloonTemplate.scripts
\r
11 v.add_helper( n, '' )
\r
12 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
13 ColorHelper = window.PettanrColorHelper
\r
15 $('.panel-editor').map ->
\r
16 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
17 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
18 if editor.is_editting()
\r
20 $('#elements-tabs').tabs()
\r
21 $('#new-element-tabs').tabs()
\r
22 $('#new-speech_balloon-tabs').tabs()
\r
23 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
24 $("#elements-tabs li").removeClass("ui-corner-top")
\r
25 $("#elements-tabs li").addClass("ui-corner-left")
\r
26 $("#elements-tabs li").map ->
\r
28 switch $(@).attr('element_type')
\r
29 when 'speech_balloon'
\r
30 trace = editor.element_tag_id($(@))
\r
31 t = $('img', $(trace))
\r
32 when 'panel_picture'
\r
33 trace = editor.element_tag_id($(@)) + 'img'
\r
38 $('.ui-resizable-handle', t.parent()).map ->
\r
39 $(@).css('display', 'block')
\r
41 switch $(@).attr('element_type')
\r
42 when 'speech_balloon'
\r
43 trace = editor.element_tag_id($(@))
\r
44 t = $('img', $(trace))
\r
45 when 'panel_picture'
\r
46 trace = editor.element_tag_id($(@)) + 'img'
\r
51 $('.ui-resizable-handle', t.parent()).map ->
\r
52 $(@).css('display', 'none')
\r
55 $('.ui-icon-destroy').map ->
\r
58 primary: 'ui-icon-close',
\r
64 if confirm('destroy ?')
\r
65 trace = editor.element_tag_id($(@))
\r
66 $(trace + '_destroy').val('true')
\r
67 panel_trace = editor.panel_tag_id($(@))
\r
68 update_t(panel_trace + 'tsort')
\r
69 update_z(panel_trace + 'zsort')
\r
71 $(trace + 'element_tab').css('display', 'none')
\r
72 $(trace + 'tab_panel').css('display', 'none')
\r
73 $(trace + 'zsort').css('display', 'none')
\r
74 $(trace + 'tsort').css('display', 'none')
\r
75 switch $(@).attr('element_type')
\r
76 when 'panel_picture'
\r
77 trace = trace + 'div'
\r
78 $(trace).css('display', 'none')
\r
81 $('#pettanr-panel-submit').focusin ->
\r
82 editor.refresh_attribute($('#pettanr-panel-json'))
\r
85 $('.pettanr-comic-panel').map ->
\r
86 if editor.is_editable($(@))
\r
88 stop: ( event, ui ) ->
\r
89 trace = editor.panel_tag_id($(@))
\r
90 w = parseInt($(@).width())
\r
91 h = parseInt($(@).height())
\r
92 $(trace + 'width').val(w)
\r
93 $(trace + 'height').val(h)
\r
94 $('.pettanr-comic-ground-picture').map ->
\r
97 $('.pettanr-comic-ground-color').map ->
\r
105 if $(@).attr('element_type')
\r
107 if $(@).attr('panel_id')
\r
109 switch $(@).attr('column')
\r
111 trace = editor.panel_tag_id($(@))
\r
112 $(trace).width(parseInt( $(@).val()))
\r
114 trace = editor.panel_tag_id($(@))
\r
115 $(trace).height(parseInt( $(@).val()))
\r
117 trace = editor.panel_tag_id($(@))
\r
118 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
121 PictureSizeHelper.add_helper()
\r
123 $('.pettanr-panel-picture-wrapper').map ->
\r
125 stop: ( event, ui ) ->
\r
126 trace = editor.element_tag_id($(@))
\r
127 img = $(trace + 'img')
\r
128 left = img.parent().position().left + $(@).position().left
\r
129 top = img.parent().position().top + $(@).position().top
\r
130 $(trace + 'x').val(parseInt(left))
\r
131 $(trace + 'y').val(parseInt(top))
\r
134 $('.panel-picture').map ->
\r
136 stop: ( event, ui ) ->
\r
138 panel_picture_div = resize_div.parent()
\r
139 trace = editor.element_tag_id(panel_picture_div)
\r
141 resize_div.css('top', '0px')
\r
142 resize_div.css('left', '0px')
\r
143 if ui.originalPosition.top != ui.position.top
\r
144 t = panel_picture_div.position().top + ui.position.top
\r
145 $(trace + 'y').val(Math.floor(t))
\r
146 panel_picture_div.css('top', t.toString() + 'px')
\r
147 if ui.originalPosition.left != ui.position.left
\r
148 l = panel_picture_div.position().left + ui.position.left
\r
149 $(trace + 'x').val(Math.floor(l))
\r
150 panel_picture_div.css('left', l.toString() + 'px')
\r
151 w = if $(trace + 'width').val() < 0
\r
155 h = if $(trace + 'height').val() < 0
\r
159 $(trace + 'width').val(w)
\r
160 $(trace + 'height').val(h)
\r
161 resize: ( event, ui ) ->
\r
163 panel_picture_div = resize_div.parent()
\r
164 trace = editor.element_tag_id(panel_picture_div)
\r
171 if editor.element_is('panel_picture', $(@))
\r
173 switch $(@).attr('column')
\r
175 trace = editor.element_tag_id($(@)) + 'div'
\r
176 v = parseInt($(@).val()).toString() + 'px'
\r
177 $(trace).css('left', v)
\r
179 trace = editor.element_tag_id($(@)) + 'div'
\r
180 v = parseInt($(@).val()).toString() + 'px'
\r
181 $(trace).css('top', v)
\r
183 trace = editor.element_tag_id($(@)) + 'img'
\r
184 w = parseInt($(@).val())
\r
185 $(trace).width(Math.abs(w))
\r
186 $(trace).parent().width(Math.abs(w))
\r
187 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
189 trace = editor.element_tag_id($(@)) + 'img'
\r
190 h = parseInt($(@).val())
\r
191 $(trace).height(Math.abs(h))
\r
192 $(trace).parent().height(Math.abs(h))
\r
193 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
195 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
199 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
201 $('.pettanr-comic-balloon' ).map ->
\r
203 stop: ( event, ui ) ->
\r
204 balloon = $('.pettanr-balloon', $(@))
\r
205 trace = editor.element_part_tag_id(balloon)
\r
206 left = $(@).position().left
\r
207 top = $(@).position().top
\r
208 $(trace + 'x').val(parseInt(left))
\r
209 $(trace + 'y').val(parseInt(top))
\r
212 $('.pettanr-balloon' ).map ->
\r
214 stop: ( event, ui ) ->
\r
216 speech_balloon_div = resize_div.parent()
\r
217 balloon = $('.pettanr-balloon', $(@))
\r
218 trace = editor.element_tag_id(speech_balloon_div)
\r
219 trace_balloon = editor.element_part_tag_id(balloon)
\r
221 resize_div.css('top', '0px')
\r
222 resize_div.css('left', '0px')
\r
225 if ui.originalPosition.top != ui.position.top
\r
226 t = speech_balloon_div.position().top + ui.position.top
\r
227 $(trace_balloon + 'y').val(Math.floor(t))
\r
228 speech_balloon_div.css('top', t.toString() + 'px')
\r
229 speech_balloon_div.css('height', h + 'px')
\r
230 if ui.originalPosition.left != ui.position.left
\r
231 l = speech_balloon_div.position().left + ui.position.left
\r
232 $(trace_balloon + 'x').val(Math.floor(l))
\r
233 speech_balloon_div.css('left', l.toString() + 'px')
\r
234 speech_balloon_div.css('width', w + 'px')
\r
235 $(trace_balloon + 'width').val(w)
\r
236 $(trace_balloon + 'height').val(h)
\r
237 speech_balloon_div.css('width', w.toString() + 'px')
\r
238 speech_balloon_div.css('height', h.toString() + 'px')
\r
239 resize: ( event, ui ) ->
\r
241 speech_balloon_div = resize_div.parent()
\r
242 balloon = $('.pettanr-balloon', $(@))
\r
243 trace = editor.element_tag_id(speech_balloon_div)
\r
244 trace_balloon = editor.element_part_tag_id(balloon)
\r
249 $('.pettanr-comic-speech-inner' ).map ->
\r
251 outer = $(@).parent()
\r
252 sb = outer.parent()
\r
253 trace = editor.element_tag_id(sb)
\r
254 img = $('.pettanr-balloon', $(trace))
\r
255 $('.ui-resizable-handle', img.parent()).map ->
\r
256 $(@).css('display', 'block')
\r
258 outer = $(@).parent()
\r
259 sb = outer.parent()
\r
260 trace = editor.element_tag_id(sb)
\r
261 img = $('.pettanr-balloon', $(trace))
\r
262 $('.ui-resizable-handle', img.parent()).map ->
\r
263 $(@).css('display', 'none')
\r
268 if editor.element_is('speech_balloon', $(@))
\r
270 switch $(@).attr('column')
\r
272 trace = editor.element_tag_id($(@))
\r
273 v = parseInt($(@).val()).toString() + 'px'
\r
274 $(trace).css('left', v)
\r
276 trace = editor.element_tag_id($(@))
\r
277 v = parseInt($(@).val()).toString() + 'px'
\r
278 $(trace).css('top', v)
\r
280 trace = editor.element_tag_id($(@))
\r
281 v = parseInt($(@).val())
\r
282 $(trace).width(Math.abs(v))
\r
283 img = $('.pettanr-balloon', $(trace))
\r
284 img.parent().width(v)
\r
287 trace = editor.element_tag_id($(@))
\r
288 v = parseInt($(@).val())
\r
289 $(trace).height(Math.abs(v))
\r
290 img = $('.pettanr-balloon', $(trace))
\r
291 img.parent().height(v)
\r
295 $('textarea').map ->
\r
296 if editor.element_is('speech_balloon', $(@))
\r
298 switch $(@).attr('column')
\r
300 trace = editor.element_part_tag_id($(@))
\r
301 wf_sel = $(trace + 'writing_format_id')
\r
302 wf_id = parseInt(wf_sel.val())
\r
303 v = WritingFormat.render(wf_id, $(@).val())
\r
305 $('textarea').map ->
\r
306 if editor.element_is('speech_balloon', $(@))
\r
307 switch $(@).attr('column')
\r
309 $(@).bind('textchange', (event, previousText) ->
\r
310 trace = editor.element_part_tag_id($(@))
\r
311 wf_sel = $(trace + 'writing_format_id')
\r
312 wf_id = parseInt(wf_sel.val())
\r
313 v = WritingFormat.render(wf_id, $(@).val())
\r
317 if editor.element_is('speech_balloon', $(@))
\r
319 switch $(@).attr('column')
\r
321 trace = editor.element_part_tag_id($(@))
\r
322 $(trace).css('font-size', $(@).val() + 'em')
\r
324 trace = editor.element_part_tag_id($(@))
\r
325 v = parseInt($(@).val())
\r
326 $(trace).css('text-align', editor.text_align_texts[v])
\r
329 if editor.element_is('speech_balloon', $(@))
\r
330 if $(@).attr('column') == 'fore_color'
\r
337 if editor.element_is('ground_picture', $(@))
\r
339 switch $(@).attr('column')
\r
341 trace = editor.element_tag_id($(@))
\r
342 x = parseInt($(trace + 'x').val()).toString() + 'px'
\r
343 y = parseInt($(trace + 'y').val()).toString() + 'px'
\r
344 $(trace).css('background-position', x + ' ' + y)
\r
346 if editor.element_is('ground_picture', $(@))
\r
348 switch $(@).attr('column')
\r
350 trace = editor.element_tag_id($(@))
\r
351 v = parseInt($(@).val())
\r
352 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
357 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
361 if editor.element_is('ground_color', $(@))
\r
362 if $(@).attr('column') == 'code'
\r
365 update_t = (ultrace) ->
\r
367 $(ultrace + ' li').map ->
\r
368 trace = editor.element_tag_id($(@))
\r
369 if $(trace + '_destroy').val().length < 1
\r
370 $(trace + 't').val(t)
\r
374 $('.tsort').map ->
\r
376 update: ( event, ui ) ->
\r
377 trace = editor.panel_tag_id($(@))
\r
378 update_t(trace + 'tsort')
\r
380 $('.t-sort li').map ->
\r
381 $(@).disableSelection()
\r
383 update_z = (ultrace) ->
\r
385 $(ultrace + ' li').map ->
\r
386 trace = editor.element_tag_id($(@))
\r
388 if $(trace + '_destroy').val().length < 1
\r
389 $(trace + 'z').val(z)
\r
390 switch $(@).attr('element_type')
\r
391 when 'panel_picture'
\r
392 trace = trace + 'div'
\r
393 $(trace).css('zIndex', z)
\r
397 $('.zsort').map ->
\r
399 update: ( event, ui ) ->
\r
400 trace = editor.panel_tag_id($(@))
\r
401 update_z(trace + 'zsort')
\r
403 $('.z-sort li').map ->
\r
404 $(@).disableSelection()
\r
407 # disable form actions
\r
408 # hide submit buttons
\r
409 $('.edit_panel_picture' ).map ->
\r
412 $('.edit_speech_balloon' ).map ->
\r
415 $('.edit_ground_picture' ).map ->
\r
418 $('.edit_ground_color' ).map ->
\r
422 $('.edit_panel' ).map ->
\r
423 if $(@).attr('jqform')
\r
428 $('.submit' ).map ->
\r
433 if editor.is_element($(@))
\r
434 switch $(@).attr('column')
\r
437 $(@).parent().hide() #label
\r
439 # add button on new form
\r
440 $('.submit-new-form').map ->
\r
441 $(@).html('<button class="new-element">add</button>')
\r
443 $('.new-element').map ->
\r