OSDN Git Service

t#32246:add sheet
[pettanr/pettanr.git] / app / assets / javascripts / sheets.js.coffee
index 634a64f..c9ebf21 100644 (file)
@@ -1,11 +1,11 @@
 $ ->
   confirm_confirm_confirm = () ->
     confirm(  )
-  editor = window.PettanrEditor
+  editor = window.PettanrSheeter
   
-  $('.panel-editor').map ->
+  $('.sheet-editor').map ->
     if $(@).attr('current') and parseInt($(@).attr('current')) > 0
-      editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
+      editor.pettanr_current_sheet_id = parseInt($(@).attr('sheet_id'))
   if editor.is_editting()
     $('#tabs').tabs()
     $('#elements-tabs').tabs()
@@ -17,12 +17,9 @@ $ ->
     $("#elements-tabs li").map ->
       $(@).mouseover -> 
         switch $(@).attr('element_type')
-          when 'speech_balloon'
+          when 'sheet_panel'
             trace = editor.element_tag_id($(@)) 
-            t = $('img', $(trace))
-          when 'panel_picture'
-            trace = editor.element_tag_id($(@)) + 'img'
-            t = $(trace)
+            t = $('.pettanr-comic-panel', $(trace))
           else
             t = null
         if t
@@ -30,12 +27,9 @@ $ ->
             $(@).css('display', 'block')
       $(@).mouseout -> 
         switch $(@).attr('element_type')
-          when 'speech_balloon'
+          when 'sheet_panel'
             trace = editor.element_tag_id($(@)) 
-            t = $('img', $(trace))
-          when 'panel_picture'
-            trace = editor.element_tag_id($(@)) + 'img'
-            t = $(trace)
+            t = $('.pettanr-comic-panel', $(trace))
           else
             t = null
         if t
@@ -55,9 +49,9 @@ $ ->
         if confirm('destroy ?')
           trace = editor.element_tag_id($(@))
           $(trace + '_destroy').val('true')
-          panel_trace = editor.panel_tag_id($(@))
-          update_t(panel_trace + 'tsort')
-          update_z(panel_trace + 'zsort')
+          sheet_trace = editor.panel_tag_id($(@))
+          update_t(sheet_trace + 'tsort')
+          update_z(sheet_trace + 'zsort')
           # sync
           $(trace + 'element_tab').css('display', 'none')
           $(trace + 'tab_panel').css('display', 'none')
@@ -69,25 +63,19 @@ $ ->
           $(trace).css('display', 'none')
           
     
-    $('#pettanr-panel-submit').focusin ->
-      editor.refresh_attribute($('#pettanr-panel-json'))
+    $('#pettanr-sheet-submit').focusin ->
+      editor.refresh_attribute($('#pettanr-sheet-json'))
     
-    # panel
-    $('.pettanr-comic-panel').map ->
+    # sheet
+    $('.sheet').map ->
       if editor.is_editable($(@))
         $(@).resizable {
           stop: ( event, ui ) ->
-            trace = editor.panel_tag_id($(@))
+            trace = editor.sheet_tag_id($(@))
             w = parseInt($(@).width())
             h = parseInt($(@).height())
             $(trace + 'width').val(w)
             $(trace + 'height').val(h)
-            $('.pettanr-comic-ground-picture').map ->
-              $(@).width(w)
-              $(@).height(h)
-            $('.pettanr-comic-ground-color').map ->
-              $(@).width(w)
-              $(@).height(h)
           , autoHide: true
         }
     
@@ -95,168 +83,30 @@ $ ->
     $('input').map  ->
       if $(@).attr('element_type')
       else
-        if $(@).attr('panel_id')
+        if $(@).attr('sheet_id')
           $(@).focusout ->
             switch $(@).attr('column')
               when 'width'
-                trace = editor.panel_tag_id($(@))
+                trace = editor.sheet_tag_id($(@))
                 $(trace).width(parseInt( $(@).val()))
               when 'height'
-                trace = editor.panel_tag_id($(@))
+                trace = editor.sheet_tag_id($(@))
                 $(trace).height(parseInt( $(@).val()))
-              when 'border'
-                trace = editor.panel_tag_id($(@))
-                $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
     
