120.misc.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /** This file is part of KCFinder project
  2. *
  3. * @desc Miscellaneous 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. _.orderFiles = function(callBack, selected) {
  13. var order = $.$.kuki.get('order'),
  14. desc = ($.$.kuki.get('orderDesc') == "on"),
  15. a1, b1, arr;
  16. if (!_.files || !_.files.sort)
  17. _.files = [];
  18. _.files = _.files.sort(function(a, b) {
  19. if (!order) order = "name";
  20. if (order == "date") {
  21. a1 = a.mtime;
  22. b1 = b.mtime;
  23. } else if (order == "type") {
  24. a1 = $.$.getFileExtension(a.name);
  25. b1 = $.$.getFileExtension(b.name);
  26. } else if (order == "size") {
  27. a1 = a.size;
  28. b1 = b.size;
  29. } else {
  30. a1 = a[order].toLowerCase();
  31. b1 = b[order].toLowerCase();
  32. }
  33. if ((order == "size") || (order == "date")) {
  34. if (a1 < b1) return desc ? 1 : -1;
  35. if (a1 > b1) return desc ? -1 : 1;
  36. }
  37. if (a1 == b1) {
  38. a1 = a.name.toLowerCase();
  39. b1 = b.name.toLowerCase();
  40. arr = [a1, b1];
  41. arr = arr.sort();
  42. return (arr[0] == a1) ? -1 : 1;
  43. }
  44. arr = [a1, b1];
  45. arr = arr.sort();
  46. if (arr[0] == a1) return desc ? 1 : -1;
  47. return desc ? -1 : 1;
  48. });
  49. _.showFiles(callBack, selected);
  50. _.initFiles();
  51. };
  52. _.humanSize = function(size) {
  53. if (size < 1024) {
  54. size = size.toString() + " B";
  55. } else if (size < 1048576) {
  56. size /= 1024;
  57. size = parseInt(size).toString() + " KB";
  58. } else if (size < 1073741824) {
  59. size /= 1048576;
  60. size = parseInt(size).toString() + " MB";
  61. } else if (size < 1099511627776) {
  62. size /= 1073741824;
  63. size = parseInt(size).toString() + " GB";
  64. } else {
  65. size /= 1099511627776;
  66. size = parseInt(size).toString() + " TB";
  67. }
  68. return size;
  69. };
  70. _.getURL = function(act) {
  71. var url = "browse.php?type=" + encodeURIComponent(_.type) + "&lng=" + encodeURIComponent(_.lang);
  72. if (_.opener.name)
  73. url += "&opener=" + encodeURIComponent(_.opener.name);
  74. if (act)
  75. url += "&act=" + encodeURIComponent(act);
  76. if (_.cms)
  77. url += "&cms=" + encodeURIComponent(_.cms);
  78. return url;
  79. };
  80. _.label = function(index, data) {
  81. var label = _.labels[index] ? _.labels[index] : index;
  82. if (data)
  83. $.each(data, function(key, val) {
  84. label = label.replace("{" + key + "}", val);
  85. });
  86. return label;
  87. };
  88. _.check4errors = function(data) {
  89. if (!data.error)
  90. return false;
  91. var msg = data.error.join
  92. ? data.error.join("\n")
  93. : data.error;
  94. _.alert(msg);
  95. return true;
  96. };
  97. _.post = function(url, data) {
  98. var html = '<form id="postForm" method="post" action="' + url + '">';
  99. $.each(data, function(key, val) {
  100. if ($.isArray(val))
  101. $.each(val, function(i, aval) {
  102. html += '<input type="hidden" name="' + $.$.htmlValue(key) + '[]" value="' + $.$.htmlValue(aval) + '" />';
  103. });
  104. else
  105. html += '<input type="hidden" name="' + $.$.htmlValue(key) + '" value="' + $.$.htmlValue(val) + '" />';
  106. });
  107. html += '</form>';
  108. $('#menu').html(html).show();
  109. $('#postForm').get(0).submit();
  110. };
  111. _.fadeFiles = function() {
  112. $('#files > div').css({
  113. opacity: "0.4",
  114. filter: "alpha(opacity=40)"
  115. });
  116. };