source: trunk/admin/inc/ckeditor/filemanager/js/browser/misc.js@ 239

Last change on this file since 239 was 239, checked in by luc, 9 years ago

Admin: correzione visulaizzazione immissione dati spoglio per Chrome e Safari - Aggiornamento dell'editor da FCKeditor a CKeditor , accessibili anche a Chrome e Safari.

  • Property svn:executable set to *
File size: 12.5 KB
Line 
1<?php
2
3/** This file is part of KCFinder project
4 *
5 * @desc Miscellaneous functionality
6 * @package KCFinder
7 * @version 2.51
8 * @author Pavel Tzonkov <pavelc@users.sourceforge.net>
9 * @copyright 2010, 2011 KCFinder Project
10 * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11 * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12 * @link http://kcfinder.sunhater.com
13 */?>
14
15browser.drag = function(ev, dd) {
16 var top = dd.offsetY,
17 left = dd.offsetX;
18 if (top < 0) top = 0;
19 if (left < 0) left = 0;
20 if (top + $(this).outerHeight() > $(window).height())
21 top = $(window).height() - $(this).outerHeight();
22 if (left + $(this).outerWidth() > $(window).width())
23 left = $(window).width() - $(this).outerWidth();
24 $(this).css({
25 top: top,
26 left: left
27 });
28};
29
30browser.showDialog = function(e) {
31 $('#dialog').css({left: 0, top: 0});
32 this.shadow();
33 if ($('#dialog div.box') && !$('#dialog div.title').get(0)) {
34 var html = $('#dialog div.box').html();
35 var title = $('#dialog').data('title') ? $('#dialog').data('title') : "";
36 html = '<div class="title"><span class="close"></span>' + title + '</div>' + html;
37 $('#dialog div.box').html(html);
38 $('#dialog div.title span.close').mousedown(function() {
39 $(this).addClass('clicked');
40 });
41 $('#dialog div.title span.close').mouseup(function() {
42 $(this).removeClass('clicked');
43 });
44 $('#dialog div.title span.close').click(function() {
45 browser.hideDialog();
46 browser.hideAlert();
47 });
48 }
49 $('#dialog').drag(browser.drag, {handle: '#dialog div.title'});
50 $('#dialog').css('display', 'block');
51
52 if (e) {
53 var left = e.pageX - parseInt($('#dialog').outerWidth() / 2);
54 var top = e.pageY - parseInt($('#dialog').outerHeight() / 2);
55 if (left < 0) left = 0;
56 if (top < 0) top = 0;
57 if (($('#dialog').outerWidth() + left) > $(window).width())
58 left = $(window).width() - $('#dialog').outerWidth();
59 if (($('#dialog').outerHeight() + top) > $(window).height())
60 top = $(window).height() - $('#dialog').outerHeight();
61 $('#dialog').css({
62 left: left + 'px',
63 top: top + 'px'
64 });
65 } else
66 $('#dialog').css({
67 left: parseInt(($(window).width() - $('#dialog').outerWidth()) / 2) + 'px',
68 top: parseInt(($(window).height() - $('#dialog').outerHeight()) / 2) + 'px'
69 });
70 $(document).unbind('keydown');
71 $(document).keydown(function(e) {
72 if (e.keyCode == 27)
73 browser.hideDialog();
74 });
75};
76
77browser.hideDialog = function() {
78 this.unshadow();
79 if ($('#clipboard').hasClass('selected'))
80 $('#clipboard').removeClass('selected');
81 $('#dialog').css('display', 'none');
82 $('div.folder > a > span.folder').removeClass('context');
83 $('#dialog').html('');
84 $('#dialog').data('title', null);
85 $('#dialog').unbind();
86 $('#dialog').click(function() {
87 return false;
88 });
89 $(document).unbind('keydown');
90 $(document).keydown(function(e) {
91 return !browser.selectAll(e);
92 });
93 browser.hideAlert();
94};
95
96browser.showAlert = function(shadow) {
97 $('#alert').css({left: 0, top: 0});
98 if (typeof shadow == 'undefined')
99 shadow = true;
100 if (shadow)
101 this.shadow();
102 var left = parseInt(($(window).width() - $('#alert').outerWidth()) / 2),
103 top = parseInt(($(window).height() - $('#alert').outerHeight()) / 2);
104 var wheight = $(window).height();
105 if (top < 0)
106 top = 0;
107 $('#alert').css({
108 left: left + 'px',
109 top: top + 'px',
110 display: 'block'
111 });
112 if ($('#alert').outerHeight() > wheight) {
113 $('#alert div.message').css({
114 height: wheight - $('#alert div.title').outerHeight() - $('#alert div.ok').outerHeight() - 20 + 'px'
115 });
116 }
117 $(document).unbind('keydown');
118 $(document).keydown(function(e) {
119 if (e.keyCode == 27) {
120 browser.hideDialog();
121 browser.hideAlert();
122 $(document).unbind('keydown');
123 $(document).keydown(function(e) {
124 return !browser.selectAll(e);
125 });
126 }
127 });
128};
129
130browser.hideAlert = function(shadow) {
131 if (typeof shadow == 'undefined')
132 shadow = true;
133 if (shadow)
134 this.unshadow();
135 $('#alert').css('display', 'none');
136 $('#alert').html('');
137 $('#alert').data('title', null);
138};
139
140browser.alert = function(msg, shadow) {
141 msg = msg.replace(/\r?\n/g, "<br />");
142 var title = $('#alert').data('title') ? $('#alert').data('title') : browser.label("Attention");
143 $('#alert').html('<div class="title"><span class="close"></span>' + title + '</div><div class="message">' + msg + '</div><div class="ok"><button>' + browser.label("OK") + '</button></div>');
144 $('#alert div.ok button').click(function() {
145 browser.hideAlert(shadow);
146 });
147 $('#alert div.title span.close').mousedown(function() {
148 $(this).addClass('clicked');
149 });
150 $('#alert div.title span.close').mouseup(function() {
151 $(this).removeClass('clicked');
152 });
153 $('#alert div.title span.close').click(function() {
154 browser.hideAlert(shadow);
155 });
156 $('#alert').drag(browser.drag, {handle: "#alert div.title"});
157 browser.showAlert(shadow);
158};
159
160browser.confirm = function(question, callBack) {
161 $('#dialog').data('title', browser.label("Question"));
162 $('#dialog').html('<div class="box"><div class="question">' + browser.label(question) + '<div class="buttons"><button>' + browser.label("No") + '</button> <button>' + browser.label("Yes") + '</button></div></div></div>');
163 browser.showDialog();
164 $('#dialog div.buttons button').first().click(function() {
165 browser.hideDialog();
166 });
167 $('#dialog div.buttons button').last().click(function() {
168 if (callBack)
169 callBack(function() {
170 browser.hideDialog();
171 });
172 else
173 browser.hideDialog();
174 });
175 $('#dialog div.buttons button').get(1).focus();
176};
177
178browser.shadow = function() {
179 $('#shadow').css('display', 'block');
180};
181
182browser.unshadow = function() {
183 $('#shadow').css('display', 'none');
184};
185
186browser.showMenu = function(e) {
187 var left = e.pageX;
188 var top = e.pageY;
189 if (($('#dialog').outerWidth() + left) > $(window).width())
190 left = $(window).width() - $('#dialog').outerWidth();
191 if (($('#dialog').outerHeight() + top) > $(window).height())
192 top = $(window).height() - $('#dialog').outerHeight();
193 $('#dialog').css({
194 left: left + 'px',
195 top: top + 'px',
196 display: 'none'
197 });
198 $('#dialog').fadeIn();
199};
200
201browser.fileNameDialog = function(e, post, inputName, inputValue, url, labels, callBack, selectAll) {
202 var html = '<form method="post" action="javascript:;">' +
203 '<div class="box">' +
204 '<input name="' + inputName + '" type="text" /><br />' +
205 '<div style="text-align:right">' +
206 '<input type="submit" value="' + _.htmlValue(this.label("OK")) + '" /> ' +
207 '<input type="button" value="' + _.htmlValue(this.label("Cancel")) + '" onclick="browser.hideDialog(); browser.hideAlert(); return false" />' +
208 '</div></div></form>';
209 $('#dialog').html(html);
210 $('#dialog').data('title', this.label(labels.title));
211 $('#dialog input[name="' + inputName + '"]').attr('value', inputValue);
212 $('#dialog').unbind();
213 $('#dialog').click(function() {
214 return false;
215 });
216 $('#dialog form').submit(function() {
217 var name = this.elements[0];
218 name.value = $.trim(name.value);
219 if (name.value == '') {
220 browser.alert(browser.label(labels.errEmpty), false);
221 name.focus();
222 return;
223 } else if (/[\/\\]/g.test(name.value)) {
224 browser.alert(browser.label(labels.errSlash), false);
225 name.focus();
226 return;
227 } else if (name.value.substr(0, 1) == ".") {
228 browser.alert(browser.label(labels.errDot), false);
229 name.focus();
230 return;
231 }
232 eval('post.' + inputName + ' = name.value;');
233 $.ajax({
234 type: 'POST',
235 dataType: 'json',
236 url: url,
237 data: post,
238 async: false,
239 success: function(data) {
240 if (browser.check4errors(data, false))
241 return;
242 if (callBack) callBack(data);
243 browser.hideDialog();
244 },
245 error: function() {
246 browser.alert(browser.label("Unknown error."), false);
247 }
248 });
249 return false;
250 });
251 browser.showDialog(e);
252 $('#dialog').css('display', 'block');
253 $('#dialog input[type="submit"]').click(function() {
254 return $('#dialog form').submit();
255 });
256 var field = $('#dialog input[type="text"]');
257 var value = field.attr('value');
258 if (!selectAll && /^(.+)\.[^\.]+$/ .test(value)) {
259 value = value.replace(/^(.+)\.[^\.]+$/, "$1");
260 _.selection(field.get(0), 0, value.length);
261 } else {
262 field.get(0).focus();
263 field.get(0).select();
264 }
265};
266
267browser.orderFiles = function(callBack, selected) {
268 var order = _.kuki.get('order');
269 var desc = (_.kuki.get('orderDesc') == 'on');
270
271 if (!browser.files || !browser.files.sort)
272 browser.files = [];
273
274 browser.files = browser.files.sort(function(a, b) {
275 var a1, b1, arr;
276 if (!order) order = 'name';
277
278 if (order == 'date') {
279 a1 = a.mtime;
280 b1 = b.mtime;
281 } else if (order == 'type') {
282 a1 = _.getFileExtension(a.name);
283 b1 = _.getFileExtension(b.name);
284 } else if (order == 'size') {
285 a1 = a.size;
286 b1 = b.size;
287 } else
288 eval('a1 = a.' + order + '.toLowerCase(); b1 = b.' + order + '.toLowerCase();');
289
290 if ((order == 'size') || (order == 'date')) {
291 if (a1 < b1) return desc ? 1 : -1;
292 if (a1 > b1) return desc ? -1 : 1;
293 }
294
295 if (a1 == b1) {
296 a1 = a.name.toLowerCase();
297 b1 = b.name.toLowerCase();
298 arr = [a1, b1];
299 arr = arr.sort();
300 return (arr[0] == a1) ? -1 : 1;
301 }
302
303 arr = [a1, b1];
304 arr = arr.sort();
305 if (arr[0] == a1) return desc ? 1 : -1;
306 return desc ? -1 : 1;
307 });
308
309 browser.showFiles(callBack, selected);
310 browser.initFiles();
311};
312
313browser.humanSize = function(size) {
314 if (size < 1024) {
315 size = size.toString() + ' B';
316 } else if (size < 1048576) {
317 size /= 1024;
318 size = parseInt(size).toString() + ' KB';
319 } else if (size < 1073741824) {
320 size /= 1048576;
321 size = parseInt(size).toString() + ' MB';
322 } else if (size < 1099511627776) {
323 size /= 1073741824;
324 size = parseInt(size).toString() + ' GB';
325 } else {
326 size /= 1099511627776;
327 size = parseInt(size).toString() + ' TB';
328 }
329 return size;
330};
331
332browser.baseGetData = function(act) {
333 var data = 'browse.php?type=' + encodeURIComponent(this.type) + '&lng=' + this.lang;
334 if (act)
335 data += "&act=" + act;
336 if (this.cms)
337 data += "&cms=" + this.cms;
338 return data;
339};
340
341browser.label = function(index, data) {
342 var label = this.labels[index] ? this.labels[index] : index;
343 if (data)
344 $.each(data, function(key, val) {
345 label = label.replace('{' + key + '}', val);
346 });
347 return label;
348};
349
350browser.check4errors = function(data, shadow) {
351 if (!data.error)
352 return false;
353 var msg;
354 if (data.error.join)
355 msg = data.error.join("\n");
356 else
357 msg = data.error;
358 browser.alert(msg, shadow);
359 return true;
360};
361
362browser.post = function(url, data) {
363 var html = '<form id="postForm" method="POST" action="' + url + '">';
364 $.each(data, function(key, val) {
365 if ($.isArray(val))
366 $.each(val, function(i, aval) {
367 html += '<input type="hidden" name="' + _.htmlValue(key) + '[]" value="' + _.htmlValue(aval) + '" />';
368 });
369 else
370 html += '<input type="hidden" name="' + _.htmlValue(key) + '" value="' + _.htmlValue(val) + '" />';
371 });
372 html += '</form>';
373 $('#dialog').html(html);
374 $('#dialog').css('display', 'block');
375 $('#postForm').get(0).submit();
376};
377
378browser.fadeFiles = function() {
379 $('#files > div').css({
380 opacity: '0.4',
381 filter: 'alpha(opacity:40)'
382 });
383};
Note: See TracBrowser for help on using the repository browser.