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 lists: window.lists,
\r
15 system_resources: window.system_resources,
\r
16 magic_numbers: window.magic_numbers,
\r
17 select_items: window.select_items,
\r
19 profilers: window.profilers,
\r
20 filers: window.filers,
\r
21 elements: window.elements,
\r
22 forms: window.forms,
\r
25 j = JSON.stringify(configurations, undefined, 2)
\r
26 $('#pettanr-configurations').val(j)
\r
27 WritingFormat = window.PettanrWritingFormat
\r
28 WritingFormat.load($('#writing_formats'))
\r
29 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
30 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
31 for n, v of SpeechBalloonTemplate.scripts
\r
33 v.add_helper( n, '' )
\r
34 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
35 ColorHelper = window.PettanrColorHelper
\r
36 PopupHelper = window.PettanrPopupHelper
\r
39 #pp = new PanelPicture
\r
40 #pp.set_panel(panel)
\r
41 #confirm( PanelPicture.test() )
\r
42 #confirm( pp.test() )
\r
43 find_configurations = ( hash, key) ->
\r
44 if typeof(hash[key]) == 'string'
\r
45 find_configurations(hash, hash[key])
\r
49 set_validates = (form) ->
\r
51 $('input', form).map ->
\r
52 model_name = $(@).attr('data-model')
\r
53 column_name = $(@).attr('column')
\r
54 name = $(@).attr('name')
\r
55 if model_name and column_name
\r
56 model = find_configurations(configurations['models'], model_name)
\r
57 rule = model['attributes'][column_name]['rules']
\r
58 trace = editor.element_tag_id($(@))
\r
62 if editor.is_panel(form)
\r
63 validate_panel(form)
\r
65 validate_element(form)
\r
66 if Object.keys(rules).length > 0
\r
67 v = form.validate({ignore:[],rules: rules})
\r
69 display_panel = (panel, vis) ->
\r
74 trace = editor.panel_tag_id(panel)
\r
75 $(trace).css('display', v)
\r
77 validate_panel = (form) ->
\r
78 valid = form.valid()
\r
83 $('a', $('#tabs-1-tab')).map ->
\r
84 $(@).css('background-color', bc)
\r
85 display_panel(form, valid)
\r
88 display_element = (element, vis) ->
\r
89 trace = editor.element_tag_id(element)
\r
90 d = $(trace + '_destroy').val()
\r
91 v = if vis and d.length < 1
\r
95 switch element.attr('element_type')
\r
96 when 'panel_picture'
\r
97 trace = trace + 'div'
\r
98 $(trace).css('display', v)
\r
100 validate_element = (form) ->
\r
101 valid = form.valid()
\r
106 display_element(form, valid)
\r
107 trace = editor.element_tag_id(form)
\r
108 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
109 $(@).css('background-color', bc)
\r
112 validate_forms = () ->
\r
114 $('form', $('#tabs-1')).map ->
\r
115 form_name = $(@).attr('data-form-name')
\r
117 if validate_panel($(@))
\r
120 invalid_elements = []
\r
121 $('form', $('#tabs-2')).map ->
\r
122 form_name = $(@).attr('data-form-name')
\r
124 if validate_element($(@))
\r
127 invalid_elements.push form_name
\r
128 if invalid_elements.length > 0
\r
132 $('a', $('#tabs-2-tab')).map ->
\r
133 $(@).css('background-color', bc)
\r
136 form_name = $(@).attr('data-form-name')
\r
139 set_validates(form)
\r
140 $('.panel-editor').map ->
\r
141 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
142 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
143 if editor.is_editting()
\r
145 $('#elements-tabs').tabs()
\r
146 $('#new-element-tabs').tabs()
\r
147 $('#new-speech_balloon-tabs').tabs()
\r
148 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
149 $("#elements-tabs li").removeClass("ui-corner-top")
\r
150 $("#elements-tabs li").addClass("ui-corner-left")
\r
151 $("#elements-tabs li").map ->
\r
153 switch $(@).attr('element_type')
\r
154 when 'speech_balloon'
\r
155 trace = editor.element_tag_id($(@))
\r
156 t = $('img', $(trace))
\r
157 when 'panel_picture'
\r
158 trace = editor.element_tag_id($(@)) + 'img'
\r
163 $('.ui-resizable-handle', t.parent()).map ->
\r
164 $(@).css('display', 'block')
\r
166 switch $(@).attr('element_type')
\r
167 when 'speech_balloon'
\r
168 trace = editor.element_tag_id($(@))
\r
169 t = $('img', $(trace))
\r
170 when 'panel_picture'
\r
171 trace = editor.element_tag_id($(@)) + 'img'
\r
176 $('.ui-resizable-handle', t.parent()).map ->
\r
177 $(@).css('display', 'none')
\r
180 $('.ui-icon-destroy').map ->
\r
183 primary: 'ui-icon-close',
\r
189 if confirm('destroy ?')
\r
190 trace = editor.element_tag_id($(@))
\r
191 $(trace + '_destroy').val('true')
\r
192 panel_trace = editor.panel_tag_id($(@))
\r
193 update_t(panel_trace + 'tsort')
\r
194 update_z(panel_trace + 'zsort')
\r
196 $(trace + 'element_tab').css('display', 'none')
\r
197 $(trace + 'tab_panel').css('display', 'none')
\r
198 $(trace + 'zsort').css('display', 'none')
\r
199 $(trace + 'tsort').css('display', 'none')
\r
200 display_element($(@), false)
\r
202 $('#pettanr-panel-submit').focusin ->
\r
203 editor.refresh_attribute($('#pettanr-panel-json'))
\r
206 $('.pettanr-comic-panel').map ->
\r
207 if editor.is_editable($(@))
\r
209 stop: ( event, ui ) ->
\r
210 trace = editor.panel_tag_id($(@))
\r
211 w = parseInt($(@).width())
\r
212 h = parseInt($(@).height())
\r
213 $(trace + 'width').val(w)
\r
214 $(trace + 'height').val(h)
\r
215 $('.pettanr-comic-ground-picture').map ->
\r
218 $('.pettanr-comic-ground-color').map ->
\r
226 if $(@).attr('element_type')
\r
228 if $(@).attr('panel_id')
\r
230 switch $(@).attr('column')
\r
232 trace = editor.panel_tag_id($(@))
\r
233 $(trace).width(parseInt( $(@).val()))
\r
235 trace = editor.panel_tag_id($(@))
\r
236 $(trace).height(parseInt( $(@).val()))
\r
238 trace = editor.panel_tag_id($(@))
\r
239 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
242 PictureSizeHelper.add_helper()
\r
243 PopupHelper.add_helper()
\r
245 $('.pettanr-panel-picture-wrapper').map ->
\r
247 stop: ( event, ui ) ->
\r
248 trace = editor.element_tag_id($(@))
\r
249 img = $(trace + 'img')
\r
250 left = img.parent().position().left + $(@).position().left
\r
251 top = img.parent().position().top + $(@).position().top
\r
252 $(trace + 'x').val(parseInt(left))
\r
253 $(trace + 'y').val(parseInt(top))
\r
256 $('.panel-picture').map ->
\r
258 stop: ( event, ui ) ->
\r
260 panel_picture_div = resize_div.parent()
\r
261 trace = editor.element_tag_id(panel_picture_div)
\r
263 resize_div.css('top', '0px')
\r
264 resize_div.css('left', '0px')
\r
265 if ui.originalPosition.top != ui.position.top
\r
266 t = panel_picture_div.position().top + ui.position.top
\r
267 $(trace + 'y').val(Math.floor(t))
\r
268 panel_picture_div.css('top', t.toString() + 'px')
\r
269 if ui.originalPosition.left != ui.position.left
\r
270 l = panel_picture_div.position().left + ui.position.left
\r
271 $(trace + 'x').val(Math.floor(l))
\r
272 panel_picture_div.css('left', l.toString() + 'px')
\r
273 w = if $(trace + 'width').val() < 0
\r
277 h = if $(trace + 'height').val() < 0
\r
281 $(trace + 'width').val(w)
\r
282 $(trace + 'height').val(h)
\r
283 resize: ( event, ui ) ->
\r
285 panel_picture_div = resize_div.parent()
\r
286 trace = editor.element_tag_id(panel_picture_div)
\r
293 if editor.element_is('panel_picture', $(@))
\r
295 switch $(@).attr('column')
\r
297 trace = editor.element_tag_id($(@)) + 'div'
\r
298 v = parseInt($(@).val()).toString() + 'px'
\r
299 $(trace).css('left', v)
\r
301 trace = editor.element_tag_id($(@)) + 'div'
\r
302 v = parseInt($(@).val()).toString() + 'px'
\r
303 $(trace).css('top', v)
\r
305 trace = editor.element_tag_id($(@)) + 'img'
\r
306 w = parseInt($(@).val())
\r
307 $(trace).width(Math.abs(w))
\r
308 $(trace).parent().width(Math.abs(w))
\r
309 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
311 trace = editor.element_tag_id($(@)) + 'img'
\r
312 h = parseInt($(@).val())
\r
313 $(trace).height(Math.abs(h))
\r
314 $(trace).parent().height(Math.abs(h))
\r
315 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
317 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
321 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
323 $('.pettanr-comic-balloon' ).map ->
\r
325 stop: ( event, ui ) ->
\r
326 balloon = $('.pettanr-balloon', $(@))
\r
327 trace = editor.element_part_tag_id(balloon)
\r
328 left = $(@).position().left
\r
329 top = $(@).position().top
\r
330 $(trace + 'x').val(parseInt(left))
\r
331 $(trace + 'y').val(parseInt(top))
\r
334 $('.pettanr-balloon' ).map ->
\r
336 stop: ( event, ui ) ->
\r
338 speech_balloon_div = resize_div.parent()
\r
339 balloon = $('.pettanr-balloon', $(@))
\r
340 trace = editor.element_tag_id(speech_balloon_div)
\r
341 trace_balloon = editor.element_part_tag_id(balloon)
\r
343 resize_div.css('top', '0px')
\r
344 resize_div.css('left', '0px')
\r
347 if ui.originalPosition.top != ui.position.top
\r
348 t = speech_balloon_div.position().top + ui.position.top
\r
349 $(trace_balloon + 'y').val(Math.floor(t))
\r
350 speech_balloon_div.css('top', t.toString() + 'px')
\r
351 speech_balloon_div.css('height', h + 'px')
\r
352 if ui.originalPosition.left != ui.position.left
\r
353 l = speech_balloon_div.position().left + ui.position.left
\r
354 $(trace_balloon + 'x').val(Math.floor(l))
\r
355 speech_balloon_div.css('left', l.toString() + 'px')
\r
356 speech_balloon_div.css('width', w + 'px')
\r
357 $(trace_balloon + 'width').val(w)
\r
358 $(trace_balloon + 'height').val(h)
\r
359 speech_balloon_div.css('width', w.toString() + 'px')
\r
360 speech_balloon_div.css('height', h.toString() + 'px')
\r
361 resize: ( event, ui ) ->
\r
363 speech_balloon_div = resize_div.parent()
\r
364 balloon = $('.pettanr-balloon', $(@))
\r
365 trace = editor.element_tag_id(speech_balloon_div)
\r
366 trace_balloon = editor.element_part_tag_id(balloon)
\r
371 $('.pettanr-comic-speech-inner' ).map ->
\r
373 outer = $(@).parent()
\r
374 sb = outer.parent()
\r
375 trace = editor.element_tag_id(sb)
\r
376 img = $('.pettanr-balloon', $(trace))
\r
377 $('.ui-resizable-handle', img.parent()).map ->
\r
378 $(@).css('display', 'block')
\r
380 outer = $(@).parent()
\r
381 sb = outer.parent()
\r
382 trace = editor.element_tag_id(sb)
\r
383 img = $('.pettanr-balloon', $(trace))
\r
384 $('.ui-resizable-handle', img.parent()).map ->
\r
385 $(@).css('display', 'none')
\r
390 if editor.element_is('speech_balloon', $(@))
\r
392 switch $(@).attr('column')
\r
394 trace = editor.element_tag_id($(@))
\r
395 v = parseInt($(@).val()).toString() + 'px'
\r
396 $(trace).css('left', v)
\r
398 trace = editor.element_tag_id($(@))
\r
399 v = parseInt($(@).val()).toString() + 'px'
\r
400 $(trace).css('top', v)
\r
402 trace = editor.element_tag_id($(@))
\r
403 v = parseInt($(@).val())
\r
404 $(trace).width(Math.abs(v))
\r
405 img = $('.pettanr-balloon', $(trace))
\r
406 img.parent().width(v)
\r
409 trace = editor.element_tag_id($(@))
\r
410 v = parseInt($(@).val())
\r
411 $(trace).height(Math.abs(v))
\r
412 img = $('.pettanr-balloon', $(trace))
\r
413 img.parent().height(v)
\r
417 $('textarea').map ->
\r
418 if editor.element_is('speech_balloon', $(@))
\r
420 switch $(@).attr('column')
\r
422 trace = editor.element_part_tag_id($(@))
\r
423 wf_sel = $(trace + 'writing_format_id')
\r
424 wf_id = parseInt(wf_sel.val())
\r
425 v = WritingFormat.render(wf_id, $(@).val())
\r
427 $('textarea').map ->
\r
428 if editor.element_is('speech_balloon', $(@))
\r
429 switch $(@).attr('column')
\r
431 $(@).bind('textchange', (event, previousText) ->
\r
432 trace = editor.element_part_tag_id($(@))
\r
433 wf_sel = $(trace + 'writing_format_id')
\r
434 wf_id = parseInt(wf_sel.val())
\r
435 v = WritingFormat.render(wf_id, $(@).val())
\r
439 if editor.element_is('speech_balloon', $(@))
\r
441 switch $(@).attr('column')
\r
443 trace = editor.element_part_tag_id($(@))
\r
444 $(trace).css('font-size', $(@).val() + 'em')
\r
446 trace = editor.element_part_tag_id($(@))
\r
447 v = parseInt($(@).val())
\r
448 $(trace).css('text-align', editor.text_align_texts[v])
\r
451 if editor.element_is('speech_balloon', $(@))
\r
452 if $(@).attr('column') == 'fore_color'
\r
457 refresh_ground_picture = (element_trace) ->
\r
458 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
459 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
460 $(element_trace).css('background-position', x + ' ' + y)
\r
464 if editor.element_is('ground_picture', $(@))
\r
465 switch $(@).attr('column')
\r
468 trace = editor.element_tag_id($(@))
\r
469 refresh_ground_picture(trace)
\r
471 stop: ( event, ui ) ->
\r
472 trace = editor.element_tag_id($(@))
\r
473 refresh_ground_picture(trace)
\r
476 if editor.element_is('ground_picture', $(@))
\r
478 switch $(@).attr('column')
\r
480 trace = editor.element_tag_id($(@))
\r
481 v = parseInt($(@).val())
\r
482 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
487 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
489 refresh_ground_color = (element_trace) ->
\r
490 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
491 xy = $(element_trace + 'xy').val()
\r
492 wh = $(element_trace + 'wh').val()
\r
501 div_x = if orientation == 0
\r
505 div_y = if orientation == 0
\r
509 div_width = if orientation == 0
\r
513 div_height = if orientation == 0
\r
517 div = $(element_trace)
\r
518 div.css('left', div_x.toString() + '%')
\r
519 div.css('top', div_y.toString() + '%')
\r
520 div.css('width', div_width.toString() + '%')
\r
521 div.css('height', div_height.toString() + '%')
\r
525 if editor.element_is('ground_color', $(@))
\r
526 switch $(@).attr('column')
\r
531 stop: ( event, ui ) ->
\r
532 trace = editor.element_tag_id($(@))
\r
533 refresh_ground_color(trace)
\r
538 trace = editor.element_tag_id($(@))
\r
539 refresh_ground_color(trace)
\r
542 if editor.element_is('ground_color', $(@))
\r
543 switch $(@).attr('column')
\r
546 trace = editor.element_tag_id($(@))
\r
547 refresh_ground_color(trace)
\r
549 update_t = (ultrace) ->
\r
551 $(ultrace + ' li').map ->
\r
552 trace = editor.element_tag_id($(@))
\r
553 if $(trace + '_destroy').val().length < 1
\r
554 $(trace + 't').val(t)
\r
558 $('.tsort').map ->
\r
560 update: ( event, ui ) ->
\r
561 trace = editor.panel_tag_id($(@))
\r
562 update_t(trace + 'tsort')
\r
564 $('.t-sort li').map ->
\r
565 $(@).disableSelection()
\r
567 update_z = (ultrace) ->
\r
569 $(ultrace + ' li').map ->
\r
570 trace = editor.element_tag_id($(@))
\r
572 if $(trace + '_destroy').val().length < 1
\r
573 $(trace + 'z').val(z)
\r
574 switch $(@).attr('element_type')
\r
575 when 'panel_picture'
\r
576 trace = trace + 'div'
\r
577 $(trace).css('zIndex', z)
\r
581 $('.zsort').map ->
\r
583 update: ( event, ui ) ->
\r
584 trace = editor.panel_tag_id($(@))
\r
585 update_z(trace + 'zsort')
\r
587 $('.z-sort li').map ->
\r
588 $(@).disableSelection()
\r
591 # disable form actions
\r
592 # hide submit buttons
\r
593 $('.edit_panel_picture' ).map ->
\r
596 $('.edit_speech_balloon' ).map ->
\r
599 $('.edit_ground_picture' ).map ->
\r
602 $('.edit_ground_color' ).map ->
\r
606 $('.edit_panel' ).map ->
\r
607 if $(@).attr('jqform')
\r
609 if validate_forms()
\r
617 $('.submit' ).map ->
\r
622 if editor.is_element($(@))
\r
623 switch $(@).attr('column')
\r
626 $(@).parent().hide() #label
\r
628 # add button on new form
\r
629 $('.submit-new-form').map ->
\r
630 $(@).html('<button class="new-element">add</button>')
\r
632 $('.new-element').map ->
\r