--- /dev/null
+$ ->
+ confirm_confirm_confirm = () ->
+ confirm( )
+ editor = window.PettanrSheeter
+
+ $('.sheet-editor').map ->
+ if $(@).attr('current') and parseInt($(@).attr('current')) > 0
+ editor.pettanr_current_sheet_id = parseInt($(@).attr('sheet_id'))
+ if editor.is_editting()
+ $('#tabs').tabs()
+ $('#elements-tabs').tabs()
+ $('#new-element-tabs').tabs()
+ $('#new-speech_balloon-tabs').tabs()
+ $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
+ $("#elements-tabs li").removeClass("ui-corner-top")
+ $("#elements-tabs li").addClass("ui-corner-left")
+ $("#elements-tabs li").map ->
+ $(@).mouseover ->
+ switch $(@).attr('element_type')
+ when 'sheet_panel'
+ trace = editor.element_tag_id($(@))
+ t = $('.pettanr-comic-panel', $(trace))
+ else
+ t = null
+ if t
+ $('.ui-resizable-handle', t.parent()).map ->
+ $(@).css('display', 'block')
+ $(@).mouseout ->
+ switch $(@).attr('element_type')
+ when 'sheet_panel'
+ trace = editor.element_tag_id($(@))
+ t = $('.pettanr-comic-panel', $(trace))
+ else
+ t = null
+ if t
+ $('.ui-resizable-handle', t.parent()).map ->
+ $(@).css('display', 'none')
+
+ #destroy button
+ $('.ui-icon-destroy').map ->
+ $(@).button {
+ icons: {
+ primary: 'ui-icon-close',
+ secondary: null
+ },
+ text: false
+ }
+ $(@).click ->
+ if confirm('destroy ?')
+ trace = editor.element_tag_id($(@))
+ $(trace + '_destroy').val('true')
+ sheet_trace = editor.sheet_tag_id($(@))
+ update_t(sheet_trace + 'tsort')
+ update_z(sheet_trace + 'zsort')
+ # sync
+ $(trace + 'element_tab').css('display', 'none')
+ $(trace + 'tab_sheet').css('display', 'none')
+ $(trace + 'zsort').css('display', 'none')
+ $(trace + 'tsort').css('display', 'none')
+ $(trace).css('display', 'none')
+
+
+ $('#pettanr-sheet-submit').focusin ->
+ editor.refresh_attribute($('#pettanr-sheet-json'))
+
+ # sheet
+ $('.sheet').map ->
+ if editor.is_editable($(@))
+ $(@).resizable {
+ stop: ( event, ui ) ->
+ trace = editor.sheet_tag_id($(@))
+ w = parseInt($(@).width())
+ h = parseInt($(@).height())
+ $(trace + 'width').val(w)
+ $(trace + 'height').val(h)
+ , autoHide: true
+ }
+
+ # sync view
+ $('input').map ->
+ if $(@).attr('element_type')
+ else
+ if $(@).attr('sheet_id')
+ $(@).focusout ->
+ switch $(@).attr('column')
+ when 'width'
+ trace = editor.sheet_tag_id($(@))
+ $(trace).width(parseInt( $(@).val()))
+ when 'height'
+ trace = editor.sheet_tag_id($(@))
+ $(trace).height(parseInt( $(@).val()))
+
+ $('.sheet_panel').map ->
+ $(@).draggable {
+ stop: ( event, ui ) ->
+ trace = editor.element_tag_id($(@))
+ left = $(@).position().left
+ top = $(@).position().top
+ $(trace + 'x').val(parseInt(left))
+ $(trace + 'y').val(parseInt(top))
+ , cursor: "crosshair"
+ }
+
+ # sync view
+ $('input').map ->
+ if editor.element_is('sheet_panel', $(@))
+ $(@).focusout ->
+ switch $(@).attr('column')
+ when 'x'
+ trace = editor.element_tag_id($(@))
+ v = parseInt($(@).val()).toString() + 'px'
+ $(trace).css('left', v)
+ when 'y'
+ trace = editor.element_tag_id($(@))
+ v = parseInt($(@).val()).toString() + 'px'
+ $(trace).css('top', v)
+ else
+ else
+
+ update_t = (ultrace) ->
+ t = 0
+ $(ultrace + ' li').map ->
+ trace = editor.element_tag_id($(@))
+ if $(trace + '_destroy').val().length < 1
+ $(trace + 't').val(t)
+ t++
+ else
+
+ $('.tsort').map ->
+ $(@).sortable {
+ update: ( event, ui ) ->
+ trace = editor.sheet_tag_id($(@))
+ update_t(trace + 'tsort')
+ }
+ $('.t-sort li').map ->
+ $(@).disableSelection()
+
+ update_z = (ultrace) ->
+ z = 1
+ $(ultrace + ' li').map ->
+ trace = editor.element_tag_id($(@))
+ # update panel
+ if $(trace + '_destroy').val().length < 1
+ $(trace + 'z').val(z)
+ switch $(@).attr('element_type')
+ when 'panel_picture'
+ trace = trace + 'div'
+ $(trace).css('zIndex', z)
+ z++
+ else
+
+ $('.zsort').map ->
+ $(@).sortable {
+ update: ( event, ui ) ->
+ trace = editor.sheet_tag_id($(@))
+ update_z(trace + 'zsort')
+ }
+ $('.z-sort li').map ->
+ $(@).disableSelection()
+
+ # all
+ # disable form actions
+
+ $('.edit_sheet' ).map ->
+ if $(@).attr('jqform')
+ else
+ $(@).submit ->
+ false
+
+ $('.submit' ).map ->
+ $(@).hide()
+
+ # disable form z t
+ $('input').map ->
+ if editor.is_element($(@))
+ switch $(@).attr('column')
+ when 'z' , 't'
+ $(@).hide()
+ $(@).parent().hide() #label
+
+ # add button on new form
+ $('.submit-new-form').map ->
+ $(@).html('<button class="new-element">add</button>')
+
+ $('.new-element').map ->
+ $(@).click ->
+ false
+