2 confirm_confirm_confirm = () ->
\r
4 editor = window.PettanrEditor
\r
5 configurations = window.configurations
\r
6 WritingFormat = window.PettanrWritingFormat
\r
7 WritingFormat.load($('#writing_formats'))
\r
8 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
9 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
10 for n, v of SpeechBalloonTemplate.scripts
\r
12 v.add_helper( n, '' )
\r
13 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
14 ColorHelper = window.PettanrColorHelper
\r
16 find_configurations = ( hash, key) ->
\r
17 if typeof(hash[key]) == 'string'
\r
18 find_configurations(hash, hash[key])
\r
22 set_validates = (form) ->
\r
24 $('input', form).map ->
\r
25 model_name = $(@).attr('data-model')
\r
26 column_name = $(@).attr('column')
\r
27 name = $(@).attr('name')
\r
28 if model_name and column_name
\r
29 model = find_configurations(configurations['models'], model_name)
\r
30 rule = model['attributes'][column_name]['rules']
\r
31 trace = editor.element_tag_id($(@))
\r
35 if editor.is_panel(form)
\r
36 validate_panel(form)
\r
38 validate_element(form)
\r
39 if Object.keys(rules).length > 0
\r
40 v = form.validate({ignore:[],rules: rules})
\r
42 validate_panel = (form) ->
\r
43 valid = form.valid()
\r
48 $('a', $('#tabs-1-tab')).map ->
\r
49 $(@).css('background-color', bc)
\r
52 display_element = (element, vis) ->
\r
57 trace = editor.element_tag_id(element)
\r
58 switch element.attr('element_type')
\r
59 when 'panel_picture'
\r
60 trace = trace + 'div'
\r
61 $(trace).css('display', v)
\r
63 validate_element = (form) ->
\r
64 valid = form.valid()
\r
69 display_element(form, valid)
\r
70 trace = editor.element_tag_id(form)
\r
71 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
72 $(@).css('background-color', bc)
\r
75 validate_forms = () ->
\r
77 $('form', $('#tabs-1')).map ->
\r
78 form_name = $(@).attr('data-form-name')
\r
80 if validate_panel($(@))
\r
83 invalid_elements = []
\r
84 $('form', $('#tabs-2')).map ->
\r
85 form_name = $(@).attr('data-form-name')
\r
87 if validate_element($(@))
\r
90 invalid_elements.push form_name
\r
91 if invalid_elements.length > 0
\r
95 $('a', $('#tabs-2-tab')).map ->
\r
96 $(@).css('background-color', bc)
\r
99 form_name = $(@).attr('data-form-name')
\r
102 set_validates(form)
\r
103 $('.panel-editor').map ->
\r
104 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
105 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
106 if editor.is_editting()
\r
108 $('#elements-tabs').tabs()
\r
109 $('#new-element-tabs').tabs()
\r
110 $('#new-speech_balloon-tabs').tabs()
\r
111 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
112 $("#elements-tabs li").removeClass("ui-corner-top")
\r
113 $("#elements-tabs li").addClass("ui-corner-left")
\r
114 $("#elements-tabs li").map ->
\r
116 switch $(@).attr('element_type')
\r
117 when 'speech_balloon'
\r
118 trace = editor.element_tag_id($(@))
\r
119 t = $('img', $(trace))
\r
120 when 'panel_picture'
\r
121 trace = editor.element_tag_id($(@)) + 'img'
\r
126 $('.ui-resizable-handle', t.parent()).map ->
\r
127 $(@).css('display', 'block')
\r
129 switch $(@).attr('element_type')
\r
130 when 'speech_balloon'
\r
131 trace = editor.element_tag_id($(@))
\r
132 t = $('img', $(trace))
\r
133 when 'panel_picture'
\r
134 trace = editor.element_tag_id($(@)) + 'img'
\r
139 $('.ui-resizable-handle', t.parent()).map ->
\r
140 $(@).css('display', 'none')
\r
143 $('.ui-icon-destroy').map ->
\r
146 primary: 'ui-icon-close',
\r
152 if confirm('destroy ?')
\r
153 trace = editor.element_tag_id($(@))
\r
154 $(trace + '_destroy').val('true')
\r
155 panel_trace = editor.panel_tag_id($(@))
\r
156 update_t(panel_trace + 'tsort')
\r
157 update_z(panel_trace + 'zsort')
\r
159 $(trace + 'element_tab').css('display', 'none')
\r
160 $(trace + 'tab_panel').css('display', 'none')
\r
161 $(trace + 'zsort').css('display', 'none')
\r
162 $(trace + 'tsort').css('display', 'none')
\r
163 display_element($(@), false)
\r
165 $('#pettanr-panel-submit').focusin ->
\r
166 editor.refresh_attribute($('#pettanr-panel-json'))
\r
169 $('.pettanr-comic-panel').map ->
\r
170 if editor.is_editable($(@))
\r
172 stop: ( event, ui ) ->
\r
173 trace = editor.panel_tag_id($(@))
\r
174 w = parseInt($(@).width())
\r
175 h = parseInt($(@).height())
\r
176 $(trace + 'width').val(w)
\r
177 $(trace + 'height').val(h)
\r
178 $('.pettanr-comic-ground-picture').map ->
\r
181 $('.pettanr-comic-ground-color').map ->
\r
189 if $(@).attr('element_type')
\r
191 if $(@).attr('panel_id')
\r
193 switch $(@).attr('column')
\r
195 trace = editor.panel_tag_id($(@))
\r
196 $(trace).width(parseInt( $(@).val()))
\r
198 trace = editor.panel_tag_id($(@))
\r
199 $(trace).height(parseInt( $(@).val()))
\r
201 trace = editor.panel_tag_id($(@))
\r
202 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
205 PictureSizeHelper.add_helper()
\r
207 $('.pettanr-panel-picture-wrapper').map ->
\r
209 stop: ( event, ui ) ->
\r
210 trace = editor.element_tag_id($(@))
\r
211 img = $(trace + 'img')
\r
212 left = img.parent().position().left + $(@).position().left
\r
213 top = img.parent().position().top + $(@).position().top
\r
214 $(trace + 'x').val(parseInt(left))
\r
215 $(trace + 'y').val(parseInt(top))
\r
218 $('.panel-picture').map ->
\r
220 stop: ( event, ui ) ->
\r
222 panel_picture_div = resize_div.parent()
\r
223 trace = editor.element_tag_id(panel_picture_div)
\r
225 resize_div.css('top', '0px')
\r
226 resize_div.css('left', '0px')
\r
227 if ui.originalPosition.top != ui.position.top
\r
228 t = panel_picture_div.position().top + ui.position.top
\r
229 $(trace + 'y').val(Math.floor(t))
\r
230 panel_picture_div.css('top', t.toString() + 'px')
\r
231 if ui.originalPosition.left != ui.position.left
\r
232 l = panel_picture_div.position().left + ui.position.left
\r
233 $(trace + 'x').val(Math.floor(l))
\r
234 panel_picture_div.css('left', l.toString() + 'px')
\r
235 w = if $(trace + 'width').val() < 0
\r
239 h = if $(trace + 'height').val() < 0
\r
243 $(trace + 'width').val(w)
\r
244 $(trace + 'height').val(h)
\r
245 resize: ( event, ui ) ->
\r
247 panel_picture_div = resize_div.parent()
\r
248 trace = editor.element_tag_id(panel_picture_div)
\r
255 if editor.element_is('panel_picture', $(@))
\r
257 switch $(@).attr('column')
\r
259 trace = editor.element_tag_id($(@)) + 'div'
\r
260 v = parseInt($(@).val()).toString() + 'px'
\r
261 $(trace).css('left', v)
\r
263 trace = editor.element_tag_id($(@)) + 'div'
\r
264 v = parseInt($(@).val()).toString() + 'px'
\r
265 $(trace).css('top', v)
\r
267 trace = editor.element_tag_id($(@)) + 'img'
\r
268 w = parseInt($(@).val())
\r
269 $(trace).width(Math.abs(w))
\r
270 $(trace).parent().width(Math.abs(w))
\r
271 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
273 trace = editor.element_tag_id($(@)) + 'img'
\r
274 h = parseInt($(@).val())
\r
275 $(trace).height(Math.abs(h))
\r
276 $(trace).parent().height(Math.abs(h))
\r
277 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
279 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
283 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
285 $('.pettanr-comic-balloon' ).map ->
\r
287 stop: ( event, ui ) ->
\r
288 balloon = $('.pettanr-balloon', $(@))
\r
289 trace = editor.element_part_tag_id(balloon)
\r
290 left = $(@).position().left
\r
291 top = $(@).position().top
\r
292 $(trace + 'x').val(parseInt(left))
\r
293 $(trace + 'y').val(parseInt(top))
\r
296 $('.pettanr-balloon' ).map ->
\r
298 stop: ( event, ui ) ->
\r
300 speech_balloon_div = resize_div.parent()
\r
301 balloon = $('.pettanr-balloon', $(@))
\r
302 trace = editor.element_tag_id(speech_balloon_div)
\r
303 trace_balloon = editor.element_part_tag_id(balloon)
\r
305 resize_div.css('top', '0px')
\r
306 resize_div.css('left', '0px')
\r
309 if ui.originalPosition.top != ui.position.top
\r
310 t = speech_balloon_div.position().top + ui.position.top
\r
311 $(trace_balloon + 'y').val(Math.floor(t))
\r
312 speech_balloon_div.css('top', t.toString() + 'px')
\r
313 speech_balloon_div.css('height', h + 'px')
\r
314 if ui.originalPosition.left != ui.position.left
\r
315 l = speech_balloon_div.position().left + ui.position.left
\r
316 $(trace_balloon + 'x').val(Math.floor(l))
\r
317 speech_balloon_div.css('left', l.toString() + 'px')
\r
318 speech_balloon_div.css('width', w + 'px')
\r
319 $(trace_balloon + 'width').val(w)
\r
320 $(trace_balloon + 'height').val(h)
\r
321 speech_balloon_div.css('width', w.toString() + 'px')
\r
322 speech_balloon_div.css('height', h.toString() + 'px')
\r
323 resize: ( event, ui ) ->
\r
325 speech_balloon_div = resize_div.parent()
\r
326 balloon = $('.pettanr-balloon', $(@))
\r
327 trace = editor.element_tag_id(speech_balloon_div)
\r
328 trace_balloon = editor.element_part_tag_id(balloon)
\r
333 $('.pettanr-comic-speech-inner' ).map ->
\r
335 outer = $(@).parent()
\r
336 sb = outer.parent()
\r
337 trace = editor.element_tag_id(sb)
\r
338 img = $('.pettanr-balloon', $(trace))
\r
339 $('.ui-resizable-handle', img.parent()).map ->
\r
340 $(@).css('display', 'block')
\r
342 outer = $(@).parent()
\r
343 sb = outer.parent()
\r
344 trace = editor.element_tag_id(sb)
\r
345 img = $('.pettanr-balloon', $(trace))
\r
346 $('.ui-resizable-handle', img.parent()).map ->
\r
347 $(@).css('display', 'none')
\r
352 if editor.element_is('speech_balloon', $(@))
\r
354 switch $(@).attr('column')
\r
356 trace = editor.element_tag_id($(@))
\r
357 v = parseInt($(@).val()).toString() + 'px'
\r
358 $(trace).css('left', v)
\r
360 trace = editor.element_tag_id($(@))
\r
361 v = parseInt($(@).val()).toString() + 'px'
\r
362 $(trace).css('top', v)
\r
364 trace = editor.element_tag_id($(@))
\r
365 v = parseInt($(@).val())
\r
366 $(trace).width(Math.abs(v))
\r
367 img = $('.pettanr-balloon', $(trace))
\r
368 img.parent().width(v)
\r
371 trace = editor.element_tag_id($(@))
\r
372 v = parseInt($(@).val())
\r
373 $(trace).height(Math.abs(v))
\r
374 img = $('.pettanr-balloon', $(trace))
\r
375 img.parent().height(v)
\r
379 $('textarea').map ->
\r
380 if editor.element_is('speech_balloon', $(@))
\r
382 switch $(@).attr('column')
\r
384 trace = editor.element_part_tag_id($(@))
\r
385 wf_sel = $(trace + 'writing_format_id')
\r
386 wf_id = parseInt(wf_sel.val())
\r
387 v = WritingFormat.render(wf_id, $(@).val())
\r
389 $('textarea').map ->
\r
390 if editor.element_is('speech_balloon', $(@))
\r
391 switch $(@).attr('column')
\r
393 $(@).bind('textchange', (event, previousText) ->
\r
394 trace = editor.element_part_tag_id($(@))
\r
395 wf_sel = $(trace + 'writing_format_id')
\r
396 wf_id = parseInt(wf_sel.val())
\r
397 v = WritingFormat.render(wf_id, $(@).val())
\r
401 if editor.element_is('speech_balloon', $(@))
\r
403 switch $(@).attr('column')
\r
405 trace = editor.element_part_tag_id($(@))
\r
406 $(trace).css('font-size', $(@).val() + 'em')
\r
408 trace = editor.element_part_tag_id($(@))
\r
409 v = parseInt($(@).val())
\r
410 $(trace).css('text-align', editor.text_align_texts[v])
\r
413 if editor.element_is('speech_balloon', $(@))
\r
414 if $(@).attr('column') == 'fore_color'
\r
419 refresh_ground_picture = (element_trace) ->
\r
420 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
421 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
422 $(element_trace).css('background-position', x + ' ' + y)
\r
426 if editor.element_is('ground_picture', $(@))
\r
427 switch $(@).attr('column')
\r
430 trace = editor.element_tag_id($(@))
\r
431 refresh_ground_picture(trace)
\r
433 stop: ( event, ui ) ->
\r
434 trace = editor.element_tag_id($(@))
\r
435 refresh_ground_picture(trace)
\r
438 if editor.element_is('ground_picture', $(@))
\r
440 switch $(@).attr('column')
\r
442 trace = editor.element_tag_id($(@))
\r
443 v = parseInt($(@).val())
\r
444 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
449 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
451 refresh_ground_color = (element_trace) ->
\r
452 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
453 xy = $(element_trace + 'xy').val()
\r
454 wh = $(element_trace + 'wh').val()
\r
463 div_x = if orientation == 0
\r
467 div_y = if orientation == 0
\r
471 div_width = if orientation == 0
\r
475 div_height = if orientation == 0
\r
479 div = $(element_trace)
\r
480 div.css('left', div_x.toString() + '%')
\r
481 div.css('top', div_y.toString() + '%')
\r
482 div.css('width', div_width.toString() + '%')
\r
483 div.css('height', div_height.toString() + '%')
\r
487 if editor.element_is('ground_color', $(@))
\r
488 switch $(@).attr('column')
\r
493 stop: ( event, ui ) ->
\r
494 trace = editor.element_tag_id($(@))
\r
495 refresh_ground_color(trace)
\r
500 trace = editor.element_tag_id($(@))
\r
501 refresh_ground_color(trace)
\r
504 if editor.element_is('ground_color', $(@))
\r
505 switch $(@).attr('column')
\r
508 trace = editor.element_tag_id($(@))
\r
509 refresh_ground_color(trace)
\r
511 update_t = (ultrace) ->
\r
513 $(ultrace + ' li').map ->
\r
514 trace = editor.element_tag_id($(@))
\r
515 if $(trace + '_destroy').val().length < 1
\r
516 $(trace + 't').val(t)
\r
520 $('.tsort').map ->
\r
522 update: ( event, ui ) ->
\r
523 trace = editor.panel_tag_id($(@))
\r
524 update_t(trace + 'tsort')
\r
526 $('.t-sort li').map ->
\r
527 $(@).disableSelection()
\r
529 update_z = (ultrace) ->
\r
531 $(ultrace + ' li').map ->
\r
532 trace = editor.element_tag_id($(@))
\r
534 if $(trace + '_destroy').val().length < 1
\r
535 $(trace + 'z').val(z)
\r
536 switch $(@).attr('element_type')
\r
537 when 'panel_picture'
\r
538 trace = trace + 'div'
\r
539 $(trace).css('zIndex', z)
\r
543 $('.zsort').map ->
\r
545 update: ( event, ui ) ->
\r
546 trace = editor.panel_tag_id($(@))
\r
547 update_z(trace + 'zsort')
\r
549 $('.z-sort li').map ->
\r
550 $(@).disableSelection()
\r
553 # disable form actions
\r
554 # hide submit buttons
\r
555 $('.edit_panel_picture' ).map ->
\r
558 $('.edit_speech_balloon' ).map ->
\r
561 $('.edit_ground_picture' ).map ->
\r
564 $('.edit_ground_color' ).map ->
\r
568 $('.edit_panel' ).map ->
\r
569 if $(@).attr('jqform')
\r
571 if validate_forms()
\r
579 $('.submit' ).map ->
\r
584 if editor.is_element($(@))
\r
585 switch $(@).attr('column')
\r
588 $(@).parent().hide() #label
\r
590 # add button on new form
\r
591 $('.submit-new-form').map ->
\r
592 $(@).html('<button class="new-element">add</button>')
\r
594 $('.new-element').map ->
\r
597 j = JSON.stringify(window.configurations)
\r
598 $('#pettanr-configurations').val(j)
\r