OSDN Git Service

fix:view
[pettanr/pettanr.git] / app / assets / javascripts / view / icon.js.coffee
1 # image: picture item or image file\r
2 class Pettanr.View.Icon extends Tag.Img\r
3   \r
4   initialize: (@image, options = {}) ->\r
5     attr = {}\r
6     attr['src'] = @image.src()\r
7     size = @get_size()\r
8     attr['width'] = size[0] if size[0]\r
9     attr['height'] = size[1] if size[1]\r
10     alt = if _.isFunction(options.alt)\r
11       options.alt()\r
12     else\r
13       options.alt\r
14     attr['alt'] = alt || 'no title'\r
15     title = if _.isFunction(options.title)\r
16       options.title()\r
17     else\r
18       options.title\r
19     attr['title'] = title || 'no title'\r
20     opt = {\r
21       attr: attr,\r
22       class_name: options.class_name\r
23     }\r
24     super(opt)\r
25   \r
26   get_size: () ->\r
27     @image.thumbnail_size()\r
28   \r
29 class Pettanr.View.Minicon extends Pettanr.View.Icon\r
30   \r
31   initialize: (@image, options = {}) ->\r
32     super(@image, options)\r
33   \r
34   get_size: () ->\r
35     @image.minicon_size()\r
36   \r