OSDN Git Service

add app body
[pettanr/pettanr.git] / app / assets / javascripts / views / ground_pictures / element.js.coffee
1 class Pettanr.Views.GroundPicture.Element extends Backbone.View\r
2   tagName: 'div'\r
3   className: 'pettanr-comic-ground-picture'\r
4   \r
5   initialize: (options) ->\r
6     @element = options.element\r
7     @root = options.root\r
8     @spot = options.spot\r
9     @picture = @element.picture()\r
10     @picture.fetch({cache: true}).done =>\r
11       @restyle()\r
12   \r
13   clear: () ->\r
14     this\r
15   \r
16   render: () ->\r
17     this\r
18   \r
19   restyle: () ->\r
20     s = @style(@spot)\r
21     _.extend(s, @style_wh())\r
22     attr = {\r
23       style: Pettanr.to_style(s)\r
24     }\r
25     this.$el.attr(attr)\r
26   \r
27   add_element: (element) ->\r
28     null\r
29   \r
30   style: (spot = null, opacity = 20) ->\r
31     r = {\r
32       position: 'absolute', \r
33       top: '0px', \r
34       left: '0px',\r
35       'z-index': @element.get('z'), \r
36       'background-image': 'url(' + @picture.r_url() + ')', \r
37       'background-repeat': @element.repeat_text(), \r
38       'background-position': Pettanr.to_s(@element.get('x')) + 'px ' + Pettanr.to_s(@element.get('y')) + 'px'\r
39     }\r
40     r\r
41   \r
42   style_wh: () ->\r
43     {\r
44       width: Pettanr.to_s(@root.get('width')) + 'px', \r
45       height: Pettanr.to_s(@root.get('height')) + 'px'\r
46     }\r
47   \r
48 class Pettanr.Views.GroundPicture.Element.Edit extends Pettanr.Views.GroundPicture.Element\r
49   \r
50   initialize: (options) ->\r
51     super(options)\r
52     @listenTo(@root, 'resize', @restyle)\r
53     @listenTo(@root, 'input:width', @restyle)\r
54     @listenTo(@root, 'input:height', @restyle)\r
55     @listenTo(@element, 'input:repeat', @restyle)\r
56     @listenTo(@element, 'input:x', @restyle)\r
57     @listenTo(@element, 'input:y', @restyle)\r
58     @listenTo(@element, 'active', @active)\r
59     @listenTo(@element, 'inactive', @inactive)\r
60   \r
61   active: () ->\r
62     @root.trigger('active')\r
63   \r
64   inactive: () ->\r
65     @root.trigger('inactive')\r
66   \r