2 confirm_confirm_confirm = () ->
\r
4 new_element_index = {}
\r
5 new_element_index[pettanr_current_panel_id] = 0
\r
8 $("<div/>").text(t).html()
\r
10 set_tree_value = (keys, last_attr, value) ->
\r
13 last_attr[key] = value
\r
15 last_attr[key] = last_attr[key] || {}
\r
16 set_tree_value(keys, last_attr[key], value)
\r
18 repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
\r
20 is_editable = (p) ->
\r
21 if p.parent().attr('editable')
\r
26 if o.attr('column')
\r
27 if o.attr('column') == '_destroy' and o.val().length < 1
\r
34 if o.attr('element_type')
\r
38 is_element_part = (o) ->
\r
39 if o.attr('element_part_type')
\r
43 element_types = {'panel_picture': 'panel_pictures', 'speech_balloon': 'speech_balloons', 'ground_picture': 'ground_pictures', 'ground_color': 'ground_colors'}
\r
44 element_type_to_table = (element_type) ->
\r
45 element_types[element_type]
\r
46 make_tree = (attr, o) ->
\r
48 tree = 'panels-' + o.attr('panel_id') + '-'
\r
50 tree = tree + element_type_to_table(o.attr('element_type')) + '_attributes-' + o.attr('element_id') + '-'
\r
51 if is_element_part(o)
\r
52 tree = tree + o.attr('element_part_type') + '_attributes-'
\r
53 tree = tree + o.attr('column')
\r
54 keys = tree.split('-')
\r
55 set_tree_value(keys, attr, o.val())
\r
57 panel_tag_id = (element) ->
\r
58 '#panel' + element.attr('panel_id')
\r
60 element_tag_id = (element) ->
\r
61 '#panel' + element.attr('panel_id') + element.attr('element_type') + element.attr('element_id')
\r
63 refresh_attribute = () ->
\r
66 make_tree(attr, $(@))
\r
67 $('textarea').map ->
\r
68 make_tree(attr, $(@))
\r
70 make_tree(attr, $(@))
\r
71 $('#pettanr-panel-json').val(JSON.stringify(attr['panels'][pettanr_current_panel_id.toString() ]))
\r
74 $('#elements-tabs').tabs()
\r
75 $('#new-element-tabs').tabs()
\r
76 $('#new-speech_balloon-tabs').tabs()
\r
77 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
78 $("#elements-tabs li").removeClass("ui-corner-top")
\r
79 $("#elements-tabs li").addClass("ui-corner-left")
\r
80 $("#elements-tabs li").map ->
\r
82 switch $(@).attr('element_type')
\r
83 when 'speech_balloon'
\r
84 trace = element_tag_id($(@))
\r
85 t = $('img', $(trace))
\r
86 when 'panel_picture'
\r
87 trace = element_tag_id($(@)) + 'img'
\r
92 $('.ui-resizable-handle', t.parent()).map ->
\r
93 $(@).css('display', 'block')
\r
95 switch $(@).attr('element_type')
\r
96 when 'speech_balloon'
\r
97 trace = element_tag_id($(@))
\r
98 t = $('img', $(trace))
\r
99 when 'panel_picture'
\r
100 trace = element_tag_id($(@)) + 'img'
\r
105 $('.ui-resizable-handle', t.parent()).map ->
\r
106 $(@).css('display', 'none')
\r
109 $('.ui-icon-destroy').map ->
\r
112 primary: 'ui-icon-close',
\r
118 if confirm('destroy ?')
\r
119 trace = element_tag_id($(@))
\r
120 $(trace + '_destroy').val('true')
\r
121 panel_trace = panel_tag_id($(@))
\r
122 update_t(panel_trace + 'tsort')
\r
123 update_z(panel_trace + 'zsort')
\r
125 $(trace + 'element_tab').css('display', 'none')
\r
126 $(trace + 'tab_panel').css('display', 'none')
\r
127 $(trace + 'zsort').css('display', 'none')
\r
128 $(trace + 'tsort').css('display', 'none')
\r
129 switch $(@).attr('element_type')
\r
130 when 'panel_picture'
\r
131 trace = trace + 'div'
\r
132 $(trace).css('display', 'none')
\r
135 $('#pettanr-panel-submit').focusin ->
\r
136 refresh_attribute()
\r
139 $('.pettanr-comic-panel').map ->
\r
140 if is_editable($(@))
\r
142 stop: ( event, ui ) ->
\r
143 trace = panel_tag_id($(@))
\r
144 w = parseInt($(@).width())
\r
145 h = parseInt($(@).height())
\r
146 $(trace + 'width').val(w)
\r
147 $(trace + 'height').val(h)
\r
148 $('.pettanr-comic-ground-picture').map ->
\r
151 $('.pettanr-comic-ground-color').map ->
\r
157 $('#panel' + pettanr_current_panel_id.toString() + 'width').focusout ->
\r
158 trace = '#panel' + $(@).attr('panel_id')
\r
159 $(trace).width(parseInt( $(@).val()))
\r
161 $('#panel' + pettanr_current_panel_id.toString() + 'height').focusout ->
\r
162 trace = '#panel' + $(@).attr('panel_id')
\r
163 $(trace).height(parseInt( $(@).val()))
\r
165 $('#panel' + pettanr_current_panel_id.toString() + 'border').focusout ->
\r
166 trace = '#panel' + $(@).attr('panel_id')
\r
167 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
171 $('.pettanr-panel-picture-wrapper').map ->
\r
173 stop: ( event, ui ) ->
\r
174 trace = '#panel' + $(@).attr('panel_id') + 'panel_picture' + $(@).attr('element_id')
\r
175 img = '#panel' + $(@).attr('panel_id') + 'panel_picture' + $(@).attr('element_id') + 'img'
\r
176 left = $(img).parent().position().left + $(@).position().left
\r
177 top = $(img ).parent().position().top + $(@).position().top
\r
178 $(trace + 'x').val(parseInt(left))
\r
179 $(trace + 'y').val(parseInt(top))
\r
182 $('.panel-picture').map ->
\r
184 stop: ( event, ui ) ->
\r
185 trace = '#panel' + $(@).parent().attr('panel_id') + 'panel_picture' + $(@).parent().attr('element_id')
\r
186 $(trace + 'width').val($(@).width())
\r
187 $(trace + 'height').val($(@).height())
\r
192 refresh_picture = (e, w, h) ->
\r
201 pid = parseInt(e.attr('picture_id')).toString()
\r
202 ext = e.attr('ext')
\r
203 src = '/pictures/' + sd + pid + '.' + ext
\r
208 if $(@).attr('element_type') and $(@).attr('element_type') == 'panel_picture'
\r
210 switch $(@).attr('column')
\r
212 trace = element_tag_id($(@)) + 'div'
\r
213 v = parseInt($(@).val()).toString() + 'px'
\r
214 $(trace).css('left', v)
\r
216 trace = element_tag_id($(@)) + 'div'
\r
217 v = parseInt($(@).val()).toString() + 'px'
\r
218 $(trace).css('top', v)
\r
220 trace = element_tag_id($(@)) + 'img'
\r
221 w = parseInt($(@).val())
\r
222 $(trace).width(Math.abs(w))
\r
223 $(trace).parent().width(Math.abs(w))
\r
224 h = parseInt($(element_tag_id($(@)) + 'height').val())
\r
226 trace = element_tag_id($(@)) + 'img'
\r
227 h = parseInt($(@).val())
\r
228 $(trace).height(Math.abs(h))
\r
229 $(trace).parent().height(Math.abs(h))
\r
230 w = parseInt($(element_tag_id($(@)) + 'width').val())
\r
232 refresh_picture($(trace), w, h)
\r
236 $('.pettanr-comic-balloon' ).map ->
\r
238 stop: ( event, ui ) ->
\r
239 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'balloon' + $(@).attr('balloon_id')
\r
240 left = $(@).position().left
\r
241 top = $(@).position().top
\r
242 $(trace + 'x').val(parseInt(left))
\r
243 $(trace + 'y').val(parseInt(top))
\r
247 $('.pettanr-balloon' ).map ->
\r
249 stop: ( event, ui ) ->
\r
250 trace = '#panel' + $(@).parent().attr('panel_id') + 'speech_balloon' + $(@).parent().attr('element_id') + 'balloon' + $(@).parent().attr('balloon_id')
\r
251 $(trace + 'width').val($(@).width())
\r
252 $(trace + 'height').val($(@).height())
\r
253 resize: ( event, ui ) ->
\r
254 trace = '#panel' + $(@).parent().attr('panel_id') + 'speech_balloon' + $(@).parent().attr('element_id')
\r
255 $(trace).width($(@).width())
\r
256 $(trace).height($(@).height())
\r
260 $('.pettanr-comic-balloon span' ).map ->
\r
264 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'balloon' + $(@).attr('balloon_id')
\r
266 $('.ui-resizable-handle', img.parent()).map ->
\r
267 $(@).css('display', 'block')
\r
269 trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'balloon' + $(@).attr('balloon_id')
\r
271 $('.ui-resizable-handle', img.parent()).map ->
\r
272 $(@).css('display', 'none')
\r
277 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
279 switch $(@).attr('column')
\r
281 trace = element_tag_id($(@))
\r
282 v = parseInt($(@).val()).toString() + 'px'
\r
283 $(trace).css('left', v)
\r
285 trace = element_tag_id($(@))
\r
286 v = parseInt($(@).val()).toString() + 'px'
\r
287 $(trace).css('top', v)
\r
289 trace = element_tag_id($(@))
\r
290 v = parseInt($(@).val())
\r
291 $(trace).width(Math.abs(v))
\r
292 trace = '#panel' + $(trace).attr('panel_id') + 'speech_balloon' + $(trace).attr('element_id') + 'balloon' + $(trace).attr('balloon_id')
\r
293 $(trace).parent().width(v)
\r
296 trace = element_tag_id($(@))
\r
297 v = parseInt($(@).val())
\r
298 $(trace).height(Math.abs(v))
\r
299 trace = '#panel' + $(trace).attr('panel_id') + 'speech_balloon' + $(trace).attr('element_id') + 'balloon' + $(trace).attr('balloon_id')
\r
300 $(trace).parent().height(v)
\r
304 $('textarea').map ->
\r
305 if $(@).attr('element_type') and $(@).attr('element_type') == 'speech_balloon'
\r
307 switch $(@).attr('column')
\r
309 trace = element_tag_id($(@))
\r
310 speech_trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'speech' + $(@).attr('element_part_id')
\r
311 v = escapeHTML($(@).val())
\r
312 $(speech_trace).html(v)
\r
317 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_picture'
\r
319 switch $(@).attr('column')
\r
321 trace = element_tag_id($(@))
\r
322 x = parseInt($(@).val()).toString() + 'px'
\r
323 ytrace = '#panel' + $(@).attr('panel_id') + 'ground_picture' + $(@).attr('element_id') + 'y'
\r
324 y = parseInt($(ytrace).val()).toString() + 'px'
\r
325 $(trace).css('background-position', y + ' ' + x)
\r
327 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_picture'
\r
329 switch $(@).attr('column')
\r
331 trace = element_tag_id($(@))
\r
332 v = parseInt($(@).val())
\r
333 $(trace).css('background-repeat', repeat_texts[v])
\r
340 if $(@).attr('element_type') and $(@).attr('element_type') == 'ground_color' and $(@).attr('column') == 'code'
\r
343 color_slider_change = (trace) ->
\r
344 red = $(trace + 'code_red').slider('value')
\r
345 green = $(trace + 'code_green').slider('value')
\r
346 blue = $(trace + 'code_blue').slider('value')
\r
347 code = (red << 16) + (green << 8) + (blue)
\r
348 phex = "000000" + code.toString(16)
\r
349 hex = code.toString(16)
\r
350 h = phex.substring(phex.length - 6)
\r
351 $(trace + 'code_swatch').css('background-color', '#' + h)
\r
352 $(trace + 'code_hex').html('HEX: #' + h)
\r
353 $(trace + 'code_rgb').html('RGB: (' + red + ',' + green + ',' +blue + ')')
\r
354 $(trace + 'code').val(code)
\r
356 $(trace).css('background-color', v)
\r
358 $('.colorpicker').map ->
\r
359 code_picker_trace = element_tag_id($(@))
\r
360 code = parseInt($(code_picker_trace + 'code').val())
\r
361 red = (code >> 16) & 0xFF
\r
362 green = (code >> 8) & 0xFF
\r
364 $(code_picker_trace + 'code_red').slider {
\r
365 orientation: 'horizontal',
\r
369 change: ( event, ui ) ->
\r
370 trace = element_tag_id($(@).parent())
\r
371 color_slider_change(trace)
\r
373 $(code_picker_trace + 'code_green').slider {
\r
374 orientation: 'horizontal',
\r
378 change: ( event, ui ) ->
\r
379 trace = element_tag_id($(@).parent())
\r
380 color_slider_change(trace)
\r
382 $(code_picker_trace + 'code_blue').slider {
\r
383 orientation: 'horizontal',
\r
387 change: ( event, ui ) ->
\r
388 trace = element_tag_id($(@).parent())
\r
389 color_slider_change(trace)
\r
391 color_slider_change(code_picker_trace)
\r
392 $('.colorpicker-wrap').map ->
\r
393 $(@).css('display', 'block')
\r
395 update_t = (ultrace) ->
\r
397 $(ultrace + ' li').map ->
\r
398 trace = element_tag_id($(@))
\r
399 if $(trace + '_destroy').val().length < 1
\r
400 $(trace + 't').val(t)
\r
404 $('.tsort').map ->
\r
406 update: ( event, ui ) ->
\r
407 trace = panel_tag_id($(@))
\r
408 update_t(trace + 'tsort')
\r
410 $('.t-sort li').map ->
\r
411 $(@).disableSelection()
\r
413 update_z = (ultrace) ->
\r
415 $(ultrace + ' li').map ->
\r
416 trace = element_tag_id($(@))
\r
418 if $(trace + '_destroy').val().length < 1
\r
419 $(trace + 'z').val(z)
\r
420 switch $(@).attr('element_type')
\r
421 when 'panel_picture'
\r
422 trace = trace + 'div'
\r
423 $(trace).css('zIndex', z)
\r
427 $('.zsort').map ->
\r
429 update: ( event, ui ) ->
\r
430 trace = panel_tag_id($(@))
\r
431 update_z(trace + 'zsort')
\r
433 $('.z-sort li').map ->
\r
434 $(@).disableSelection()
\r
436 $('.panel_picture_width_tool').map ->
\r
437 $(@).html('<button class="wreverse">Rev</button><button class="wdouble">x2</button><button class="whalf">/2</button>')
\r
439 $('.wreverse').click ->
\r
441 trace = element_tag_id(d)
\r
442 f = $(trace + 'width')
\r
445 f = $(trace + 'height')
\r
447 refresh_picture($(trace + 'img'), w, h)
\r
449 $('.wdouble').click ->
\r
451 trace = element_tag_id(d)
\r
452 f = $(trace + 'width')
\r
455 $(trace + 'img').width(Math.abs(w))
\r
456 $(trace + 'img').parent().width(Math.abs(w))
\r
458 $('.whalf').click ->
\r
460 trace = element_tag_id(d)
\r
461 f = $(trace + 'width')
\r
462 w = Math.floor(f.val() / 2)
\r
464 $(trace + 'img').width(Math.abs(w))
\r
465 $(trace + 'img').parent().width(Math.abs(w))
\r
467 $('.panel_picture_height_tool').map ->
\r
468 $(@).html('<button class="hreverse">Rev</button><button class="hdouble">x2</button><button class="hhalf">/2</button>')
\r
470 $('.hreverse').click ->
\r
472 trace = element_tag_id(d)
\r
473 f = $(trace + 'height')
\r
476 f = $(trace + 'width')
\r
478 refresh_picture($(trace + 'img'), w, h)
\r
480 $('.hdouble').click ->
\r
482 trace = element_tag_id(d)
\r
483 f = $(trace + 'height')
\r
486 $(trace + 'img').height(Math.abs(h))
\r
487 $(trace + 'img').parent().height(Math.abs(h))
\r
489 $('.hhalf').click ->
\r
491 trace = element_tag_id(d)
\r
492 f = $(trace + 'height')
\r
493 h = Math.floor(f.val() / 2)
\r
495 $(trace + 'img').height(Math.abs(h))
\r
496 $(trace + 'img').parent().height(Math.abs(h))
\r
499 # disable form actions
\r
500 # hide submit buttons
\r
501 $('.edit_panel_picture' ).map ->
\r
504 $('.edit_speech_balloon' ).map ->
\r
507 $('.edit_ground_picture' ).map ->
\r
510 $('.edit_ground_color' ).map ->
\r
514 $('.edit_panel' ).map ->
\r
515 if $(@).attr('jqform')
\r
520 $('.submit' ).map ->
\r
525 if $(@).attr('element_type') and $(@).attr('column')
\r
526 switch $(@).attr('column')
\r
529 $(@).parent().hide() #label
\r
531 # add button on new form
\r
532 $('.submit-new-form').map ->
\r
533 $(@).html('<button class="new-element">add</button>')
\r
535 $('.new-element').map ->
\r