OSDN Git Service

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