3 /** This file is part of KCFinder project
5 * @desc Clipboard functionality
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
15 browser.initClipboard = function() {
16 if (!this.clipboard || !this.clipboard.length) return;
18 $.each(this.clipboard, function(i, val) {
19 size += parseInt(val.size);
21 size = this.humanSize(size);
22 $('#clipboard').html('<div title="' + this.label("Clipboard") + ' (' + this.clipboard.length + ' ' + this.label("files") + ', ' + size + ')" onclick="browser.openClipboard()"></div>');
23 var resize = function() {
25 left: $(window).width() - $('#clipboard').outerWidth() + 'px',
26 top: $(window).height() - $('#clipboard').outerHeight() + 'px'
30 $('#clipboard').css('display', 'block');
32 $(window).resize(function() {
38 browser.openClipboard = function() {
39 if (!this.clipboard || !this.clipboard.length) return;
40 if ($('.menu a[href="kcact:cpcbd"]').html()) {
41 $('#clipboard').removeClass('selected');
45 var html = '<div class="menu"><div class="list">';
46 $.each(this.clipboard, function(i, val) {
47 icon = _.getFileExtension(val.name);
50 else if (!val.smallIcon || !icon.length)
52 var icon = 'themes/' + browser.theme + '/img/files/small/' + icon + '.png';
53 html += '<a style="background-image:url(' + _.escapeDirs(icon) + ')" title="' + browser.label("Click to remove from the Clipboard") + '" onclick="browser.removeFromClipboard(' + i + ')">' + _.htmlData(_.basename(val.name)) + '</a>';
55 html += '</div><div class="delimiter"></div>';
56 if (this.support.zip) html+=
57 '<a href="kcact:download">' + this.label("Download files") + '</a>';
58 if (this.access.files.copy || this.access.files.move || this.access.files['delete'])
59 html += '<div class="delimiter"></div>';
60 if (this.access.files.copy)
61 html += '<a href="kcact:cpcbd"' + (!browser.dirWritable ? ' class="denied"' : '') + '>' +
62 this.label("Copy files here") + '</a>';
63 if (this.access.files.move)
64 html += '<a href="kcact:mvcbd"' + (!browser.dirWritable ? ' class="denied"' : '') + '>' +
65 this.label("Move files here") + '</a>';
66 if (this.access.files['delete'])
67 html += '<a href="kcact:rmcbd">' + this.label("Delete files") + '</a>';
68 html += '<div class="delimiter"></div>' +
69 '<a href="kcact:clrcbd">' + this.label("Clear the Clipboard") + '</a>' + '</div>';
71 setTimeout(function() {
72 $('#clipboard').addClass('selected');
73 $('#dialog').html(html);
74 $('.menu a[href="kcact:download"]').click(function() {
76 browser.downloadClipboard();
79 $('.menu a[href="kcact:cpcbd"]').click(function() {
80 if (!browser.dirWritable) return false;
82 browser.copyClipboard(browser.dir);
85 $('.menu a[href="kcact:mvcbd"]').click(function() {
86 if (!browser.dirWritable) return false;
88 browser.moveClipboard(browser.dir);
91 $('.menu a[href="kcact:rmcbd"]').click(function() {
94 browser.label("Are you sure you want to delete all files in the Clipboard?"),
96 if (callBack) callBack();
97 browser.deleteClipboard();
102 $('.menu a[href="kcact:clrcbd"]').click(function() {
103 browser.hideDialog();
104 browser.clearClipboard();
108 var left = $(window).width() - $('#dialog').outerWidth();
109 var top = $(window).height() - $('#dialog').outerHeight() - $('#clipboard').outerHeight();
110 var lheight = top + _.outerTopSpace('#dialog');
111 $('.menu .list').css('max-height', lheight + 'px');
112 var top = $(window).height() - $('#dialog').outerHeight() - $('#clipboard').outerHeight();
114 left: (left - 4) + 'px',
117 $('#dialog').fadeIn();
121 browser.removeFromClipboard = function(i) {
122 if (!this.clipboard || !this.clipboard[i]) return false;
123 if (this.clipboard.length == 1) {
124 this.clearClipboard();
129 if (i < this.clipboard.length - 1) {
130 var last = this.clipboard.slice(i + 1);
131 this.clipboard = this.clipboard.slice(0, i);
132 this.clipboard = this.clipboard.concat(last);
134 this.clipboard.pop();
136 this.initClipboard();
138 this.openClipboard();
142 browser.copyClipboard = function(dir) {
143 if (!this.clipboard || !this.clipboard.length) return;
146 for (i = 0; i < this.clipboard.length; i++)
147 if (this.clipboard[i].readable)
148 files[i] = this.clipboard[i].dir + '/' + this.clipboard[i].name;
151 if (this.clipboard.length == failed) {
152 browser.alert(this.label("The files in the Clipboard are not readable."));
155 var go = function(callBack) {
156 if (dir == browser.dir)
161 url: browser.baseGetData('cp_cbd'),
162 data: {dir: dir, files: files},
164 success: function(data) {
165 if (callBack) callBack();
166 browser.check4errors(data);
167 browser.clearClipboard();
168 if (dir == browser.dir)
172 if (callBack) callBack();
173 $('#files > div').css({
177 browser.alert(browser.label("Unknown error."));
184 browser.label("{count} files in the Clipboard are not readable. Do you want to copy the rest?", {count:failed}),
192 browser.moveClipboard = function(dir) {
193 if (!this.clipboard || !this.clipboard.length) return;
196 for (i = 0; i < this.clipboard.length; i++)
197 if (this.clipboard[i].readable && this.clipboard[i].writable)
198 files[i] = this.clipboard[i].dir + "/" + this.clipboard[i].name;
201 if (this.clipboard.length == failed) {
202 browser.alert(this.label("The files in the Clipboard are not movable."))
206 var go = function(callBack) {
211 url: browser.baseGetData('mv_cbd'),
212 data: {dir: dir, files: files},
214 success: function(data) {
215 if (callBack) callBack();
216 browser.check4errors(data);
217 browser.clearClipboard();
221 if (callBack) callBack();
222 $('#files > div').css({
226 browser.alert(browser.label("Unknown error."));
233 browser.label("{count} files in the Clipboard are not movable. Do you want to move the rest?", {count: failed}),
240 browser.deleteClipboard = function() {
241 if (!this.clipboard || !this.clipboard.length) return;
244 for (i = 0; i < this.clipboard.length; i++)
245 if (this.clipboard[i].readable && this.clipboard[i].writable)
246 files[i] = this.clipboard[i].dir + '/' + this.clipboard[i].name;
249 if (this.clipboard.length == failed) {
250 browser.alert(this.label("The files in the Clipboard are not removable."))
253 var go = function(callBack) {
258 url: browser.baseGetData('rm_cbd'),
261 success: function(data) {
262 if (callBack) callBack();
263 browser.check4errors(data);
264 browser.clearClipboard();
268 if (callBack) callBack();
269 $('#files > div').css({
273 browser.alert(browser.label("Unknown error."));
279 browser.label("{count} files in the Clipboard are not removable. Do you want to delete the rest?", {count: failed}),
286 browser.downloadClipboard = function() {
287 if (!this.clipboard || !this.clipboard.length) return;
289 for (i = 0; i < this.clipboard.length; i++)
290 if (this.clipboard[i].readable)
291 files[i] = this.clipboard[i].dir + '/' + this.clipboard[i].name;
293 this.post(this.baseGetData('downloadClipboard'), {files:files});
296 browser.clearClipboard = function() {
297 $('#clipboard').html('');