OSDN Git Service

add app body
[pettanr/pettanr.git] / app / assets / javascripts / views / ground_colors / element.js.coffee
1 class Pettanr.Views.GroundColor.Element extends Backbone.View\r
2   tagName: 'div'\r
3   className: 'pettanr-comic-ground-color'\r
4   \r
5   initialize: (options) ->\r
6     @element = options.element\r
7     @root = options.root\r
8     @spot = options.spot\r
9   \r
10   clear: () ->\r
11     this\r
12   \r
13   render: () ->\r
14     @restyle()\r
15     this\r
16   \r
17   restyle: () ->\r
18     attr = {\r
19       style: Pettanr.to_style(@style(@spot))\r
20     }\r
21     this.$el.attr(attr)\r
22   \r
23   add_element: (element) ->\r
24     null\r
25   \r
26   div_offset: () ->\r
27     if @element.get('xy')\r
28       @element.get('xy')\r
29     else\r
30       0\r
31   \r
32   div_size: () ->\r
33     if @element.get('wh')\r
34       @element.get('wh')\r
35     else\r
36       100 - @div_offset()\r
37   \r
38   div_x: () ->\r
39     if @element.get('orientation') == 0\r
40       0\r
41     else\r
42       @div_offset()\r
43   \r
44   div_y: () ->\r
45     if @element.get('orientation') == 0\r
46       @div_offset()\r
47     else\r
48       0\r
49   \r
50   div_width: () ->\r
51     if @element.get('orientation') == 0\r
52       100\r
53     else\r
54       @div_size()\r
55   \r
56   div_height: () ->\r
57     if @element.get('orientation') == 0\r
58       @div_size()\r
59     else\r
60       100\r
61   \r
62   style: (spot = null, opacity = 20) ->\r
63     r = {\r
64       position: 'absolute', \r
65       'z-index': @element.get('z'), \r
66       top: Pettanr.to_s(@div_y()) + '%', \r
67       left: Pettanr.to_s(@div_x()) + '%', \r
68       width: Pettanr.to_s(@div_width()) + '%', \r
69       height: Pettanr.to_s(@div_height()) + '%', \r
70       'background-color': '#' + ('000000' + @element.get('code').toString(16)).slice(-6)\r
71     }\r
72     r\r
73   \r
74 class Pettanr.Views.GroundColor.Element.Edit extends Pettanr.Views.GroundColor.Element\r
75   \r
76   initialize: (options) ->\r
77     super(options)\r
78     @listenTo(@element, 'input:code', @restyle)\r
79     @listenTo(@element, 'input:xy', @restyle)\r
80     @listenTo(@element, 'input:wh', @restyle)\r
81     @listenTo(@element, 'input:orientation', @restyle)\r
82     @listenTo(@element, 'active', @active)\r
83     @listenTo(@element, 'inactive', @inactive)\r
84   \r
85   active: () ->\r
86     @root.trigger('active')\r
87   \r
88   inactive: () ->\r
89     @root.trigger('inactive')\r
90   \r