source: extensions/Crop_Image/crop_image.tpl @ 27153

Last change on this file since 27153 was 24055, checked in by Chillexistence, 11 years ago

Added Ability to Specify the Aspect Ratio for Cropping.

File size: 5.2 KB
Line 
1<div class="titrePage">
2        <h2>{$TITLE} &#8250; {'Edit photo'|@translate} {$TABSHEET_TITLE}</h2>
3</div>
4{if $IN_CROP}
5
6{combine_css path="themes/default/js/plugins/jquery.Jcrop.css"}
7{combine_script id='jquery.jcrop' load='footer' require='jquery' path='themes/default/js/plugins/jquery.Jcrop.min.js'}
8
9{footer_script require="jquery"}
10var jcrop_api;
11
12jQuery("#jcrop").Jcrop({ldelim}
13                //boxWidth: {$crop.display_width},
14    //boxHeight: {$crop.display_height},
15                boxWidth: 500, boxHeight: 400,
16    onChange: jOnChange,
17    onRelease: jOnRelease
18        },
19  function(){ldelim}
20    jcrop_api = this;
21  });
22
23        $("input[name='ratio']").change(function(e) {ldelim}
24      if ($("input[name='ratio']:checked").val() == '1/1')
25                        {ldelim}
26                          jcrop_api.setOptions({ldelim} aspectRatio: 1/1 });
27                                document.getElementById('ratioC').disabled = true;
28                                document.getElementById('ratioC').value = '';
29                        }
30                        else if ($("input[name='ratio']:checked").val() == '4/5')
31                        {ldelim}
32                          jcrop_api.setOptions({ldelim} aspectRatio: 4/5 });
33                                document.getElementById('ratioC').disabled = true;
34                                document.getElementById('ratioC').value = '';
35                        }
36                        else if ($("input[name='ratio']:checked").val() == '4/3')
37                        {ldelim}
38                          jcrop_api.setOptions({ldelim} aspectRatio: 4/3 });
39                                document.getElementById('ratioC').disabled = true;
40                                document.getElementById('ratioC').value = '';
41                        }
42                        else if ($("input[name='ratio']:checked").val() == '5/7')
43                        {ldelim}
44                          jcrop_api.setOptions({ldelim} aspectRatio: 5/7 });
45                                document.getElementById('ratioC').disabled = true;
46                                document.getElementById('ratioC').value = '';
47                        }
48                        else if ($("input[name='ratio']:checked").val() == '16/9')
49                        {ldelim}
50                                jcrop_api.setOptions({ldelim} aspectRatio: 16/9 });
51                                document.getElementById('ratioC').disabled = true;
52                                document.getElementById('ratioC').value = '';
53                        }
54                        else if ($("input[name='ratio']:checked").val() == '2.35/1')
55                        {ldelim}
56                                jcrop_api.setOptions({ldelim} aspectRatio: 2.35/1 });
57                                document.getElementById('ratioC').disabled = true;
58                                document.getElementById('ratioC').value = '';
59                        }
60                        else if ($("input[name='ratio']:checked").val() == 'original')
61                        {ldelim}
62                                jcrop_api.setOptions({ldelim} aspectRatio: eval($('#image_ratio').val()) });
63                                document.getElementById('ratioC').disabled = true;
64                                document.getElementById('ratioC').value = '';                           
65                        }
66                        else if ($("input[name='ratio']:checked").val() == 'C')
67                        {ldelim}
68                                document.getElementById('ratioC').disabled = false;
69                                if ( eval($('#ratioC').val()) > 0 )
70                                jcrop_api.setOptions({ldelim} aspectRatio: eval($('#ratioC').val()) });
71                        }
72                        else
73                        {ldelim}
74                          jcrop_api.setOptions({ldelim} aspectRatio: 0 });
75                                document.getElementById('ratioC').disabled = true;
76                                document.getElementById('ratioC').value = '';
77                        }
78      jcrop_api.focus();
79    });
80        $("input[name='ratioC']").change(function(e) {ldelim}
81                        if (($("input[name='ratio']:checked").val() == 'C') && eval($('#ratioC').val()) > 0)
82                          jcrop_api.setOptions({ldelim} aspectRatio: eval($('#ratioC').val()) });
83      jcrop_api.focus();
84    });
85 
86function jOnChange(sel) {ldelim}
87        jQuery("input[name='x']").val(sel.x);
88        jQuery("input[name='y']").val(sel.y);
89        jQuery("input[name='x2']").val(sel.x2);
90        jQuery("input[name='y2']").val(sel.y2);
91       
92  jQuery("input[name='w']").val(sel.w);
93        jQuery("input[name='h']").val(sel.h);   
94       
95  jQuery("#width").html(Math.round(sel.x2-sel.x).toFixed(0));
96  jQuery("#height").html(Math.round(sel.y2-sel.y).toFixed(0));
97}
98  function jOnRelease() {ldelim}
99       
100}
101
102{/footer_script}
103
104<form method="post" action="">
105<fieldset>
106  <legend>{'Crop Photo'|@translate}</legend>
107  {'Choose the part of the photo you want to keep'|@translate}<br>
108  <img id="jcrop" src="{$picture.banner_src}?{1|rand:200}" width="{$crop.display_width}" height="{$crop.display_height}">
109 
110  <ul>
111    <li><b>{'Width'|@translate}:</b> <span id="width"></span>px</li>
112    <li><b>{'Height'|@translate}:</b> <span id="height"></span>px</li>
113  </ul>
114       
115  <input type="hidden" name="x">
116  <input type="hidden" name="y">
117  <input type="hidden" name="x2">
118  <input type="hidden" name="y2">
119        <input type="hidden" name="h">
120        <input type="hidden" name="w">
121  <input type="hidden" name="picture_file" value="{$picture.path}">
122        <input type="hidden" name="image_ratio" id="image_ratio" value="{$image_ratio}">
123  <input type="hidden" name="image_id" value="{$image_id}">
124        <fieldset>
125  <legend>{'Aspect Ratio'|@translate}</legend>
126        {'Square'|@translate}<input type="radio" value="1/1" name="ratio">&nbsp;&nbsp;4:5<input type="radio" value="4/5" name="ratio">&nbsp;&nbsp;4:3<input type="radio" value="4/3" name="ratio">&nbsp;&nbsp;5:7<input type="radio" value="5/7" name="ratio">&nbsp;&nbsp; 16:9<input type="radio" value="16/9" name="ratio">&nbsp;&nbsp; 2.35:1<input type="radio" value="2.35/1" name="ratio">&nbsp;
127        {'None'|@translate}<input type="radio" value="0" checked name="ratio">&nbsp;&nbsp; {'Original'|@translate}<input type="radio" value="original" name="ratio">&nbsp;&nbsp;{'Custom'|@translate}<input type="radio" value="C" name="ratio">&nbsp;<input type="text" name="ratioC" id="ratioC" value="" size="5" disabled/>
128        </fieldset>
129  <input type="submit" name="submit_crop" value="{'Submit'|@translate}">
130  <input type="submit" name="cancel_crop" value="{'Cancel'|@translate}">
131</fieldset>
132</form>
133{/if}
Note: See TracBrowser for help on using the repository browser.