120.misc.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. if (_.uid)
  79. url += "&uid=" + encodeURIComponent(_.uid);
  80. console.log(url);
  81. return url;
  82. };
  83. _.label = function(index, data) {
  84. var label = _.labels[index] ? _.labels[index] : index;
  85. if (data)
  86. $.each(data, function(key, val) {
  87. label = label.replace("{" + key + "}", val);
  88. });
  89. return label;
  90. };
  91. _.check4errors = function(data) {
  92. if (!data.error)
  93. return false;
  94. var msg = data.error.join
  95. ? data.error.join("\n")
  96. : data.error;
  97. _.alert(msg);
  98. return true;
  99. };
  100. _.post = function(url, data) {
  101. var html = '<form id="postForm" method="post" action="' + url + '">';
  102. $.each(data, function(key, val) {
  103. if ($.isArray(val))
  104. $.each(val, function(i, aval) {
  105. html += '<input type="hidden" name="' + $.$.htmlValue(key) + '[]" value="' + $.$.htmlValue(aval) + '" />';
  106. });
  107. else
  108. html += '<input type="hidden" name="' + $.$.htmlValue(key) + '" value="' + $.$.htmlValue(val) + '" />';
  109. });
  110. html += '</form>';
  111. $('#menu').html(html).show();
  112. $('#postForm').get(0).submit();
  113. };
  114. _.fadeFiles = function() {
  115. $('#files > div').css({
  116. opacity: "0.4",
  117. filter: "alpha(opacity=40)"
  118. });
  119. };