OSDN Git Service

fix: js models
[pettanr/pettanr.git] / app / assets / javascripts / models / ground_picture.js.coffee
1 class Pettanr.GroundPicture extends Peta.Element\r
2   @singular: () ->\r
3     'GroundPicture'\r
4   \r
5   @plural: () ->\r
6     'GroundPictures'\r
7   \r
8   defaults: {\r
9     id: null,\r
10     x: 0,\r
11     y: 0,\r
12     repeat: 0\r
13   } \r
14   \r
15   @repeat_texts: () -> \r
16     ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']\r
17   \r
18   picture: () ->\r
19     @get('picture')\r
20   \r
21   has_picture: () ->\r
22     true\r
23   \r
24   style: (spot = null, opacity = 20) ->\r
25     r = {\r
26       position: 'absolute', \r
27       top: '0px', \r
28       left: '0px',\r
29       'z-index': @get('z'), \r
30       'background-image': 'url(' + @picture().r_url() + ')', \r
31       'background-repeat': @repeat_text(), \r
32       'background-position': Pettanr.to_s(@get('x')) + 'px ' + Pettanr.to_s(@get('y')) + 'px'\r
33     }\r
34     @merge_opacity(r, opacity) if spot and spot != this\r
35     r\r
36   \r
37   tmb_opt_img_tag: () ->\r
38     wh = Pettanr.Imager.thumbnail_size(@picture().get('width'), @picture().get('height'))\r
39     {src: @picture().r_url(), width: wh[0], height: wh[1], alt: @get('caption')}\r
40   \r
41   symbol_option: () ->\r
42     @tmb_opt_img_tag()\r
43   \r
44   repeat_text: () ->\r
45     Pettanr.GroundPicture.repeat_texts()[@get('repeat')]\r
46   \r
47   initialize: () ->\r
48     if @id\r
49       @url = @url + @id\r
50   \r
51 class Pettanr.GroundPicture.Collection extends Backbone.Collection\r
52   model: Pettanr.GroundPicture\r
53   url: '/ground_pictures'\r