OSDN Git Service

d14426a5b73e02a2a3e6fd343405f6abdab7c188
[pettanr/pettanr.git] / app / assets / javascripts / views / balloons / element.js.coffee
1 class Pettanr.Views.Balloon.Element extends Pettanr.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   \r
11   clear: () ->\r
12     this\r
13   \r
14   render: () ->\r
15     this.$el.html('')\r
16     @element.get_parent('system_picture', this, {\r
17       success: (@system_picture) =>\r
18         @set_style()\r
19         @init_picture()\r
20     })\r
21   \r
22   init_picture: () ->\r
23   \r
24   set_style: () ->\r
25     attr = {\r
26       src: @system_picture.picture_file().src(), \r
27       alt: @element.get('caption'),\r
28       style: Pettanr.to_style(@style())\r
29     }\r
30     this.$el.attr(attr)\r
31   \r
32   style: () ->\r
33     {\r
34       'width': '100%',\r
35       'height': '100%',\r
36       'z-index': 1  # play case\r
37     }\r
38   \r
39   add_element: (element) ->\r
40     null\r
41   \r
42 class Pettanr.Views.Balloon.Element.Edit extends Pettanr.Views.Balloon.Element\r
43   \r
44   initialize: (options) ->\r
45     super(options)\r
46   \r
47   init_picture: () ->\r
48     @listenTo(@element, 'input:system_picture_id', @input_r)\r
49     @listenTo(@element, 'input:width', @resize)\r
50     @listenTo(@element, 'input:height', @resize)\r
51     sb = @speech_balloon\r
52     elm = @element\r
53     this.$el.resizable {\r
54       stop: (event, ui) ->\r
55         resize_div = $(@)\r
56         speech_balloon_div = sb.$el\r
57         \r
58         resize_div.css('top', '0px')\r
59         resize_div.css('left', '0px')\r
60         # resize_div.css('z-index', 1)\r
61         width = ui.size.width\r
62         height = ui.size.height\r
63         top = speech_balloon_div.position().top\r
64         if ui.originalPosition.top != ui.position.top\r
65           top += ui.position.top\r
66           speech_balloon_div.css('top', top.toString() + 'px')\r
67           speech_balloon_div.css('height', height + 'px')\r
68         left = speech_balloon_div.position().left\r
69         if ui.originalPosition.left != ui.position.left\r
70           left += ui.position.left\r
71           speech_balloon_div.css('left', left.toString() + 'px')\r
72           speech_balloon_div.css('width', width + 'px')\r
73         speech_balloon_div.css('width', width.toString() + 'px')\r
74         speech_balloon_div.css('height', height.toString() + 'px')\r
75         elm.set({\r
76           x: Math.floor(left), \r
77           y: Math.floor(top), \r
78           width: width, \r
79           height: height\r
80         }, {silent: true})\r
81         elm.trigger('resize')\r
82       handles: 'all',\r
83       autoHide: true\r
84     }\r
85     this\r
86   \r
87   style: () ->\r
88     {\r
89       top: '0px',\r
90       left: '0px',\r
91       width: Pettanr.to_s(@element.get('width')) + 'px', \r
92       height: Pettanr.to_s(@element.get('height')) + 'px',\r
93       'z-index': 1  # play case\r
94     }\r
95   \r
96   input_r: () ->\r
97     @render()\r
98     resize_div = this.$el.parent()\r
99     resize_div.css('z-index', 1)\r
100   \r
101   resize: () ->\r
102     resize_div = this.$el.parent()\r
103     resize_div.css('width', '100%')\r
104     resize_div.css('height', '100%')\r
105     this.$el.css('width',  '100%')\r
106     this.$el.css('height', '100%')\r
107   \r