OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / kcfinder-2.51 / js / browser / clipboard.js
1 <?php
2
3 /** This file is part of KCFinder project
4   *
5   *      @desc Clipboard 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
15 browser.initClipboard = function() {
16     if (!this.clipboard || !this.clipboard.length) return;
17     var size = 0;
18     $.each(this.clipboard, function(i, val) {
19         size += parseInt(val.size);
20     });
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() {
24         $('#clipboard').css({
25             left: $(window).width() - $('#clipboard').outerWidth() + 'px',
26             top: $(window).height() - $('#clipboard').outerHeight() + 'px'
27         });
28     };
29     resize();
30     $('#clipboard').css('display', 'block');
31     $(window).unbind();
32     $(window).resize(function() {
33         browser.resize();
34         resize();
35     });
36 };
37
38 browser.openClipboard = function() {
39     if (!this.clipboard || !this.clipboard.length) return;
40     if ($('.menu a[href="kcact:cpcbd"]').html()) {
41         $('#clipboard').removeClass('selected');
42         this.hideDialog();
43         return;
44     }
45     var html = '<div class="menu"><div class="list">';
46     $.each(this.clipboard, function(i, val) {
47         icon = _.getFileExtension(val.name);
48         if (val.thumb)
49             icon = '.image';
50         else if (!val.smallIcon || !icon.length)
51             icon = '.';
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>';
54     });
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>';
70
71     setTimeout(function() {
72         $('#clipboard').addClass('selected');
73         $('#dialog').html(html);
74         $('.menu a[href="kcact:download"]').click(function() {
75             browser.hideDialog();
76             browser.downloadClipboard();
77             return false;
78         });
79         $('.menu a[href="kcact:cpcbd"]').click(function() {
80             if (!browser.dirWritable) return false;
81             browser.hideDialog();
82             browser.copyClipboard(browser.dir);
83             return false;
84         });
85         $('.menu a[href="kcact:mvcbd"]').click(function() {
86             if (!browser.dirWritable) return false;
87             browser.hideDialog();
88             browser.moveClipboard(browser.dir);
89             return false;
90         });
91         $('.menu a[href="kcact:rmcbd"]').click(function() {
92             browser.hideDialog();
93             browser.confirm(
94                 browser.label("Are you sure you want to delete all files in the Clipboard?"),
95                 function(callBack) {
96                     if (callBack) callBack();
97                     browser.deleteClipboard();
98                 }
99             );
100             return false;
101         });
102         $('.menu a[href="kcact:clrcbd"]').click(function() {
103             browser.hideDialog();
104             browser.clearClipboard();
105             return false;
106         });
107
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();
113         $('#dialog').css({
114             left: (left - 4) + 'px',
115             top: top + 'px'
116         });
117         $('#dialog').fadeIn();
118     }, 1);
119 };
120
121 browser.removeFromClipboard = function(i) {
122     if (!this.clipboard || !this.clipboard[i]) return false;
123     if (this.clipboard.length == 1) {
124         this.clearClipboard();
125         this.hideDialog();
126         return;
127     }
128
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);
133     } else
134         this.clipboard.pop();
135
136     this.initClipboard();
137     this.hideDialog();
138     this.openClipboard();
139     return true;
140 };
141
142 browser.copyClipboard = function(dir) {
143     if (!this.clipboard || !this.clipboard.length) return;
144     var files = [];
145     var failed = 0;
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;
149         else
150             failed++;
151     if (this.clipboard.length == failed) {
152         browser.alert(this.label("The files in the Clipboard are not readable."));
153         return;
154     }
155     var go = function(callBack) {
156         if (dir == browser.dir)
157             browser.fadeFiles();
158         $.ajax({
159             type: 'POST',
160             dataType: 'json',
161             url: browser.baseGetData('cp_cbd'),
162             data: {dir: dir, files: files},
163             async: false,
164             success: function(data) {
165                 if (callBack) callBack();
166                 browser.check4errors(data);
167                 browser.clearClipboard();
168                 if (dir == browser.dir)
169                     browser.refresh();
170             },
171             error: function() {
172                 if (callBack) callBack();
173                 $('#files > div').css({
174                     opacity: '',
175                     filter: ''
176                 });
177                 browser.alert(browser.label("Unknown error."));
178             }
179         });
180     };
181
182     if (failed)
183         browser.confirm(
184             browser.label("{count} files in the Clipboard are not readable. Do you want to copy the rest?", {count:failed}),
185             go
186         )
187     else
188         go();
189
190 };
191
192 browser.moveClipboard = function(dir) {
193     if (!this.clipboard || !this.clipboard.length) return;
194     var files = [];
195     var failed = 0;
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;
199         else
200             failed++;
201     if (this.clipboard.length == failed) {
202         browser.alert(this.label("The files in the Clipboard are not movable."))
203         return;
204     }
205
206     var go = function(callBack) {
207         browser.fadeFiles();
208         $.ajax({
209             type: 'POST',
210             dataType: 'json',
211             url: browser.baseGetData('mv_cbd'),
212             data: {dir: dir, files: files},
213             async: false,
214             success: function(data) {
215                 if (callBack) callBack();
216                 browser.check4errors(data);
217                 browser.clearClipboard();
218                 browser.refresh();
219             },
220             error: function() {
221                 if (callBack) callBack();
222                 $('#files > div').css({
223                     opacity: '',
224                     filter: ''
225                 });
226                 browser.alert(browser.label("Unknown error."));
227             }
228         });
229     };
230
231     if (failed)
232         browser.confirm(
233             browser.label("{count} files in the Clipboard are not movable. Do you want to move the rest?", {count: failed}),
234             go
235         );
236     else
237         go();
238 };
239
240 browser.deleteClipboard = function() {
241     if (!this.clipboard || !this.clipboard.length) return;
242     var files = [];
243     var failed = 0;
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;
247         else
248             failed++;
249     if (this.clipboard.length == failed) {
250         browser.alert(this.label("The files in the Clipboard are not removable."))
251         return;
252     }
253     var go = function(callBack) {
254         browser.fadeFiles();
255         $.ajax({
256             type: 'POST',
257             dataType: 'json',
258             url: browser.baseGetData('rm_cbd'),
259             data: {files:files},
260             async: false,
261             success: function(data) {
262                 if (callBack) callBack();
263                 browser.check4errors(data);
264                 browser.clearClipboard();
265                 browser.refresh();
266             },
267             error: function() {
268                 if (callBack) callBack();
269                 $('#files > div').css({
270                     opacity: '',
271                     filter:''
272                 });
273                 browser.alert(browser.label("Unknown error."));
274             }
275         });
276     };
277     if (failed)
278         browser.confirm(
279             browser.label("{count} files in the Clipboard are not removable. Do you want to delete the rest?", {count: failed}),
280             go
281         );
282     else
283         go();
284 };
285
286 browser.downloadClipboard = function() {
287     if (!this.clipboard || !this.clipboard.length) return;
288     var files = [];
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;
292     if (files.length)
293         this.post(this.baseGetData('downloadClipboard'), {files:files});
294 };
295
296 browser.clearClipboard = function() {
297     $('#clipboard').html('');
298     this.clipboard = [];
299 };