-    # panel picture
-    PictureSizeHelper.add_helper()
-    
-    $('.pettanr-panel-picture-wrapper').map ->
+    $('.sheet_panel').map ->
       $(@).draggable {
         stop: ( event, ui ) ->
           trace = editor.element_tag_id($(@))
-          img = $(trace + 'img')
-          left = img.parent().position().left + $(@).position().left
-          top = img.parent().position().top + $(@).position().top
-          $(trace + 'x').val(parseInt(left))
-          $(trace + 'y').val(parseInt(top))
-      }
-    
-    $('.panel-picture').map ->
-      $(@).resizable {
-        stop: ( event, ui ) ->
-          resize_div = $(@)
-          panel_picture_div = resize_div.parent()
-          trace = editor.element_tag_id(panel_picture_div)
-          
-          resize_div.css('top', '0px')
-          resize_div.css('left', '0px')
-          if ui.originalPosition.top != ui.position.top
-            t = panel_picture_div.position().top + ui.position.top
-            $(trace + 'y').val(Math.floor(t))
-            panel_picture_div.css('top', t.toString() + 'px')
-          if ui.originalPosition.left != ui.position.left
-            l = panel_picture_div.position().left + ui.position.left
-            $(trace + 'x').val(Math.floor(l))
-            panel_picture_div.css('left', l.toString() + 'px')
-          w = if $(trace + 'width').val() < 0
-            -ui.size.width
-          else
-            ui.size.width
-          h = if $(trace + 'height').val() < 0
-            -ui.size.height
-          else
-            ui.size.height
-          $(trace + 'width').val(w)
-          $(trace + 'height').val(h)
-        resize: ( event, ui ) ->
-          resize_div = $(@)
-          panel_picture_div = resize_div.parent()
-          trace = editor.element_tag_id(panel_picture_div)
-        handles: 'all',
-        autoHide: true
-      }
-    
-    # sync view 
-    $('input').map  ->
-      if editor.element_is('panel_picture', $(@))
-        $(@).focusout ->
-          switch $(@).attr('column')
-            when 'x'
-              trace = editor.element_tag_id($(@)) + 'div'
-              v = parseInt($(@).val()).toString() + 'px'
-              $(trace).css('left', v)
-            when 'y'
-              trace = editor.element_tag_id($(@)) + 'div'
-              v = parseInt($(@).val()).toString() + 'px'
-              $(trace).css('top', v)
-            when 'width'
-              trace = editor.element_tag_id($(@)) + 'img'
-              w = parseInt($(@).val())
-              $(trace).width(Math.abs(w))
-              $(trace).parent().width(Math.abs(w))
-              h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
-            when 'height'
-              trace = editor.element_tag_id($(@)) + 'img'
-              h = parseInt($(@).val())
-              $(trace).height(Math.abs(h))
-              $(trace).parent().height(Math.abs(h))
-              w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
-            else
-          PictureSizeHelper.refresh_picture($(trace), w, h)
-      else
-    
-    # speech_balloons
-    ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
-    
-    $('.pettanr-comic-balloon' ).map ->
-      $(@).draggable {
-        stop: ( event, ui ) ->
-          balloon = $('.pettanr-balloon', $(@))
-          trace = editor.element_part_tag_id(balloon)
           left = $(@).position().left
           top = $(@).position().top
           $(trace + 'x').val(parseInt(left))
           $(trace + 'y').val(parseInt(top))
+        , cursor: "crosshair"
       }
     
-    $('.pettanr-balloon' ).map ->
-      $(@).resizable {
-        stop: ( event, ui ) ->
-          resize_div = $(@)
-          speech_balloon_div = resize_div.parent()
-          balloon = $('.pettanr-balloon', $(@))
-          trace = editor.element_tag_id(speech_balloon_div)
-          trace_balloon = editor.element_part_tag_id(balloon)
-          
-          resize_div.css('top', '0px')
-          resize_div.css('left', '0px')
-          w = ui.size.width
-          h = ui.size.height
-          if ui.originalPosition.top != ui.position.top
-            t = speech_balloon_div.position().top + ui.position.top
-            $(trace_balloon + 'y').val(Math.floor(t))
-            speech_balloon_div.css('top', t.toString() + 'px')
-            speech_balloon_div.css('height', h + 'px')
-          if ui.originalPosition.left != ui.position.left
-            l = speech_balloon_div.position().left + ui.position.left
-            $(trace_balloon + 'x').val(Math.floor(l))
-            speech_balloon_div.css('left', l.toString() + 'px')
-            speech_balloon_div.css('width', w + 'px')
-          $(trace_balloon + 'width').val(w)
-          $(trace_balloon + 'height').val(h)
-          speech_balloon_div.css('width', w.toString() + 'px')
-          speech_balloon_div.css('height', h.toString() + 'px')
-       resize: ( event, ui ) ->
-          resize_div = $(@)
-          speech_balloon_div = resize_div.parent()
-          balloon = $('.pettanr-balloon', $(@))
-          trace = editor.element_tag_id(speech_balloon_div)
-          trace_balloon = editor.element_part_tag_id(balloon)
-        handles: 'all',
-        autoHide: true
-      }
-    
-    $('.pettanr-comic-speech-inner' ).map ->
-      $(@).mouseover -> 
-        outer = $(@).parent()
-        sb = outer.parent()
-        trace = editor.element_tag_id(sb)
-        img = $('.pettanr-balloon', $(trace))
-        $('.ui-resizable-handle', img.parent()).map ->
-          $(@).css('display', 'block')
-      $(@).mouseout -> 
-        outer = $(@).parent()
-        sb = outer.parent()
-        trace = editor.element_tag_id(sb)
-        img = $('.pettanr-balloon', $(trace))
-        $('.ui-resizable-handle', img.parent()).map ->
-          $(@).css('display', 'none')
-          
-    
     # sync view 
     $('input').map  ->
