1 /** This file is part of KCFinder project
3 * @desc Miscellaneous functionality
6 * @author Pavel Tzonkov <sunhater@sunhater.com>
7 * @copyright 2010-2014 KCFinder Project
8 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
9 * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
10 * @link http://kcfinder.sunhater.com
13 _
.orderFiles = function(callBack
, selected
) {
14 var order
= $.$.kuki
.get('order'),
15 desc
= ($.$.kuki
.get('orderDesc') == "on"),
18 if (!_
.files
|| !_
.files
.sort
)
21 _
.files
= _
.files
.sort(function(a
, b
) {
22 if (!order
) order
= "name";
24 if (order
== "date") {
27 } else if (order
== "type") {
28 a1
= $.$.getFileExtension(a
.name
);
29 b1
= $.$.getFileExtension(b
.name
);
30 } else if (order
== "size") {
34 a1
= a
[order
].toLowerCase();
35 b1
= b
[order
].toLowerCase();
38 if ((order
== "size") || (order
== "date")) {
39 if (a1
< b1
) return desc
? 1 : -1;
40 if (a1
> b1
) return desc
? -1 : 1;
44 a1
= a
.name
.toLowerCase();
45 b1
= b
.name
.toLowerCase();
48 return (arr
[0] == a1
) ? -1 : 1;
53 if (arr
[0] == a1
) return desc
? 1 : -1;
57 _
.showFiles(callBack
, selected
);
61 _
.humanSize = function(size
) {
63 size
= size
.toString() + " B";
64 } else if (size
< 1048576) {
66 size
= parseInt(size
).toString() + " KB";
67 } else if (size
< 1073741824) {
69 size
= parseInt(size
).toString() + " MB";
70 } else if (size
< 1099511627776) {
72 size
= parseInt(size
).toString() + " GB";
74 size
/= 1099511627776;
75 size
= parseInt(size
).toString() + " TB";
80 _
.getURL = function(act
) {
81 var url
= "browse.php?type=" + encodeURIComponent(_
.type
) + "&lng=" + encodeURIComponent(_
.lang
);
83 url
+= "&opener=" + encodeURIComponent(_
.opener
.name
);
85 url
+= "&act=" + encodeURIComponent(act
);
87 url
+= "&cms=" + encodeURIComponent(_
.cms
);
91 _
.label = function(index
, data
) {
92 var label
= _
.labels
[index
] ? _
.labels
[index
] : index
;
94 $.each(data
, function(key
, val
) {
95 label
= label
.replace("{" + key
+ "}", val
);
100 _
.check4errors = function(data
) {
103 var msg
= data
.error
.join
104 ? data
.error
.join("\n")
110 _
.post = function(url
, data
) {
111 var html
= '<form id="postForm" method="post" action="' + url
+ '">';
112 $.each(data
, function(key
, val
) {
114 $.each(val
, function(i
, aval
) {
115 html
+= '<input type="hidden" name="' + $.$.htmlValue(key
) + '[]" value="' + $.$.htmlValue(aval
) + '" />';
118 html
+= '<input type="hidden" name="' + $.$.htmlValue(key
) + '" value="' + $.$.htmlValue(val
) + '" />';
121 $('#menu').html(html
).show();
122 $('#postForm').get(0).submit();
125 _
.fadeFiles = function() {
126 $('#files > div').css({
128 filter
: "alpha(opacity=40)"