OSDN Git Service

bf63c6df4487f93f72e2168e035f3cd0dccb1f29
[pettanr/pettanr.git] / app / assets / javascripts / views / balloons / element.js.coffee
1 class Pettanr.Views.Balloon.Element extends Backbone.View\r
2   tagName: 'img'\r
3   className: 'pettanr-balloon'\r
4   \r
5   initialize: (options) ->\r
6     @element = options.element\r
7     @root = options.root\r
8     @spot = options.spot\r
9     @speech_balloon = options.parent\r
10     @system_picture = @element.system_picture()\r
11     @system_picture.fetch({cache: true}).done =>\r
12       @render()\r
13   \r
14   clear: () ->\r
15     this\r
16   \r
17   render: () ->\r
18     attr = {\r
19       src: @system_picture.r_url(), \r
20       alt: @element.get('caption')\r
21     }\r
22     this.$el.attr(attr)\r
23     this\r
24   \r
25 class Pettanr.Views.Balloon.Element.Edit extends Pettanr.Views.Balloon.Element\r
26   \r
27   initialize: (options) ->\r
28     super(options)\r
29   \r
30   render: () ->\r
31     super()\r
32     sb = @speech_balloon\r
33     elm = @element\r
34     this.$el.resizable {\r
35       stop: (event, ui) ->\r
36         resize_div = $(@)\r
37         speech_balloon_div = sb.$el\r
38         \r
39         resize_div.css('top', '0px')\r
40         resize_div.css('left', '0px')\r
41         width = ui.size.width\r
42         height = ui.size.height\r
43         top = speech_balloon_div.position().top\r
44         if ui.originalPosition.top != ui.position.top\r
45           top += ui.position.top\r
46           speech_balloon_div.css('top', top.toString() + 'px')\r
47           speech_balloon_div.css('height', height + 'px')\r
48         left = speech_balloon_div.position().left\r
49         if ui.originalPosition.left != ui.position.left\r
50           left += ui.position.left\r
51           speech_balloon_div.css('left', left.toString() + 'px')\r
52           speech_balloon_div.css('width', width + 'px')\r
53         speech_balloon_div.css('width', width.toString() + 'px')\r
54         speech_balloon_div.css('height', height.toString() + 'px')\r
55         elm.set({\r
56           x: Math.floor(left), \r
57           y: Math.floor(top), \r
58           width: width, \r
59           height: height\r
60         }, {silent: true})\r
61         elm.trigger('resize')\r
62      resize: (event, ui) ->\r
63         resize_div = $(@)\r
64         speech_balloon_div = resize_div.parent()\r
65       handles: 'all',\r
66       autoHide: true\r
67     }\r
68     this\r
69   \r
70   \r