-      if editor.element_is('speech_balloon', $(@))
+      if editor.element_is('sheet_panel', $(@))
         $(@).focusout ->
           switch $(@).attr('column')
             when 'x'
@@ -267,92 +117,9 @@ $ ->
               trace = editor.element_tag_id($(@))
               v = parseInt($(@).val()).toString() + 'px'
               $(trace).css('top', v)
-            when 'width'
-              trace = editor.element_tag_id($(@))
-              v = parseInt($(@).val())
-              $(trace).width(Math.abs(v))
-              img = $('.pettanr-balloon', $(trace))
-              img.parent().width(v)
-              img.width(v)
-            when 'height'
-              trace = editor.element_tag_id($(@))
-              v = parseInt($(@).val())
-              $(trace).height(Math.abs(v))
-              img = $('.pettanr-balloon', $(trace))
-              img.parent().height(v)
-              img.height(v)
             else
       else
-    $('textarea').map  ->
-      if editor.element_is('speech_balloon', $(@))
-        $(@).focusout ->
-          switch $(@).attr('column')
-            when 'content'
-              trace = editor.element_part_tag_id($(@))
-              wf_sel = $(trace + 'writing_format_id')
-              wf_id = parseInt(wf_sel.val())
-              v = WritingFormat.render(wf_id, $(@).val())
-              $(trace).html(v)
-    $('textarea').map  ->
-      if editor.element_is('speech_balloon', $(@))
-        switch $(@).attr('column')
-          when 'content'
-            $(@).bind('textchange', (event, previousText) ->
-              trace = editor.element_part_tag_id($(@))
-              wf_sel = $(trace + 'writing_format_id')
-              wf_id = parseInt(wf_sel.val())
-              v = WritingFormat.render(wf_id, $(@).val())
-              $(trace).html(v)
-            )
-    $('select').map  ->
-      if editor.element_is('speech_balloon', $(@))
-        $(@).change ->
-          switch $(@).attr('column')
-            when 'font_size'
-              trace = editor.element_part_tag_id($(@))
-              $(trace).css('font-size', $(@).val() + 'em')
-            when 'text_align'
-              trace = editor.element_part_tag_id($(@))
-              v = parseInt($(@).val())
-              $(trace).css('text-align', editor.text_align_texts[v])
-      else
-    $('input').map  ->
-      if editor.element_is('speech_balloon', $(@))
-        if $(@).attr('column') == 'fore_color'
-          $(@).hide()
-
-    
-    # ground-picture
-    # sync view 
-    $('input').map  ->
-      if editor.element_is('ground_picture', $(@))
-        $(@).focusout ->
-          switch $(@).attr('column')
-            when 'x', 'y'
-              trace = editor.element_tag_id($(@))
-              x = parseInt($(trace + 'x').val()).toString() + 'px'
-              y = parseInt($(trace + 'y').val()).toString() + 'px'
-              $(trace).css('background-position', x + ' ' + y)
-    $('select').map  ->
-      if editor.element_is('ground_picture', $(@))
-        $(@).change ->
-          switch $(@).attr('column')
-            when 'repeat'
-              trace = editor.element_tag_id($(@))
-              v = parseInt($(@).val())
-              $(trace).css('background-repeat', editor.repeat_texts[v])
-      else
-    
     
-    # ground_color
-    ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
-    
-    # sync view 
-    $('input').map  ->
-      if editor.element_is('ground_color', $(@))
-        if $(@).attr('column') == 'code'
-          $(@).hide()
-
     update_t = (ultrace) -> 
       t = 0
       $(ultrace + ' li').map ->
@@ -365,7 +132,7 @@ $ ->
     $('.tsort').map -> 
       $(@).sortable {
         update: ( event, ui ) ->
-          trace = editor.panel_tag_id($(@))
+          trace = editor.sheet_tag_id($(@))
           update_t(trace + 'tsort')
       }
     $('.t-sort li').map -> 
@@ -388,7 +155,7 @@ $ ->
     $('.zsort').map -> 
       $(@).sortable {
         update: ( event, ui ) ->
-          trace = editor.panel_tag_id($(@))
+          trace = editor.sheet_tag_id($(@))
           update_z(trace + 'zsort')
       }
     $('.z-sort li').map -> 
@@ -396,21 +163,8 @@ $ ->
     
     # all
     # disable form actions
-    # hide submit buttons
-    $('.edit_panel_picture' ).map ->
-      $(@).submit ->
-        false
-    $('.edit_speech_balloon' ).map ->
-      $(@).submit ->
-        false
-    $('.edit_ground_picture' ).map ->
-      $(@).submit ->
-        false
-    $('.edit_ground_color' ).map ->
-      $(@).submit ->
-        false
     
-    $('.edit_panel' ).map ->
+    $('.edit_sheet' ).map ->
       if $(@).attr('jqform')
       else
         $(@).submit ->