OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / views / ground_pictures / element.js.coffee
index 8323822..52911b5 100644 (file)
@@ -1,4 +1,4 @@
-class Pettanr.Views.GroundPicture.Element extends Backbone.View\r
+class Pettanr.Views.GroundPicture.Element extends Pettanr.View\r
   tagName: 'div'\r
   className: 'pettanr-comic-ground-picture'\r
   \r
@@ -7,14 +7,23 @@ class Pettanr.Views.GroundPicture.Element extends Backbone.View
     @root = options.root\r
     @spot = options.spot\r
   \r
+  init_picture: () ->\r
+  \r
   render: () ->\r
+    @element.get_parent('picture', this, {\r
+      success: (@picture) =>\r
+        @init_picture()\r
+        @restyle()\r
+    })\r
+    this\r
+  \r
+  restyle: () ->\r
     s = @style(@spot)\r
     _.extend(s, @style_wh())\r
     attr = {\r
       style: Pettanr.to_style(s)\r
     }\r
     this.$el.attr(attr)\r
-    this\r
   \r
   style: (spot = null, opacity = 20) ->\r
     r = {\r
@@ -22,11 +31,10 @@ class Pettanr.Views.GroundPicture.Element extends Backbone.View
       top: '0px', \r
       left: '0px',\r
       'z-index': @element.get('z'), \r
-      'background-image': 'url(' + @picture().r_url() + ')', \r
-      'background-repeat': @repeat_text(), \r
-      'background-position': Pettanr.to_s(@element.get('x')) + 'px ' + Pettanr.to_s(@element.get('y')) + 'px'\r
+      'background-image': 'url(' + @picture.picture_file().src() + ')', \r
+      'background-repeat': @element.repeat_text(), \r
+      'background-position': Pettanr.to_s(@element.get('x')) + '% ' + Pettanr.to_s(@element.get('y')) + '%'\r
     }\r
-    @merge_opacity(r, opacity) if spot and spot != @element\r
     r\r
   \r
   style_wh: () ->\r
@@ -35,3 +43,26 @@ class Pettanr.Views.GroundPicture.Element extends Backbone.View
       height: Pettanr.to_s(@root.get('height')) + 'px'\r
     }\r
   \r
+class Pettanr.Views.GroundPicture.Element.Edit extends Pettanr.Views.GroundPicture.Element\r
+  \r
+  initialize: (options) ->\r
+    super(options)\r
+  \r
+  init_picture: () ->\r
+    super()\r
+    @listenTo(@root, 'resize', @restyle)\r
+    @listenTo(@root, 'input:width', @restyle)\r
+    @listenTo(@root, 'input:height', @restyle)\r
+    @listenTo(@element, 'input:repeat', @restyle)\r
+    @listenTo(@element, 'input:x', @restyle)\r
+    @listenTo(@element, 'input:y', @restyle)\r
+    @listenTo(@element, 'active', @active)\r
+    @listenTo(@element, 'inactive', @inactive)\r
+    @listenTo(@element, 'sort', @restyle)\r
+  \r
+  active: () ->\r
+    @root.trigger('active')\r
+  \r
+  inactive: () ->\r
+    @root.trigger('inactive')\r
+  \r