2 _.templateSettings = {
\r
3 interpolate: /\<\&\=(.+?)\&\>/g,
\r
4 evaluate: /\<\&(.+?)\&\>/g
\r
6 #filer = new Filer('tt', ['ea','eb','ec'])
\r
7 #view = new FilerView( { filer: filer } )
\r
8 confirm_confirm_confirm = () ->
\r
10 editor = window.PettanrEditor
\r
12 controllers: window.controllers,
\r
13 models: window.models,
\r
14 system_resources: window.system_resources,
\r
15 magic_numbers: window.magic_numbers,
\r
17 profilers: window.profilers,
\r
18 filers: window.filers,
\r
19 list_groups: window.list_groups,
\r
20 forms: window.forms,
\r
23 j = JSON.stringify(configurations, undefined, 2)
\r
24 $('#pettanr-configurations').val(j)
\r
25 WritingFormat = window.PettanrWritingFormat
\r
26 WritingFormat.load($('#writing_formats'))
\r
27 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
28 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
29 for n, v of SpeechBalloonTemplate.scripts
\r
31 v.add_helper( n, '' )
\r
32 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
33 ColorHelper = window.PettanrColorHelper
\r
34 PopupHelper = window.PettanrPopupHelper
\r
37 #pp = new PanelPicture
\r
38 #pp.set_panel(panel)
\r
39 #confirm( PanelPicture.test() )
\r
40 #confirm( pp.test() )
\r
41 find_configurations = ( hash, key) ->
\r
42 if typeof(hash[key]) == 'string'
\r
43 find_configurations(hash, hash[key])
\r
47 set_validates = (form) ->
\r
49 $('input', form).map ->
\r
50 model_name = $(@).attr('data-model')
\r
51 column_name = $(@).attr('column')
\r
52 name = $(@).attr('name')
\r
53 if model_name and column_name
\r
54 model = find_configurations(configurations['models'], model_name)
\r
55 rule = model['attributes'][column_name]['rules']
\r
56 trace = editor.element_tag_id($(@))
\r
60 if editor.is_panel(form)
\r
61 validate_panel(form)
\r
63 validate_element(form)
\r
64 if Object.keys(rules).length > 0
\r
65 v = form.validate({ignore:[],rules: rules})
\r
67 display_panel = (panel, vis) ->
\r
72 trace = editor.panel_tag_id(panel)
\r
73 $(trace).css('display', v)
\r
75 validate_panel = (form) ->
\r
76 valid = form.valid()
\r
81 $('a', $('#tabs-1-tab')).map ->
\r
82 $(@).css('background-color', bc)
\r
83 display_panel(form, valid)
\r
86 display_element = (element, vis) ->
\r
87 trace = editor.element_tag_id(element)
\r
88 d = $(trace + '_destroy').val()
\r
89 v = if vis and d.length < 1
\r
93 switch element.attr('element_type')
\r
94 when 'panel_picture'
\r
95 trace = trace + 'div'
\r
96 $(trace).css('display', v)
\r
98 validate_element = (form) ->
\r
99 valid = form.valid()
\r
104 display_element(form, valid)
\r
105 trace = editor.element_tag_id(form)
\r
106 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
107 $(@).css('background-color', bc)
\r
110 validate_forms = () ->
\r
112 $('form', $('#tabs-1')).map ->
\r
113 form_name = $(@).attr('data-form-name')
\r
115 if validate_panel($(@))
\r
118 invalid_elements = []
\r
119 $('form', $('#tabs-2')).map ->
\r
120 form_name = $(@).attr('data-form-name')
\r
122 if validate_element($(@))
\r
125 invalid_elements.push form_name
\r
126 if invalid_elements.length > 0
\r
130 $('a', $('#tabs-2-tab')).map ->
\r
131 $(@).css('background-color', bc)
\r
134 form_name = $(@).attr('data-form-name')
\r
137 set_validates(form)
\r
138 $('.panel-editor').map ->
\r
139 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
140 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
141 if editor.is_editting()
\r
143 $('#elements-tabs').tabs()
\r
144 $('#new-element-tabs').tabs()
\r
145 $('#new-speech_balloon-tabs').tabs()
\r
146 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
147 $("#elements-tabs li").removeClass("ui-corner-top")
\r
148 $("#elements-tabs li").addClass("ui-corner-left")
\r
149 $("#elements-tabs li").map ->
\r
151 switch $(@).attr('element_type')
\r
152 when 'speech_balloon'
\r
153 trace = editor.element_tag_id($(@))
\r
154 t = $('img', $(trace))
\r
155 when 'panel_picture'
\r
156 trace = editor.element_tag_id($(@)) + 'img'
\r
161 $('.ui-resizable-handle', t.parent()).map ->
\r
162 $(@).css('display', 'block')
\r
164 switch $(@).attr('element_type')
\r
165 when 'speech_balloon'
\r
166 trace = editor.element_tag_id($(@))
\r
167 t = $('img', $(trace))
\r
168 when 'panel_picture'
\r
169 trace = editor.element_tag_id($(@)) + 'img'
\r
174 $('.ui-resizable-handle', t.parent()).map ->
\r
175 $(@).css('display', 'none')
\r
178 $('.ui-icon-destroy').map ->
\r
181 primary: 'ui-icon-close',
\r
187 if confirm('destroy ?')
\r
188 trace = editor.element_tag_id($(@))
\r
189 $(trace + '_destroy').val('true')
\r
190 panel_trace = editor.panel_tag_id($(@))
\r
191 update_t(panel_trace + 'tsort')
\r
192 update_z(panel_trace + 'zsort')
\r
194 $(trace + 'element_tab').css('display', 'none')
\r
195 $(trace + 'tab_panel').css('display', 'none')
\r
196 $(trace + 'zsort').css('display', 'none')
\r
197 $(trace + 'tsort').css('display', 'none')
\r
198 display_element($(@), false)
\r
200 $('#pettanr-panel-submit').focusin ->
\r
201 editor.refresh_attribute($('#pettanr-panel-json'))
\r
204 $('.pettanr-comic-panel').map ->
\r
205 if editor.is_editable($(@))
\r
207 stop: ( event, ui ) ->
\r
208 trace = editor.panel_tag_id($(@))
\r
209 w = parseInt($(@).width())
\r
210 h = parseInt($(@).height())
\r
211 $(trace + 'width').val(w)
\r
212 $(trace + 'height').val(h)
\r
213 $('.pettanr-comic-ground-picture').map ->
\r
216 $('.pettanr-comic-ground-color').map ->
\r
224 if $(@).attr('element_type')
\r
226 if $(@).attr('panel_id')
\r
228 switch $(@).attr('column')
\r
230 trace = editor.panel_tag_id($(@))
\r
231 $(trace).width(parseInt( $(@).val()))
\r
233 trace = editor.panel_tag_id($(@))
\r
234 $(trace).height(parseInt( $(@).val()))
\r
236 trace = editor.panel_tag_id($(@))
\r
237 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
240 PictureSizeHelper.add_helper()
\r
241 PopupHelper.add_helper()
\r
243 $('.pettanr-panel-picture-wrapper').map ->
\r
245 stop: ( event, ui ) ->
\r
246 trace = editor.element_tag_id($(@))
\r
247 img = $(trace + 'img')
\r
248 left = img.parent().position().left + $(@).position().left
\r
249 top = img.parent().position().top + $(@).position().top
\r
250 $(trace + 'x').val(parseInt(left))
\r
251 $(trace + 'y').val(parseInt(top))
\r
254 $('.panel-picture').map ->
\r
256 stop: ( event, ui ) ->
\r
258 panel_picture_div = resize_div.parent()
\r
259 trace = editor.element_tag_id(panel_picture_div)
\r
261 resize_div.css('top', '0px')
\r
262 resize_div.css('left', '0px')
\r
263 if ui.originalPosition.top != ui.position.top
\r
264 t = panel_picture_div.position().top + ui.position.top
\r
265 $(trace + 'y').val(Math.floor(t))
\r
266 panel_picture_div.css('top', t.toString() + 'px')
\r
267 if ui.originalPosition.left != ui.position.left
\r
268 l = panel_picture_div.position().left + ui.position.left
\r
269 $(trace + 'x').val(Math.floor(l))
\r
270 panel_picture_div.css('left', l.toString() + 'px')
\r
271 w = if $(trace + 'width').val() < 0
\r
275 h = if $(trace + 'height').val() < 0
\r
279 $(trace + 'width').val(w)
\r
280 $(trace + 'height').val(h)
\r
281 resize: ( event, ui ) ->
\r
283 panel_picture_div = resize_div.parent()
\r
284 trace = editor.element_tag_id(panel_picture_div)
\r
291 if editor.element_is('panel_picture', $(@))
\r
293 switch $(@).attr('column')
\r
295 trace = editor.element_tag_id($(@)) + 'div'
\r
296 v = parseInt($(@).val()).toString() + 'px'
\r
297 $(trace).css('left', v)
\r
299 trace = editor.element_tag_id($(@)) + 'div'
\r
300 v = parseInt($(@).val()).toString() + 'px'
\r
301 $(trace).css('top', v)
\r
303 trace = editor.element_tag_id($(@)) + 'img'
\r
304 w = parseInt($(@).val())
\r
305 $(trace).width(Math.abs(w))
\r
306 $(trace).parent().width(Math.abs(w))
\r
307 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
309 trace = editor.element_tag_id($(@)) + 'img'
\r
310 h = parseInt($(@).val())
\r
311 $(trace).height(Math.abs(h))
\r
312 $(trace).parent().height(Math.abs(h))
\r
313 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
315 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
319 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
321 $('.pettanr-comic-balloon' ).map ->
\r
323 stop: ( event, ui ) ->
\r
324 balloon = $('.pettanr-balloon', $(@))
\r
325 trace = editor.element_part_tag_id(balloon)
\r
326 left = $(@).position().left
\r
327 top = $(@).position().top
\r
328 $(trace + 'x').val(parseInt(left))
\r
329 $(trace + 'y').val(parseInt(top))
\r
332 $('.pettanr-balloon' ).map ->
\r
334 stop: ( event, ui ) ->
\r
336 speech_balloon_div = resize_div.parent()
\r
337 balloon = $('.pettanr-balloon', $(@))
\r
338 trace = editor.element_tag_id(speech_balloon_div)
\r
339 trace_balloon = editor.element_part_tag_id(balloon)
\r
341 resize_div.css('top', '0px')
\r
342 resize_div.css('left', '0px')
\r
345 if ui.originalPosition.top != ui.position.top
\r
346 t = speech_balloon_div.position().top + ui.position.top
\r
347 $(trace_balloon + 'y').val(Math.floor(t))
\r
348 speech_balloon_div.css('top', t.toString() + 'px')
\r
349 speech_balloon_div.css('height', h + 'px')
\r
350 if ui.originalPosition.left != ui.position.left
\r
351 l = speech_balloon_div.position().left + ui.position.left
\r
352 $(trace_balloon + 'x').val(Math.floor(l))
\r
353 speech_balloon_div.css('left', l.toString() + 'px')
\r
354 speech_balloon_div.css('width', w + 'px')
\r
355 $(trace_balloon + 'width').val(w)
\r
356 $(trace_balloon + 'height').val(h)
\r
357 speech_balloon_div.css('width', w.toString() + 'px')
\r
358 speech_balloon_div.css('height', h.toString() + 'px')
\r
359 resize: ( event, ui ) ->
\r
361 speech_balloon_div = resize_div.parent()
\r
362 balloon = $('.pettanr-balloon', $(@))
\r
363 trace = editor.element_tag_id(speech_balloon_div)
\r
364 trace_balloon = editor.element_part_tag_id(balloon)
\r
369 $('.pettanr-comic-speech-inner' ).map ->
\r
371 outer = $(@).parent()
\r
372 sb = outer.parent()
\r
373 trace = editor.element_tag_id(sb)
\r
374 img = $('.pettanr-balloon', $(trace))
\r
375 $('.ui-resizable-handle', img.parent()).map ->
\r
376 $(@).css('display', 'block')
\r
378 outer = $(@).parent()
\r
379 sb = outer.parent()
\r
380 trace = editor.element_tag_id(sb)
\r
381 img = $('.pettanr-balloon', $(trace))
\r
382 $('.ui-resizable-handle', img.parent()).map ->
\r
383 $(@).css('display', 'none')
\r
388 if editor.element_is('speech_balloon', $(@))
\r
390 switch $(@).attr('column')
\r
392 trace = editor.element_tag_id($(@))
\r
393 v = parseInt($(@).val()).toString() + 'px'
\r
394 $(trace).css('left', v)
\r
396 trace = editor.element_tag_id($(@))
\r
397 v = parseInt($(@).val()).toString() + 'px'
\r
398 $(trace).css('top', v)
\r
400 trace = editor.element_tag_id($(@))
\r
401 v = parseInt($(@).val())
\r
402 $(trace).width(Math.abs(v))
\r
403 img = $('.pettanr-balloon', $(trace))
\r
404 img.parent().width(v)
\r
407 trace = editor.element_tag_id($(@))
\r
408 v = parseInt($(@).val())
\r
409 $(trace).height(Math.abs(v))
\r
410 img = $('.pettanr-balloon', $(trace))
\r
411 img.parent().height(v)
\r
415 $('textarea').map ->
\r
416 if editor.element_is('speech_balloon', $(@))
\r
418 switch $(@).attr('column')
\r
420 trace = editor.element_part_tag_id($(@))
\r
421 wf_sel = $(trace + 'writing_format_id')
\r
422 wf_id = parseInt(wf_sel.val())
\r
423 v = WritingFormat.render(wf_id, $(@).val())
\r
425 $('textarea').map ->
\r
426 if editor.element_is('speech_balloon', $(@))
\r
427 switch $(@).attr('column')
\r
429 $(@).bind('textchange', (event, previousText) ->
\r
430 trace = editor.element_part_tag_id($(@))
\r
431 wf_sel = $(trace + 'writing_format_id')
\r
432 wf_id = parseInt(wf_sel.val())
\r
433 v = WritingFormat.render(wf_id, $(@).val())
\r
437 if editor.element_is('speech_balloon', $(@))
\r
439 switch $(@).attr('column')
\r
441 trace = editor.element_part_tag_id($(@))
\r
442 $(trace).css('font-size', $(@).val() + 'em')
\r
444 trace = editor.element_part_tag_id($(@))
\r
445 v = parseInt($(@).val())
\r
446 $(trace).css('text-align', editor.text_align_texts[v])
\r
449 if editor.element_is('speech_balloon', $(@))
\r
450 if $(@).attr('column') == 'fore_color'
\r
455 refresh_ground_picture = (element_trace) ->
\r
456 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
457 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
458 $(element_trace).css('background-position', x + ' ' + y)
\r
462 if editor.element_is('ground_picture', $(@))
\r
463 switch $(@).attr('column')
\r
466 trace = editor.element_tag_id($(@))
\r
467 refresh_ground_picture(trace)
\r
469 stop: ( event, ui ) ->
\r
470 trace = editor.element_tag_id($(@))
\r
471 refresh_ground_picture(trace)
\r
474 if editor.element_is('ground_picture', $(@))
\r
476 switch $(@).attr('column')
\r
478 trace = editor.element_tag_id($(@))
\r
479 v = parseInt($(@).val())
\r
480 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
485 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
487 refresh_ground_color = (element_trace) ->
\r
488 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
489 xy = $(element_trace + 'xy').val()
\r
490 wh = $(element_trace + 'wh').val()
\r
499 div_x = if orientation == 0
\r
503 div_y = if orientation == 0
\r
507 div_width = if orientation == 0
\r
511 div_height = if orientation == 0
\r
515 div = $(element_trace)
\r
516 div.css('left', div_x.toString() + '%')
\r
517 div.css('top', div_y.toString() + '%')
\r
518 div.css('width', div_width.toString() + '%')
\r
519 div.css('height', div_height.toString() + '%')
\r
523 if editor.element_is('ground_color', $(@))
\r
524 switch $(@).attr('column')
\r
529 stop: ( event, ui ) ->
\r
530 trace = editor.element_tag_id($(@))
\r
531 refresh_ground_color(trace)
\r
536 trace = editor.element_tag_id($(@))
\r
537 refresh_ground_color(trace)
\r
540 if editor.element_is('ground_color', $(@))
\r
541 switch $(@).attr('column')
\r
544 trace = editor.element_tag_id($(@))
\r
545 refresh_ground_color(trace)
\r
547 update_t = (ultrace) ->
\r
549 $(ultrace + ' li').map ->
\r
550 trace = editor.element_tag_id($(@))
\r
551 if $(trace + '_destroy').val().length < 1
\r
552 $(trace + 't').val(t)
\r
556 $('.tsort').map ->
\r
558 update: ( event, ui ) ->
\r
559 trace = editor.panel_tag_id($(@))
\r
560 update_t(trace + 'tsort')
\r
562 $('.t-sort li').map ->
\r
563 $(@).disableSelection()
\r
565 update_z = (ultrace) ->
\r
567 $(ultrace + ' li').map ->
\r
568 trace = editor.element_tag_id($(@))
\r
570 if $(trace + '_destroy').val().length < 1
\r
571 $(trace + 'z').val(z)
\r
572 switch $(@).attr('element_type')
\r
573 when 'panel_picture'
\r
574 trace = trace + 'div'
\r
575 $(trace).css('zIndex', z)
\r
579 $('.zsort').map ->
\r
581 update: ( event, ui ) ->
\r
582 trace = editor.panel_tag_id($(@))
\r
583 update_z(trace + 'zsort')
\r
585 $('.z-sort li').map ->
\r
586 $(@).disableSelection()
\r
589 # disable form actions
\r
590 # hide submit buttons
\r
591 $('.edit_panel_picture' ).map ->
\r
594 $('.edit_speech_balloon' ).map ->
\r
597 $('.edit_ground_picture' ).map ->
\r
600 $('.edit_ground_color' ).map ->
\r
604 $('.edit_panel' ).map ->
\r
605 if $(@).attr('jqform')
\r
607 if validate_forms()
\r
615 $('.submit' ).map ->
\r
620 if editor.is_element($(@))
\r
621 switch $(@).attr('column')
\r
624 $(@).parent().hide() #label
\r
626 # add button on new form
\r
627 $('.submit-new-form').map ->
\r
628 $(@).html('<button class="new-element">add</button>')
\r
630 $('.new-element').map ->
\r