1 /** This file is part of KCFinder project
3 * @desc Clipboard 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 _
.initClipboard = function() {
14 if (!_
.clipboard
|| !_
.clipboard
.length
) return;
17 jClipboard
= $('#clipboard');
19 $.each(_
.clipboard
, function(i
, val
) {
22 size
= _
.humanSize(size
);
23 jClipboard
.disableTextSelect().html('<div title="' + _
.label("Clipboard") + ' (' + _
.clipboard
.length
+ ' ' + _
.label("files") + ', ' + size
+ ')" onclick="_.openClipboard()"></div>');
24 var resize = function() {
26 left
: $(window
).width() - jClipboard
.outerWidth(),
27 top
: $(window
).height() - jClipboard
.outerHeight()
32 $(window
).unbind().resize(function() {
38 _
.removeFromClipboard = function(i
) {
39 if (!_
.clipboard
|| !_
.clipboard
[i
]) return false;
40 if (_
.clipboard
.length
== 1) {
46 if (i
< _
.clipboard
.length
- 1) {
47 var last
= _
.clipboard
.slice(i
+ 1);
48 _
.clipboard
= _
.clipboard
.slice(0, i
);
49 _
.clipboard
= _
.clipboard
.concat(last
);
59 _
.copyClipboard = function(dir
) {
60 if (!_
.clipboard
|| !_
.clipboard
.length
) return;
63 for (i
= 0; i
< _
.clipboard
.length
; i
++)
64 if (_
.clipboard
[i
].readable
)
65 files
[i
] = _
.clipboard
[i
].dir
+ "/" + _
.clipboard
[i
].name
;
68 if (_
.clipboard
.length
== failed
) {
69 _
.alert(_
.label("The files in the Clipboard are not readable."));
72 var go = function(callBack
) {
78 url
: _
.getURL("cp_cbd"),
79 data
: {dir
: dir
, files
: files
},
81 success: function(data
) {
82 if (callBack
) callBack();
89 if (callBack
) callBack();
90 $('#files > div').css({
94 _
.alert(_
.label("Unknown error."));
101 _
.label("{count} files in the Clipboard are not readable. Do you want to copy the rest?", {count
:failed
}),
109 _
.moveClipboard = function(dir
) {
110 if (!_
.clipboard
|| !_
.clipboard
.length
) return;
113 for (i
= 0; i
< _
.clipboard
.length
; i
++)
114 if (_
.clipboard
[i
].readable
&& _
.clipboard
[i
].writable
)
115 files
[i
] = _
.clipboard
[i
].dir
+ "/" + _
.clipboard
[i
].name
;
118 if (_
.clipboard
.length
== failed
) {
119 _
.alert(_
.label("The files in the Clipboard are not movable."))
123 var go = function(callBack
) {
128 url
: _
.getURL("mv_cbd"),
129 data
: {dir
: dir
, files
: files
},
131 success: function(data
) {
132 if (callBack
) callBack();
133 _
.check4errors(data
);
138 if (callBack
) callBack();
139 $('#files > div').css({
143 _
.alert(_
.label("Unknown error."));
150 _
.label("{count} files in the Clipboard are not movable. Do you want to move the rest?", {count
: failed
}),
157 _
.deleteClipboard = function() {
158 if (!_
.clipboard
|| !_
.clipboard
.length
) return;
161 for (i
= 0; i
< _
.clipboard
.length
; i
++)
162 if (_
.clipboard
[i
].readable
&& _
.clipboard
[i
].writable
)
163 files
[i
] = _
.clipboard
[i
].dir
+ "/" + _
.clipboard
[i
].name
;
166 if (_
.clipboard
.length
== failed
) {
167 _
.alert(_
.label("The files in the Clipboard are not removable."))
170 var go = function(callBack
) {
175 url
: _
.getURL("rm_cbd"),
178 success: function(data
) {
179 if (callBack
) callBack();
180 _
.check4errors(data
);
185 if (callBack
) callBack();
186 $('#files > div').css({
190 _
.alert(_
.label("Unknown error."));
196 _
.label("{count} files in the Clipboard are not removable. Do you want to delete the rest?", {count
: failed
}),
203 _
.downloadClipboard = function() {
204 if (!_
.clipboard
|| !_
.clipboard
.length
) return;
206 for (i
= 0; i
< _
.clipboard
.length
; i
++)
207 if (_
.clipboard
[i
].readable
)
208 files
[i
] = _
.clipboard
[i
].dir
+ "/" + _
.clipboard
[i
].name
;
210 _
.post(_
.getURL('downloadClipboard'), {files
:files
});
213 _
.clearClipboard = function() {
214 $('#clipboard').html("");