2 confirm_confirm_confirm = () ->
\r
4 editor = window.PettanrEditor
\r
6 $('.panel-editor').map ->
\r
7 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
8 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
10 $('#elements-tabs').tabs()
\r
11 $('#new-element-tabs').tabs()
\r
12 $('#new-speech_balloon-tabs').tabs()
\r
13 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
14 $("#elements-tabs li").removeClass("ui-corner-top")
\r
15 $("#elements-tabs li").addClass("ui-corner-left")
\r
16 $("#elements-tabs li").map ->
\r
18 switch $(@).attr('element_type')
\r
19 when 'speech_balloon'
\r
20 trace = editor.element_tag_id($(@))
\r
21 t = $('img', $(trace))
\r
22 when 'panel_picture'
\r
23 trace = editor.element_tag_id($(@)) + 'img'
\r
28 $('.ui-resizable-handle', t.parent()).map ->
\r
29 $(@).css('display', 'block')
\r
31 switch $(@).attr('element_type')
\r
32 when 'speech_balloon'
\r
33 trace = editor.element_tag_id($(@))
\r
34 t = $('img', $(trace))
\r
35 when 'panel_picture'
\r
36 trace = editor.element_tag_id($(@)) + 'img'
\r
41 $('.ui-resizable-handle', t.parent()).map ->
\r
42 $(@).css('display', 'none')
\r
45 $('.ui-icon-destroy').map ->
\r
48 primary: 'ui-icon-close',
\r
54 if confirm('destroy ?')
\r
55 trace = editor.element_tag_id($(@))
\r
56 $(trace + '_destroy').val('true')
\r
57 panel_trace = editor.panel_tag_id($(@))
\r
58 update_t(panel_trace + 'tsort')
\r
59 update_z(panel_trace + 'zsort')
\r
61 $(trace + 'element_tab').css('display', 'none')
\r
62 $(trace + 'tab_panel').css('display', 'none')
\r
63 $(trace + 'zsort').css('display', 'none')
\r
64 $(trace + 'tsort').css('display', 'none')
\r
65 switch $(@).attr('element_type')
\r
66 when 'panel_picture'
\r
67 trace = trace + 'div'
\r
68 $(trace).css('display', 'none')
\r
71 $('#pettanr-panel-submit').focusin ->
\r
72 editor.refresh_attribute($('#pettanr-panel-json'))
\r
75 $('.pettanr-comic-panel').map ->
\r
76 if editor.is_editable($(@))
\r
78 stop: ( event, ui ) ->
\r
79 trace = editor.panel_tag_id($(@))
\r
80 w = parseInt($(@).width())
\r
81 h = parseInt($(@).height())
\r
82 $(trace + 'width').val(w)
\r
83 $(trace + 'height').val(h)
\r
84 $('.pettanr-comic-ground-picture').map ->
\r
87 $('.pettanr-comic-ground-color').map ->
\r
94 if $(@).attr('element_type')
\r
96 if $(@).attr('panel_id')
\r
98 switch $(@).attr('column')
\r
100 trace = editor.panel_tag_id($(@))
\r
101 $(trace).width(parseInt( $(@).val()))
\r
103 trace = editor.panel_tag_id($(@))
\r
104 $(trace).height(parseInt( $(@).val()))
\r
106 trace = editor.panel_tag_id($(@))
\r
107 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
111 $('.pettanr-panel-picture-wrapper').map ->
\r
113 stop: ( event, ui ) ->
\r
114 trace = '#panel' + $(@).attr('panel_id') + 'panel_picture' + $(@).attr('element_id')
\r
115 img = '#panel' + $(@).attr('panel_id') + 'panel_picture' + $(@).attr('element_id') + 'img'
\r
116 left = $(img).parent().position().left + $(@).position().left
\r
117 top = $(img ).parent().position().top + $(@).position().top
\r
118 $(trace + 'x').val(parseInt(left))
\r
119 $(trace + 'y').val(parseInt(top))
\r
122 $('.panel-picture').map ->
\r
124 stop: ( event, ui ) ->
\r
125 trace = '#panel' + $(@).parent().attr('panel_id') + 'panel_picture' + $(@).parent().attr('element_id')
\r
126 $(trace + 'width').val($(@).width())
\r
127 $(trace + 'height').val($(@).height())
\r
132 refresh_picture = (e, w, h) ->
\r
141 pid = parseInt(e.attr('picture_id')).toString()
\r
142 ext = e.attr('ext')
\r
143 src = '/pictures/' + sd + pid + '.' + ext
\r
148 if $(@).attr('element_type') and $(@).attr('element_type') == 'panel_picture'
\r
150 switch $(@).attr('column')
\r
152 trace = editor.element_tag_id($(@)) + 'div'
\r
153 v = parseInt($(@).val()).toString() + 'px'
\r
154 $(trace).css('left', v)
\r
156 trace = editor.element_tag_id($(@)) + 'div'
\r
157 v = parseInt($(@).val()).toString() + 'px'
\r
158 $(trace).css('top', v)
\r
160 trace = editor.element_tag_id($(@)) + 'img'
\r
161 w = parseInt($(@).val())
\r
162 $(trace).width(Math.abs(w))
\r
163 $(trace).parent().width(Math.abs(w))
\r
164 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
166 trace = editor.element_tag_id($(@)) + 'img'
\r
167 h = parseInt($(@).val())
\r
168 $(trace).height(Math.abs(h))
\r
169 $(trace).parent().height(Math.abs(h))
\r
170 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
172 refresh_picture($(trace), w, h)
\r
176 $('.pettanr-comic-balloon' ).map ->
\r
178 stop: ( event, ui ) ->
\r
179 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'balloon' + $(@).attr('balloon_id')
\r
180 left = $(@).position().left
\r
181 top = $(@).position().top
\r
182 $(trace + 'x').val(parseInt(left))
\r
183 $(trace + 'y').val(parseInt(top))
\r
187 $('.pettanr-balloon' ).map ->
\r
189 stop: ( event, ui ) ->
\r
190 trace = '#panel' + $(@).parent().attr('panel_id') + 'speech_balloon' + $(@).parent().attr('element_id') + 'balloon' + $(@).parent().attr('balloon_id')
\r
191 $(trace + 'width').val($(@).width())
\r
192 $(trace + 'height').val($(@).height())
\r
193 resize: ( event, ui ) ->
\r
194 trace = '#panel' + $(@).parent().attr('panel_id') + 'speech_balloon' + $(@).parent().attr('element_id')
\r
195 $(trace).width($(@).width())
\r
196 $(trace).height($(@).height())
\r
200 $('.pettanr-comic-speech-inner' ).map ->
\r
202 outer = $(@).parent()
\r
203 sb = outer.parent()
\r
204 trace = '#panel' + sb.attr('panel_id') + 'speech_balloon' + sb.attr('element_id') + 'balloon' + sb.attr('balloon_id')
\r
206 $('.ui-resizable-handle', img.parent()).map ->
\r
207 $(@).css('display', 'block')
\r
209 outer = $(@).parent()
\r
210 sb = outer.parent()
\r
211 trace = '#panel' + sb.attr('panel_id') + 'speech_balloon' + sb.attr('element_id') + 'balloon' + sb.attr('balloon_id')
\r
213 $('.ui-resizable-handle', img.parent()).map ->
\r
214 $(@).css('display', 'none')
\r
219 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
221 switch $(@).attr('column')
\r
223 trace = editor.element_tag_id($(@))
\r
224 v = parseInt($(@).val()).toString() + 'px'
\r
225 $(trace).css('left', v)
\r
227 trace = editor.element_tag_id($(@))
\r
228 v = parseInt($(@).val()).toString() + 'px'
\r
229 $(trace).css('top', v)
\r
231 trace = editor.element_tag_id($(@))
\r
232 v = parseInt($(@).val())
\r
233 $(trace).width(Math.abs(v))
\r
234 trace = '#panel' + $(trace).attr('panel_id') + 'speech_balloon' + $(trace).attr('element_id') + 'balloon' + $(trace).attr('balloon_id')
\r
235 $(trace).parent().width(v)
\r
238 trace = editor.element_tag_id($(@))
\r
239 v = parseInt($(@).val())
\r
240 $(trace).height(Math.abs(v))
\r
241 trace = '#panel' + $(trace).attr('panel_id') + 'speech_balloon' + $(trace).attr('element_id') + 'balloon' + $(trace).attr('balloon_id')
\r
242 $(trace).parent().height(v)
\r
246 $('textarea').map ->
\r
247 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
249 switch $(@).attr('column')
\r
251 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'speech' + $(@).attr('element_part_id')
\r
252 wf_sel = $(trace + 'writing_format_id')
\r
253 wf_id = parseInt(wf_sel.val())
\r
254 v = writing_format_functions[writing_formats[wf_id]]($(@).val())
\r
256 $('textarea').map ->
\r
257 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
258 switch $(@).attr('column')
\r
260 $(@).bind('textchange', (event, previousText) ->
\r
261 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'speech' + $(@).attr('element_part_id')
\r
262 wf_sel = $(trace + 'writing_format_id')
\r
263 wf_id = parseInt(wf_sel.val())
\r
264 v = writing_format_functions[writing_formats[wf_id]]($(@).val())
\r
265 $(trace).html('<p>' + v + '</p>')
\r
268 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
270 switch $(@).attr('column')
\r
272 trace = editor.element_part_tag_id($(@))
\r
273 $(trace).css('font-size', $(@).val() + 'em')
\r
275 trace = editor.element_part_tag_id($(@))
\r
276 v = parseInt($(@).val())
\r
277 $(trace).css('text-align', text_align_texts[v])
\r
280 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon' and $(@).attr('column') == 'fore_color'
\r
287 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_picture'
\r
289 switch $(@).attr('column')
\r
291 trace = editor.element_tag_id($(@))
\r
292 x = parseInt($(@).val()).toString() + 'px'
\r
293 ytrace = '#panel' + $(@).attr('panel_id') + 'ground_picture' + $(@).attr('element_id') + 'y'
\r
294 y = parseInt($(ytrace).val()).toString() + 'px'
\r
295 $(trace).css('background-position', y + ' ' + x)
\r
297 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_picture'
\r
299 switch $(@).attr('column')
\r
301 trace = editor.element_tag_id($(@))
\r
302 v = parseInt($(@).val())
\r
303 $(trace).css('background-repeat', repeat_texts[v])
\r
310 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_color' and $(@).attr('column') == 'code'
\r
313 color_slider_change = (trace) ->
\r
314 red = $(trace + 'code_red').slider('value')
\r
315 green = $(trace + 'code_green').slider('value')
\r
316 blue = $(trace + 'code_blue').slider('value')
\r
317 code = (red << 16) + (green << 8) + (blue)
\r
318 phex = "000000" + code.toString(16)
\r
319 hex = code.toString(16)
\r
320 h = phex.substring(phex.length - 6)
\r
321 $(trace + 'code_swatch').css('background-color', '#' + h)
\r
322 $(trace + 'code_hex').html('HEX: #' + h)
\r
323 $(trace + 'code_rgb').html('RGB: (' + red + ',' + green + ',' +blue + ')')
\r
325 if editor.is_element_part($(trace))
\r
326 $(trace + 'fore_color').val(code)
\r
327 $(trace).css('color', v)
\r
329 $(trace + 'code').val(code)
\r
330 $(trace).css('background-color', v)
\r
332 $('.colorpicker').map ->
\r
333 if editor.is_element_part($(@))
\r
334 code_picker_trace = editor.element_part_tag_id($(@))
\r
335 code = parseInt($(code_picker_trace + 'fore_color').val())
\r
337 code_picker_trace = editor.element_tag_id($(@))
\r
338 code = parseInt($(code_picker_trace + 'code').val())
\r
339 red = (code >> 16) & 0xFF
\r
340 green = (code >> 8) & 0xFF
\r
342 $(code_picker_trace + 'code_red').slider {
\r
343 orientation: 'horizontal',
\r
347 change: ( event, ui ) ->
\r
348 if editor.is_element_part($(@).parent())
\r
349 trace = editor.element_part_tag_id($(@).parent())
\r
351 trace = editor.element_tag_id($(@).parent())
\r
352 color_slider_change(trace)
\r
354 $(code_picker_trace + 'code_green').slider {
\r
355 orientation: 'horizontal',
\r
359 change: ( event, ui ) ->
\r
360 if editor.is_element_part($(@).parent())
\r
361 trace = editor.element_part_tag_id($(@).parent())
\r
363 trace = editor.element_tag_id($(@).parent())
\r
364 color_slider_change(trace)
\r
366 $(code_picker_trace + 'code_blue').slider {
\r
367 orientation: 'horizontal',
\r
371 change: ( event, ui ) ->
\r
372 if editor.is_element_part($(@).parent())
\r
373 trace = editor.element_part_tag_id($(@).parent())
\r
375 trace = editor.element_tag_id($(@).parent())
\r
376 color_slider_change(trace)
\r
378 color_slider_change(code_picker_trace)
\r
379 $('.colorpicker-wrap').map ->
\r
380 $(@).css('display', 'block')
\r
382 update_t = (ultrace) ->
\r
384 $(ultrace + ' li').map ->
\r
385 trace = editor.element_tag_id($(@))
\r
386 if $(trace + '_destroy').val().length < 1
\r
387 $(trace + 't').val(t)
\r
391 $('.tsort').map ->
\r
393 update: ( event, ui ) ->
\r
394 trace = editor.panel_tag_id($(@))
\r
395 update_t(trace + 'tsort')
\r
397 $('.t-sort li').map ->
\r
398 $(@).disableSelection()
\r
400 update_z = (ultrace) ->
\r
402 $(ultrace + ' li').map ->
\r
403 trace = editor.element_tag_id($(@))
\r
405 if $(trace + '_destroy').val().length < 1
\r
406 $(trace + 'z').val(z)
\r
407 switch $(@).attr('element_type')
\r
408 when 'panel_picture'
\r
409 trace = trace + 'div'
\r
410 $(trace).css('zIndex', z)
\r
414 $('.zsort').map ->
\r
416 update: ( event, ui ) ->
\r
417 trace = editor.panel_tag_id($(@))
\r
418 update_z(trace + 'zsort')
\r
420 $('.z-sort li').map ->
\r
421 $(@).disableSelection()
\r
423 $('.panel_picture_width_tool').map ->
\r
424 $(@).html('<button class="wreverse">Rev</button><button class="wdouble">x2</button><button class="whalf">/2</button>')
\r
426 $('.wreverse').click ->
\r
428 trace = editor.element_tag_id(d)
\r
429 f = $(trace + 'width')
\r
432 f = $(trace + 'height')
\r
434 refresh_picture($(trace + 'img'), w, h)
\r
436 $('.wdouble').click ->
\r
438 trace = editor.element_tag_id(d)
\r
439 f = $(trace + 'width')
\r
442 $(trace + 'img').width(Math.abs(w))
\r
443 $(trace + 'img').parent().width(Math.abs(w))
\r
445 $('.whalf').click ->
\r
447 trace = editor.element_tag_id(d)
\r
448 f = $(trace + 'width')
\r
449 w = Math.floor(f.val() / 2)
\r
451 $(trace + 'img').width(Math.abs(w))
\r
452 $(trace + 'img').parent().width(Math.abs(w))
\r
454 $('.panel_picture_height_tool').map ->
\r
455 $(@).html('<button class="hreverse">Rev</button><button class="hdouble">x2</button><button class="hhalf">/2</button>')
\r
457 $('.hreverse').click ->
\r
459 trace = editor.element_tag_id(d)
\r
460 f = $(trace + 'height')
\r
463 f = $(trace + 'width')
\r
465 refresh_picture($(trace + 'img'), w, h)
\r
467 $('.hdouble').click ->
\r
469 trace = editor.element_tag_id(d)
\r
470 f = $(trace + 'height')
\r
473 $(trace + 'img').height(Math.abs(h))
\r
474 $(trace + 'img').parent().height(Math.abs(h))
\r
476 $('.hhalf').click ->
\r
478 trace = editor.element_tag_id(d)
\r
479 f = $(trace + 'height')
\r
480 h = Math.floor(f.val() / 2)
\r
482 $(trace + 'img').height(Math.abs(h))
\r
483 $(trace + 'img').parent().height(Math.abs(h))
\r
486 # disable form actions
\r
487 # hide submit buttons
\r
488 $('.edit_panel_picture' ).map ->
\r
491 $('.edit_speech_balloon' ).map ->
\r
494 $('.edit_ground_picture' ).map ->
\r
497 $('.edit_ground_color' ).map ->
\r
501 $('.edit_panel' ).map ->
\r
502 if $(@).attr('jqform')
\r
507 $('.submit' ).map ->
\r
512 if $(@).attr('element_type') and $(@).attr('column')
\r
513 switch $(@).attr('column')
\r
516 $(@).parent().hide() #label
\r
518 # add button on new form
\r
519 $('.submit-new-form').map ->
\r
520 $(@).html('<button class="new-element">add</button>')
\r
522 $('.new-element').map ->
\r