OSDN Git Service

fix board label
[pettanr/pettanr.git] / app / assets / javascripts / views / panel_pictures / element.js.coffee
index a8e56cf..d32062d 100644 (file)
@@ -17,11 +17,14 @@ class Pettanr.Views.PanelPicture.Element extends Backbone.View
     this\r
   \r
   render: () ->\r
-    @attr = {style: Pettanr.to_style(@style())}\r
-    this.$el.attr(@attr)\r
+    @restyle()\r
     this.$el.html(@img.clear().el)\r
     this\r
   \r
+  restyle: () ->\r
+    attr = {style: Pettanr.to_style(@style())}\r
+    this.$el.attr(attr)\r
+  \r
   add_element: (element) ->\r
     null\r
   \r
@@ -55,9 +58,12 @@ class Pettanr.Views.PanelPicture.Element.Img extends Backbone.View
     this\r
   \r
   render: () ->\r
-    this.$el.attr(@attr(@spot))\r
+    @restyle()\r
     this\r
   \r
+  restyle: () ->\r
+    this.$el.attr(@attr(@spot))\r
+  \r
   attr: (spot = null, opacity = 20) ->\r
     style = {}\r
     if spot and spot.constructor == @element.constructor and spot.get('id') != @element.get('id')\r
@@ -75,8 +81,11 @@ class Pettanr.Views.PanelPicture.Element.Edit extends Pettanr.Views.PanelPicture
   \r
   initialize: (options) ->\r
     super(options)\r
-    @listenTo(@root, 'input:width', @restyle)\r
-    @listenTo(@root, 'input:height', @restyle)\r
+    @listenTo(@element, 'input:x', @restyle)\r
+    @listenTo(@element, 'input:y', @restyle)\r
+    @listenTo(@element, 'input:z', @restyle)\r
+    @listenTo(@element, 'active', @active)\r
+    @listenTo(@element, 'inactive', @inactive)\r
   \r
   render: () ->\r
     super()\r
@@ -92,6 +101,14 @@ class Pettanr.Views.PanelPicture.Element.Edit extends Pettanr.Views.PanelPicture
     }\r
     this\r
   \r
+  active: () ->\r
+    $('.ui-resizable-handle', this.el).map ->\r
+      $(@).css('display', 'block')\r
+  \r
+  inactive: () ->\r
+    $('.ui-resizable-handle', this.el).map ->\r
+      $(@).css('display', 'none')\r
+  \r
   element_class: (element) ->\r
     Pettanr.Views[element.singular()].Element.Edit\r
   \r
@@ -102,6 +119,8 @@ class Pettanr.Views.PanelPicture.Element.Img.Edit extends Pettanr.Views.PanelPic
   \r
   initialize: (options) ->\r
     super(options)\r
+    @listenTo(@element, 'input:width', @restyle)\r
+    @listenTo(@element, 'input:height', @restyle)\r
   \r
   render: () ->\r
     super()\r
@@ -142,3 +161,12 @@ class Pettanr.Views.PanelPicture.Element.Img.Edit extends Pettanr.Views.PanelPic
       handles: 'all',\r
       autoHide: true\r
     }\r
+  \r
+  restyle: () ->\r
+    super()\r
+    resize_div = this.$el.parent()\r
+    width = this.$el.css('width')\r
+    height = this.$el.css('height')\r
+    resize_div.width(width)\r
+    resize_div.height(height)\r
+  \r