2 confirm_confirm_confirm = () ->
4 editor = window.PettanrEditor
6 $('.panel-editor').map ->
7 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
8 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
9 if editor.is_editting()
11 $('#elements-tabs').tabs()
12 $('#new-element-tabs').tabs()
13 $('#new-speech_balloon-tabs').tabs()
14 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
15 $("#elements-tabs li").removeClass("ui-corner-top")
16 $("#elements-tabs li").addClass("ui-corner-left")
17 $("#elements-tabs li").map ->
19 switch $(@).attr('element_type')
21 trace = editor.element_tag_id($(@))
22 t = $('img', $(trace))
24 trace = editor.element_tag_id($(@)) + 'img'
29 $('.ui-resizable-handle', t.parent()).map ->
30 $(@).css('display', 'block')
32 switch $(@).attr('element_type')
34 trace = editor.element_tag_id($(@))
35 t = $('img', $(trace))
37 trace = editor.element_tag_id($(@)) + 'img'
42 $('.ui-resizable-handle', t.parent()).map ->
43 $(@).css('display', 'none')
46 $('.ui-icon-destroy').map ->
49 primary: 'ui-icon-close',
55 if confirm('destroy ?')
56 trace = editor.element_tag_id($(@))
57 $(trace + '_destroy').val('true')
58 panel_trace = editor.panel_tag_id($(@))
59 update_t(panel_trace + 'tsort')
60 update_z(panel_trace + 'zsort')
62 $(trace + 'element_tab').css('display', 'none')
63 $(trace + 'tab_panel').css('display', 'none')
64 $(trace + 'zsort').css('display', 'none')
65 $(trace + 'tsort').css('display', 'none')
66 switch $(@).attr('element_type')
69 $(trace).css('display', 'none')
72 $('#pettanr-panel-submit').focusin ->
73 editor.refresh_attribute($('#pettanr-panel-json'))
76 $('.pettanr-comic-panel').map ->
77 if editor.is_editable($(@))
79 stop: ( event, ui ) ->
80 trace = editor.panel_tag_id($(@))
81 w = parseInt($(@).width())
82 h = parseInt($(@).height())
83 $(trace + 'width').val(w)
84 $(trace + 'height').val(h)
85 $('.pettanr-comic-ground-picture').map ->
88 $('.pettanr-comic-ground-color').map ->
96 if $(@).attr('element_type')
98 if $(@).attr('panel_id')
100 switch $(@).attr('column')
102 trace = editor.panel_tag_id($(@))
103 $(trace).width(parseInt( $(@).val()))
105 trace = editor.panel_tag_id($(@))
106 $(trace).height(parseInt( $(@).val()))
108 trace = editor.panel_tag_id($(@))
109 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
112 PictureSizeHelper.add_helper()
114 $('.pettanr-panel-picture-wrapper').map ->
116 stop: ( event, ui ) ->
117 trace = editor.element_tag_id($(@))
118 img = $(trace + 'img')
119 left = img.parent().position().left + $(@).position().left
120 top = img.parent().position().top + $(@).position().top
121 $(trace + 'x').val(parseInt(left))
122 $(trace + 'y').val(parseInt(top))
125 $('.panel-picture').map ->
127 stop: ( event, ui ) ->
129 panel_picture_div = resize_div.parent()
130 trace = editor.element_tag_id(panel_picture_div)
132 resize_div.css('top', '0px')
133 resize_div.css('left', '0px')
134 if ui.originalPosition.top != ui.position.top
135 t = panel_picture_div.position().top + ui.position.top
136 $(trace + 'y').val(Math.floor(t))
137 panel_picture_div.css('top', t.toString() + 'px')
138 if ui.originalPosition.left != ui.position.left
139 l = panel_picture_div.position().left + ui.position.left
140 $(trace + 'x').val(Math.floor(l))
141 panel_picture_div.css('left', l.toString() + 'px')
142 w = if $(trace + 'width').val() < 0
146 h = if $(trace + 'height').val() < 0
150 $(trace + 'width').val(w)
151 $(trace + 'height').val(h)
152 resize: ( event, ui ) ->
154 panel_picture_div = resize_div.parent()
155 trace = editor.element_tag_id(panel_picture_div)
162 if editor.element_is('panel_picture', $(@))
164 switch $(@).attr('column')
166 trace = editor.element_tag_id($(@)) + 'div'
167 v = parseInt($(@).val()).toString() + 'px'
168 $(trace).css('left', v)
170 trace = editor.element_tag_id($(@)) + 'div'
171 v = parseInt($(@).val()).toString() + 'px'
172 $(trace).css('top', v)
174 trace = editor.element_tag_id($(@)) + 'img'
175 w = parseInt($(@).val())
176 $(trace).width(Math.abs(w))
177 $(trace).parent().width(Math.abs(w))
178 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
180 trace = editor.element_tag_id($(@)) + 'img'
181 h = parseInt($(@).val())
182 $(trace).height(Math.abs(h))
183 $(trace).parent().height(Math.abs(h))
184 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
186 PictureSizeHelper.refresh_picture($(trace), w, h)
190 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
192 $('.pettanr-comic-balloon' ).map ->
194 stop: ( event, ui ) ->
195 balloon = $('.pettanr-balloon', $(@))
196 trace = editor.element_part_tag_id(balloon)
197 left = $(@).position().left
198 top = $(@).position().top
199 $(trace + 'x').val(parseInt(left))
200 $(trace + 'y').val(parseInt(top))
203 $('.pettanr-balloon' ).map ->
205 stop: ( event, ui ) ->
207 speech_balloon_div = resize_div.parent()
208 balloon = $('.pettanr-balloon', $(@))
209 trace = editor.element_tag_id(speech_balloon_div)
210 trace_balloon = editor.element_part_tag_id(balloon)
212 resize_div.css('top', '0px')
213 resize_div.css('left', '0px')
216 if ui.originalPosition.top != ui.position.top
217 t = speech_balloon_div.position().top + ui.position.top
218 $(trace_balloon + 'y').val(Math.floor(t))
219 speech_balloon_div.css('top', t.toString() + 'px')
220 speech_balloon_div.css('height', h + 'px')
221 if ui.originalPosition.left != ui.position.left
222 l = speech_balloon_div.position().left + ui.position.left
223 $(trace_balloon + 'x').val(Math.floor(l))
224 speech_balloon_div.css('left', l.toString() + 'px')
225 speech_balloon_div.css('width', w + 'px')
226 $(trace_balloon + 'width').val(w)
227 $(trace_balloon + 'height').val(h)
228 speech_balloon_div.css('width', w.toString() + 'px')
229 speech_balloon_div.css('height', h.toString() + 'px')
230 resize: ( event, ui ) ->
232 speech_balloon_div = resize_div.parent()
233 balloon = $('.pettanr-balloon', $(@))
234 trace = editor.element_tag_id(speech_balloon_div)
235 trace_balloon = editor.element_part_tag_id(balloon)
240 $('.pettanr-comic-speech-inner' ).map ->
242 outer = $(@).parent()
244 trace = editor.element_tag_id(sb)
245 img = $('.pettanr-balloon', $(trace))
246 $('.ui-resizable-handle', img.parent()).map ->
247 $(@).css('display', 'block')
249 outer = $(@).parent()
251 trace = editor.element_tag_id(sb)
252 img = $('.pettanr-balloon', $(trace))
253 $('.ui-resizable-handle', img.parent()).map ->
254 $(@).css('display', 'none')
259 if editor.element_is('speech_balloon', $(@))
261 switch $(@).attr('column')
263 trace = editor.element_tag_id($(@))
264 v = parseInt($(@).val()).toString() + 'px'
265 $(trace).css('left', v)
267 trace = editor.element_tag_id($(@))
268 v = parseInt($(@).val()).toString() + 'px'
269 $(trace).css('top', v)
271 trace = editor.element_tag_id($(@))
272 v = parseInt($(@).val())
273 $(trace).width(Math.abs(v))
274 img = $('.pettanr-balloon', $(trace))
275 img.parent().width(v)
278 trace = editor.element_tag_id($(@))
279 v = parseInt($(@).val())
280 $(trace).height(Math.abs(v))
281 img = $('.pettanr-balloon', $(trace))
282 img.parent().height(v)
287 if editor.element_is('speech_balloon', $(@))
289 switch $(@).attr('column')
291 trace = editor.element_part_tag_id($(@))
292 wf_sel = $(trace + 'writing_format_id')
293 wf_id = parseInt(wf_sel.val())
294 v = WritingFormat.render(wf_id, $(@).val())
297 if editor.element_is('speech_balloon', $(@))
298 switch $(@).attr('column')
300 $(@).bind('textchange', (event, previousText) ->
301 trace = editor.element_part_tag_id($(@))
302 wf_sel = $(trace + 'writing_format_id')
303 wf_id = parseInt(wf_sel.val())
304 v = WritingFormat.render(wf_id, $(@).val())
308 if editor.element_is('speech_balloon', $(@))
310 switch $(@).attr('column')
312 trace = editor.element_part_tag_id($(@))
313 $(trace).css('font-size', $(@).val() + 'em')
315 trace = editor.element_part_tag_id($(@))
316 v = parseInt($(@).val())
317 $(trace).css('text-align', editor.text_align_texts[v])
320 if editor.element_is('speech_balloon', $(@))
321 if $(@).attr('column') == 'fore_color'
328 if editor.element_is('ground_picture', $(@))
330 switch $(@).attr('column')
332 trace = editor.element_tag_id($(@))
333 x = parseInt($(trace + 'x').val()).toString() + 'px'
334 y = parseInt($(trace + 'y').val()).toString() + 'px'
335 $(trace).css('background-position', x + ' ' + y)
337 if editor.element_is('ground_picture', $(@))
339 switch $(@).attr('column')
341 trace = editor.element_tag_id($(@))
342 v = parseInt($(@).val())
343 $(trace).css('background-repeat', editor.repeat_texts[v])
348 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
352 if editor.element_is('ground_color', $(@))
353 if $(@).attr('column') == 'code'
356 update_t = (ultrace) ->
358 $(ultrace + ' li').map ->
359 trace = editor.element_tag_id($(@))
360 if $(trace + '_destroy').val().length < 1
361 $(trace + 't').val(t)
367 update: ( event, ui ) ->
368 trace = editor.panel_tag_id($(@))
369 update_t(trace + 'tsort')
371 $('.t-sort li').map ->
372 $(@).disableSelection()
374 update_z = (ultrace) ->
376 $(ultrace + ' li').map ->
377 trace = editor.element_tag_id($(@))
379 if $(trace + '_destroy').val().length < 1
380 $(trace + 'z').val(z)
381 switch $(@).attr('element_type')
383 trace = trace + 'div'
384 $(trace).css('zIndex', z)
390 update: ( event, ui ) ->
391 trace = editor.panel_tag_id($(@))
392 update_z(trace + 'zsort')
394 $('.z-sort li').map ->
395 $(@).disableSelection()
398 # disable form actions
399 # hide submit buttons
400 $('.edit_panel_picture' ).map ->
403 $('.edit_speech_balloon' ).map ->
406 $('.edit_ground_picture' ).map ->
409 $('.edit_ground_color' ).map ->
413 $('.edit_panel' ).map ->
414 if $(@).attr('jqform')
424 if editor.is_element($(@))
425 switch $(@).attr('column')
428 $(@).parent().hide() #label
430 # add button on new form
431 $('.submit-new-form').map ->
432 $(@).html('<button class="new-element">add</button>')
434 $('.new-element').map ->