1 | {combine_css path='themes/default/js/plugins/jquery.tokeninput.css'} |
---|
2 | {combine_script id='jquery.tokeninput' load='footer' path='themes/default/js/plugins/jquery.tokeninput.js'} |
---|
3 | |
---|
4 | {combine_css path=$SMILIES_PATH|cat:'template/style.css'} |
---|
5 | |
---|
6 | |
---|
7 | {footer_script} |
---|
8 | (function(){ |
---|
9 | var data = {ldelim}}, |
---|
10 | edit = false, |
---|
11 | edited = false; |
---|
12 | |
---|
13 | // set changed |
---|
14 | jQuery('select[name="folder"]').change(function() { |
---|
15 | if (edited) { |
---|
16 | var ok = confirm('{'If you change current set you will lost every shortcuts changes.'|translate|escape:javascript}'); |
---|
17 | if (!ok) { |
---|
18 | jQuery(this).val(jQuery(this).data('selected')); |
---|
19 | return false; |
---|
20 | } |
---|
21 | } |
---|
22 | |
---|
23 | var image = jQuery(this).find(':selected').css('background-image'); |
---|
24 | jQuery(this).css('background-image', image); |
---|
25 | jQuery(this).data('selected', jQuery(this).val()); |
---|
26 | |
---|
27 | fetch(); |
---|
28 | }); |
---|
29 | |
---|
30 | // size changed |
---|
31 | jQuery('input[name="cols"]').change(function() { |
---|
32 | update(); |
---|
33 | }); |
---|
34 | |
---|
35 | // switch preview/edit |
---|
36 | jQuery('.edit').click(function() { |
---|
37 | if (edit) { |
---|
38 | $(this).html('{'Edit shorcuts'|translate|escape:javascript}'); |
---|
39 | } |
---|
40 | else { |
---|
41 | $(this).html('{'Preview'|translate|escape:javascript}'); |
---|
42 | } |
---|
43 | |
---|
44 | edit = !edit; |
---|
45 | update(); |
---|
46 | return false; |
---|
47 | }); |
---|
48 | |
---|
49 | // reset defaults |
---|
50 | jQuery('.reset').click(function() { |
---|
51 | if (!confirm('{'Are you sure?'|translate|escape:javascript}')) { |
---|
52 | return false; |
---|
53 | } |
---|
54 | |
---|
55 | jQuery.ajax({ |
---|
56 | url: 'admin.php', |
---|
57 | type: 'GET', |
---|
58 | dataType: 'json', |
---|
59 | data: { |
---|
60 | action: 'ss_reset', |
---|
61 | folder: jQuery('select[name="folder"]').val(), |
---|
62 | }, |
---|
63 | success: function(result) { |
---|
64 | data = result; |
---|
65 | edited = false; |
---|
66 | update(); |
---|
67 | } |
---|
68 | }); |
---|
69 | |
---|
70 | return false; |
---|
71 | }); |
---|
72 | |
---|
73 | // display edit form before submit |
---|
74 | jQuery('#smiliesupport').submit(function() { |
---|
75 | if (!edit) { |
---|
76 | jQuery('.edit').click(); |
---|
77 | } |
---|
78 | return true; |
---|
79 | }); |
---|
80 | |
---|
81 | /* get smilies list */ |
---|
82 | function fetch() { |
---|
83 | jQuery.ajax({ |
---|
84 | url: 'admin.php', |
---|
85 | type: 'GET', |
---|
86 | dataType: 'json', |
---|
87 | data: { |
---|
88 | action: 'ss_list', |
---|
89 | folder: jQuery('select[name="folder"]').val(), |
---|
90 | }, |
---|
91 | success: function(result) { |
---|
92 | data = result; |
---|
93 | edited = false; |
---|
94 | update(); |
---|
95 | } |
---|
96 | }); |
---|
97 | } |
---|
98 | |
---|
99 | /* update preview/edit table */ |
---|
100 | function update() { |
---|
101 | var html = '', i=0; |
---|
102 | |
---|
103 | if (!edit) { |
---|
104 | html+= '<tr>'; |
---|
105 | |
---|
106 | var cols = parseInt(jQuery('input[name="cols"]').val()); |
---|
107 | |
---|
108 | for (var file in data.smilies) { |
---|
109 | var smiley = data.smilies[file]; |
---|
110 | html+= '<td><a href="#" title="'+ smiley.title +'"><img src="'+ data.path + smiley.file +'"/></a></td>'; |
---|
111 | html+= (i+1)%cols==0 ? '</tr><tr>' : ''; |
---|
112 | i++; |
---|
113 | } |
---|
114 | |
---|
115 | html+= '</tr>'; |
---|
116 | |
---|
117 | jQuery('.reset').hide(); |
---|
118 | } |
---|
119 | else { |
---|
120 | html+= '<tr>' |
---|
121 | +'<th></th>' |
---|
122 | +'<th>{'Name'|translate}</th>' |
---|
123 | +'<th>{'Shortcuts'|translate}</th>' |
---|
124 | +'<th class="spacer"></th>' |
---|
125 | +'<th></th>' |
---|
126 | +'<th>{'Name'|translate}</th>' |
---|
127 | +'<th>{'Shortcuts'|translate}</th>' |
---|
128 | +'</tr>' |
---|
129 | |
---|
130 | +'<tr>'; |
---|
131 | |
---|
132 | for (var file in data.smilies) { |
---|
133 | var smiley = data.smilies[file]; |
---|
134 | |
---|
135 | html+= |
---|
136 | '<td><img src="'+ data.path + smiley.file +'"/></td>' |
---|
137 | +'<td>'+ smiley.title +'</td>' |
---|
138 | +'<td data-file="'+ smiley.file +'">' |
---|
139 | +'<select name="shortcuts['+ smiley.file +']" class="shortcuts">'; |
---|
140 | |
---|
141 | for (var j in smiley.short) { |
---|
142 | html+= '<option value="'+ smiley.short[j] +'" selected>'+ smiley.short[j] +'</option>'; |
---|
143 | } |
---|
144 | |
---|
145 | html+= |
---|
146 | '</select>' |
---|
147 | +'</td>'; |
---|
148 | |
---|
149 | html+= (i+1)%2==0 ? '</tr><tr>' : '<td></td>'; |
---|
150 | i++; |
---|
151 | } |
---|
152 | |
---|
153 | html+= '</tr>'; |
---|
154 | |
---|
155 | jQuery('.reset').show(); |
---|
156 | } |
---|
157 | |
---|
158 | jQuery('#preview').html(html); |
---|
159 | |
---|
160 | // init tokeninput |
---|
161 | jQuery('.shortcuts').tokenInput([], { |
---|
162 | hintText: '{'Type in a new shortcut'|translate|escape:javascript}', |
---|
163 | newText: '', |
---|
164 | animateDropdown: false, |
---|
165 | preventDuplicates: true, |
---|
166 | allowFreeTagging: true, |
---|
167 | minChars: 2, |
---|
168 | searchDelay: 10, |
---|
169 | |
---|
170 | onAdd: function(item) { |
---|
171 | edited = true; |
---|
172 | var file = $(this).parent('td').data("file"); |
---|
173 | |
---|
174 | if (data.smilies[file].short == null) { |
---|
175 | data.smilies[file].short = [item.name]; |
---|
176 | } |
---|
177 | else { |
---|
178 | data.smilies[file].short.push(item.name); |
---|
179 | } |
---|
180 | }, |
---|
181 | onDelete: function(item) { |
---|
182 | edited = true; |
---|
183 | var file = $(this).parent('td').data("file"); |
---|
184 | |
---|
185 | for (var i in data.smilies[file].short) { |
---|
186 | if (data.smilies[file].short[i] == item.name) { |
---|
187 | data.smilies[file].short.splice(i, 1); |
---|
188 | } |
---|
189 | } |
---|
190 | }, |
---|
191 | }); |
---|
192 | |
---|
193 | // prevent spaces |
---|
194 | jQuery('.token-input-input-token input').keydown(function(e) { |
---|
195 | if (e.keyCode == 32) { |
---|
196 | return false; |
---|
197 | } |
---|
198 | }); |
---|
199 | } |
---|
200 | |
---|
201 | // init |
---|
202 | fetch(); |
---|
203 | }());{/footer_script} |
---|
204 | |
---|
205 | |
---|
206 | <div class="titrePage"> |
---|
207 | <h2>Smilies Support</h2> |
---|
208 | </div> |
---|
209 | |
---|
210 | <form method="post" action="" class="properties" id="smiliesupport"> |
---|
211 | |
---|
212 | <fieldset> |
---|
213 | <legend>{'Configuration'|translate}</legend> |
---|
214 | |
---|
215 | <ul> |
---|
216 | <li> |
---|
217 | <b>{'Smilies set'|translate}</b> |
---|
218 | <select name="folder" style="background-image:url('{$SMILIES_PATH}smilies/{$FOLDER}/{$SETS[$FOLDER]}');" data-selected="{$FOLDER}"> |
---|
219 | {foreach from=$SETS item=rep key=set} |
---|
220 | <option value="{$set}" style="background-image:url('{$SMILIES_PATH}smilies/{$set}/{$rep}');" {if $set==$FOLDER}selected{/if}>{$set}</option> |
---|
221 | {/foreach} |
---|
222 | </select> |
---|
223 | </li> |
---|
224 | <li> |
---|
225 | <b>{'Columns'|translate}</b> |
---|
226 | <input type="text" size="2" name="cols" value="{$COLS}"> |
---|
227 | </li> |
---|
228 | </ul> |
---|
229 | </fieldset> |
---|
230 | |
---|
231 | <fieldset> |
---|
232 | <legend>{'Preview'|translate}</legend> |
---|
233 | <a href="#" class="edit buttonLike">{'Edit shortcuts'|translate}</a> |
---|
234 | <table id="preview"></table> |
---|
235 | <a href="#" class="reset buttonLike" style="display:none;">{'Reset defaults'|translate}</a> |
---|
236 | </fieldset> |
---|
237 | |
---|
238 | <p class="formButtons"><input class="submit" type="submit" value="{'Submit'|translate}" name="submit" /></p> |
---|
239 | |
---|
240 | </form> |
---|