OSDN Git Service

add editor event of speechballoon
[pettanr/pettanr.git] / app / assets / javascripts / views / balloons / element.js.coffee
index 7a2d5e2..bf63c6d 100644 (file)
@@ -6,15 +6,65 @@ class Pettanr.Views.Balloon.Element extends Backbone.View
     @element = options.element\r
     @root = options.root\r
     @spot = options.spot\r
+    @speech_balloon = options.parent\r
+    @system_picture = @element.system_picture()\r
+    @system_picture.fetch({cache: true}).done =>\r
+      @render()\r
+  \r
+  clear: () ->\r
+    this\r
   \r
   render: () ->\r
-    _this = this\r
-    system_picture = @element.system_picture()\r
-    system_picture.fetch().done ->\r
-      attr = {\r
-        src: system_picture.r_url(), \r
-        alt: _this.element.get('caption')\r
-      }\r
-      _this.$el.attr(attr)\r
+    attr = {\r
+      src: @system_picture.r_url(), \r
+      alt: @element.get('caption')\r
+    }\r
+    this.$el.attr(attr)\r
     this\r
   \r
+class Pettanr.Views.Balloon.Element.Edit extends Pettanr.Views.Balloon.Element\r
+  \r
+  initialize: (options) ->\r
+    super(options)\r
+  \r
+  render: () ->\r
+    super()\r
+    sb = @speech_balloon\r
+    elm = @element\r
+    this.$el.resizable {\r
+      stop: (event, ui) ->\r
+        resize_div = $(@)\r
+        speech_balloon_div = sb.$el\r
+        \r
+        resize_div.css('top', '0px')\r
+        resize_div.css('left', '0px')\r
+        width = ui.size.width\r
+        height = ui.size.height\r
+        top = speech_balloon_div.position().top\r
+        if ui.originalPosition.top != ui.position.top\r
+          top += ui.position.top\r
+          speech_balloon_div.css('top', top.toString() + 'px')\r
+          speech_balloon_div.css('height', height + 'px')\r
+        left = speech_balloon_div.position().left\r
+        if ui.originalPosition.left != ui.position.left\r
+          left += ui.position.left\r
+          speech_balloon_div.css('left', left.toString() + 'px')\r
+          speech_balloon_div.css('width', width + 'px')\r
+        speech_balloon_div.css('width', width.toString() + 'px')\r
+        speech_balloon_div.css('height', height.toString() + 'px')\r
+        elm.set({\r
+          x: Math.floor(left), \r
+          y: Math.floor(top), \r
+          width: width, \r
+          height: height\r
+        }, {silent: true})\r
+        elm.trigger('resize')\r
+     resize: (event, ui) ->\r
+        resize_div = $(@)\r
+        speech_balloon_div = resize_div.parent()\r
+      handles: 'all',\r
+      autoHide: true\r
+    }\r
+    this\r
+  \r
+  \r