OSDN Git Service

t#31920:fix resize js
authoryasushiito <yas@pen-chan.jp>
Fri, 30 Aug 2013 04:57:16 +0000 (13:57 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 30 Aug 2013 04:57:16 +0000 (13:57 +0900)
app/assets/javascripts/panels.js.coffee

index ec8547a..70933de 100644 (file)
@@ -192,9 +192,35 @@ $ ->
   $('.panel-picture').map ->\r
     $(@).resizable {\r
       stop: ( event, ui ) ->\r
-        trace = element_tag_id($(@).parent())\r
-        $(trace + 'width').val($(@).width())\r
-        $(trace + 'height').val($(@).height())\r
+        resize_div = $(@)\r
+        panel_picture_div = resize_div.parent()\r
+        trace = element_tag_id(panel_picture_div)\r
+        \r
+        resize_div.css('top', '0px')\r
+        resize_div.css('left', '0px')\r
+        if ui.originalPosition.top != ui.position.top\r
+          t = panel_picture_div.position().top + ui.position.top\r
+          $(trace + 'y').val(Math.floor(t))\r
+          panel_picture_div.css('top', t.toString() + 'px')\r
+        if ui.originalPosition.left != ui.position.left\r
+          l = panel_picture_div.position().left + ui.position.left\r
+          $(trace + 'x').val(Math.floor(l))\r
+          panel_picture_div.css('left', l.toString() + 'px')\r
+        w = if $(trace + 'width').val() < 0\r
+          -ui.size.width\r
+        else\r
+          ui.size.width\r
+        h = if $(trace + 'height').val() < 0\r
+          -ui.size.height\r
+        else\r
+          ui.size.height\r
+        $(trace + 'width').val(w)\r
+        $(trace + 'height').val(h)\r
+      resize: ( event, ui ) ->\r
+        resize_div = $(@)\r
+        panel_picture_div = resize_div.parent()\r
+        trace = element_tag_id(panel_picture_div)\r
+        \r
       handles: 'all',\r
       autoHide: true\r
     }\r
@@ -246,8 +272,8 @@ $ ->
   $('.pettanr-comic-balloon' ).map ->\r
     $(@).draggable {\r
       stop: ( event, ui ) ->\r
-        img = $('.pettanr-balloon', $(@))\r
-        trace = element_part_tag_id(img)\r
+        balloon = $('.pettanr-balloon', $(@))\r
+        trace = element_part_tag_id(balloon)\r
         left = $(@).position().left\r
         top = $(@).position().top\r
         $(trace + 'x').val(parseInt(left))\r
@@ -257,18 +283,41 @@ $ ->
   $('.pettanr-balloon' ).map ->\r
     $(@).resizable {\r
       stop: ( event, ui ) ->\r
-        img = $('.pettanr-balloon', $(@))\r
-        trace = element_part_tag_id(img)\r
-        $(trace + 'width').val($(@).width())\r
-        $(trace + 'height').val($(@).height())\r
+        resize_div = $(@)\r
+        speech_balloon_div = resize_div.parent()\r
+        balloon = $('.pettanr-balloon', $(@))\r
+        trace = element_tag_id(speech_balloon_div)\r
+        trace_balloon = element_part_tag_id(balloon)\r
+        \r
+        resize_div.css('top', '0px')\r
+        resize_div.css('left', '0px')\r
+        w = ui.size.width\r
+        h = ui.size.height\r
+        if ui.originalPosition.top != ui.position.top\r
+          t = speech_balloon_div.position().top + ui.position.top\r
+          $(trace_balloon + 'y').val(Math.floor(t))\r
+          speech_balloon_div.css('top', t.toString() + 'px')\r
+          speech_balloon_div.css('height', h + 'px')\r
+        if ui.originalPosition.left != ui.position.left\r
+          l = speech_balloon_div.position().left + ui.position.left\r
+          $(trace_balloon + 'x').val(Math.floor(l))\r
+          speech_balloon_div.css('left', l.toString() + 'px')\r
+          speech_balloon_div.css('width', w + 'px')\r
+        $(trace_balloon + 'width').val(w)\r
+        $(trace_balloon + 'height').val(h)\r
+        speech_balloon_div.css('width', w.toString() + 'px')\r
+        speech_balloon_div.css('height', h.toString() + 'px')\r
      resize: ( event, ui ) ->\r
-        img = $('.pettanr-balloon', $(@))\r
-        sb = element_tag_id(img)\r
-        $(sb).width($(@).width())\r
-        $(sb).height($(@).height())\r
+        resize_div = $(@)\r
+        speech_balloon_div = resize_div.parent()\r
+        balloon = $('.pettanr-balloon', $(@))\r
+        trace = element_tag_id(speech_balloon_div)\r
+        trace_balloon = element_part_tag_id(balloon)\r
+        \r
       handles: 'all',\r
       autoHide: true\r
     }\r
+  \r
   $('.pettanr-comic-speech-inner' ).map ->\r
     $(@).mouseover -> \r
       outer = $(@).parent()\r