OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / helpers / picture_size.js.coffee
1 class PettanrPictureSizeHelper\r
2   confirm_confirm_confirm = () ->\r
3     confirm(  )\r
4   @WritingFormat = window.PettanrWritingFormat\r
5   \r
6   @refresh_picture = (e, w, h)  ->\r
7     if w and h\r
8       sd = ''\r
9       if h < 0\r
10         sd += 'v'\r
11       if w < 0\r
12         sd += 'h'\r
13       if sd.length > 0\r
14         sd += '/'\r
15       pid = parseInt(e.attr('picture_id')).toString()\r
16       ext = e.attr('ext')\r
17       src = '/pictures/' + sd + pid + '.' + ext\r
18       e.attr('src', src)\r
19   \r
20   @add_helper = () ->\r
21     editor = window.PettanrEditor\r
22     $('.panel_picture_width_tool').map ->\r
23       $(@).html('<button class="wreverse">Rev</button><button class="wdouble">x2</button><button class="whalf">/2</button>')\r
24     $('.panel_picture_height_tool').map ->\r
25       $(@).html('<button class="hreverse">Rev</button><button class="hdouble">x2</button><button class="hhalf">/2</button>')\r
26     \r
27     $('.wreverse').click -> \r
28       d = $(@).parent()\r
29       trace = editor.element_tag_id(d)\r
30       f = $(trace + 'width')\r
31       w = -f.val()\r
32       f.val(w)\r
33       f = $(trace + 'height')\r
34       h = f.val()\r
35       PettanrPictureSizeHelper.refresh_picture($(trace + 'img'), w, h)\r
36     \r
37     $('.wdouble').click -> \r
38       d = $(@).parent()\r
39       trace = editor.element_tag_id(d)\r
40       f = $(trace + 'width')\r
41       w = f.val() * 2\r
42       f.val(w)\r
43       $(trace + 'img').width(Math.abs(w))\r
44       $(trace + 'img').parent().width(Math.abs(w))\r
45     \r
46     $('.whalf').click -> \r
47       d = $(@).parent()\r
48       trace = editor.element_tag_id(d)\r
49       f = $(trace + 'width')\r
50       w = Math.floor(f.val() / 2)\r
51       f.val(w)\r
52       $(trace + 'img').width(Math.abs(w))\r
53       $(trace + 'img').parent().width(Math.abs(w))\r
54     \r
55     \r
56     $('.hreverse').click -> \r
57       d = $(@).parent()\r
58       trace = editor.element_tag_id(d)\r
59       f = $(trace + 'height')\r
60       h = -f.val()\r
61       f.val(h)\r
62       f = $(trace + 'width')\r
63       w = f.val()\r
64       PettanrPictureSizeHelper.refresh_picture($(trace + 'img'), w, h)\r
65     \r
66     $('.hdouble').click -> \r
67       d = $(@).parent()\r
68       trace = editor.element_tag_id(d)\r
69       f = $(trace + 'height')\r
70       h = f.val() * 2\r
71       f.val(h)\r
72       $(trace + 'img').height(Math.abs(h))\r
73       $(trace + 'img').parent().height(Math.abs(h))\r
74     \r
75     $('.hhalf').click -> \r
76       d = $(@).parent()\r
77       trace = editor.element_tag_id(d)\r
78       f = $(trace + 'height')\r
79       h = Math.floor(f.val() / 2)\r
80       f.val(h)\r
81       $(trace + 'img').height(Math.abs(h))\r
82       $(trace + 'img').parent().height(Math.abs(h))\r
83   \r
84   \r
85   \r
86 @PettanrPictureSizeHelper = PettanrPictureSizeHelper\r