100.clipboard.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /** This file is part of KCFinder project
  2. *
  3. * @desc Clipboard functionality
  4. * @package KCFinder
  5. * @version 3.12
  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
  11. */
  12. _.initClipboard = function() {
  13. if (!_.clipboard || !_.clipboard.length) return;
  14. var size = 0,
  15. jClipboard = $('#clipboard');
  16. $.each(_.clipboard, function(i, val) {
  17. size += val.size;
  18. });
  19. size = _.humanSize(size);
  20. jClipboard.disableTextSelect().html('<div title="' + _.label("Clipboard") + ' (' + _.clipboard.length + ' ' + _.label("files") + ', ' + size + ')" onclick="_.openClipboard()"></div>');
  21. var resize = function() {
  22. jClipboard.css({
  23. left: $(window).width() - jClipboard.outerWidth(),
  24. top: $(window).height() - jClipboard.outerHeight()
  25. });
  26. };
  27. resize();
  28. jClipboard.show();
  29. $(window).unbind().resize(function() {
  30. _.resize();
  31. resize();
  32. });
  33. };
  34. _.removeFromClipboard = function(i) {
  35. if (!_.clipboard || !_.clipboard[i]) return false;
  36. if (_.clipboard.length == 1) {
  37. _.clearClipboard();
  38. _.menu.hide();
  39. return;
  40. }
  41. if (i < _.clipboard.length - 1) {
  42. var last = _.clipboard.slice(i + 1);
  43. _.clipboard = _.clipboard.slice(0, i);
  44. _.clipboard = _.clipboard.concat(last);
  45. } else
  46. _.clipboard.pop();
  47. _.initClipboard();
  48. _.menu.hide();
  49. _.openClipboard();
  50. return true;
  51. };
  52. _.copyClipboard = function(dir) {
  53. if (!_.clipboard || !_.clipboard.length) return;
  54. var files = [],
  55. failed = 0;
  56. for (i = 0; i < _.clipboard.length; i++)
  57. if (_.clipboard[i].readable)
  58. files[i] = _.clipboard[i].dir + "/" + _.clipboard[i].name;
  59. else
  60. failed++;
  61. if (_.clipboard.length == failed) {
  62. _.alert(_.label("The files in the Clipboard are not readable."));
  63. return;
  64. }
  65. var go = function(callBack) {
  66. if (dir == _.dir)
  67. _.fadeFiles();
  68. $.ajax({
  69. type: "post",
  70. dataType: "json",
  71. url: _.getURL("cp_cbd"),
  72. data: {dir: dir, files: files},
  73. async: false,
  74. success: function(data) {
  75. if (callBack) callBack();
  76. _.check4errors(data);
  77. _.clearClipboard();
  78. if (dir == _.dir)
  79. _.refresh();
  80. },
  81. error: function() {
  82. if (callBack) callBack();
  83. $('#files > div').css({
  84. opacity: "",
  85. filter: ""
  86. });
  87. _.alert(_.label("Unknown error."));
  88. }
  89. });
  90. };
  91. if (failed)
  92. _.confirm(
  93. _.label("{count} files in the Clipboard are not readable. Do you want to copy the rest?", {count:failed}),
  94. go
  95. )
  96. else
  97. go();
  98. };
  99. _.moveClipboard = function(dir) {
  100. if (!_.clipboard || !_.clipboard.length) return;
  101. var files = [],
  102. failed = 0;
  103. for (i = 0; i < _.clipboard.length; i++)
  104. if (_.clipboard[i].readable && _.clipboard[i].writable)
  105. files[i] = _.clipboard[i].dir + "/" + _.clipboard[i].name;
  106. else
  107. failed++;
  108. if (_.clipboard.length == failed) {
  109. _.alert(_.label("The files in the Clipboard are not movable."))
  110. return;
  111. }
  112. var go = function(callBack) {
  113. _.fadeFiles();
  114. $.ajax({
  115. type: "post",
  116. dataType: "json",
  117. url: _.getURL("mv_cbd"),
  118. data: {dir: dir, files: files},
  119. async: false,
  120. success: function(data) {
  121. if (callBack) callBack();
  122. _.check4errors(data);
  123. _.clearClipboard();
  124. _.refresh();
  125. },
  126. error: function() {
  127. if (callBack) callBack();
  128. $('#files > div').css({
  129. opacity: "",
  130. filter: ""
  131. });
  132. _.alert(_.label("Unknown error."));
  133. }
  134. });
  135. };
  136. if (failed)
  137. _.confirm(
  138. _.label("{count} files in the Clipboard are not movable. Do you want to move the rest?", {count: failed}),
  139. go
  140. );
  141. else
  142. go();
  143. };
  144. _.deleteClipboard = function() {
  145. if (!_.clipboard || !_.clipboard.length) return;
  146. var files = [],
  147. failed = 0;
  148. for (i = 0; i < _.clipboard.length; i++)
  149. if (_.clipboard[i].readable && _.clipboard[i].writable)
  150. files[i] = _.clipboard[i].dir + "/" + _.clipboard[i].name;
  151. else
  152. failed++;
  153. if (_.clipboard.length == failed) {
  154. _.alert(_.label("The files in the Clipboard are not removable."))
  155. return;
  156. }
  157. var go = function(callBack) {
  158. _.fadeFiles();
  159. $.ajax({
  160. type: "post",
  161. dataType: "json",
  162. url: _.getURL("rm_cbd"),
  163. data: {files:files},
  164. async: false,
  165. success: function(data) {
  166. if (callBack) callBack();
  167. _.check4errors(data);
  168. _.clearClipboard();
  169. _.refresh();
  170. },
  171. error: function() {
  172. if (callBack) callBack();
  173. $('#files > div').css({
  174. opacity: "",
  175. filter: ""
  176. });
  177. _.alert(_.label("Unknown error."));
  178. }
  179. });
  180. };
  181. if (failed)
  182. _.confirm(
  183. _.label("{count} files in the Clipboard are not removable. Do you want to delete the rest?", {count: failed}),
  184. go
  185. );
  186. else
  187. go();
  188. };
  189. _.downloadClipboard = function() {
  190. if (!_.clipboard || !_.clipboard.length) return;
  191. var files = [];
  192. for (i = 0; i < _.clipboard.length; i++)
  193. if (_.clipboard[i].readable)
  194. files[i] = _.clipboard[i].dir + "/" + _.clipboard[i].name;
  195. if (files.length)
  196. _.post(_.getURL('downloadClipboard'), {files:files});
  197. };
  198. _.clearClipboard = function() {
  199. $('#clipboard').html("");
  200. _.clipboard = [];
  201. };