progress.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. $(function()
  2. {
  3. $('li.file').mouseover(function()
  4. {
  5. $(this).children('span.right-icon').removeClass("hidden");
  6. $(this).addClass('backgroundColor');
  7. });
  8. $('li.file').mouseout(function()
  9. {
  10. $(this).children('span.right-icon').addClass("hidden");
  11. $(this).removeClass('backgroundColor');
  12. });
  13. });
  14. /**
  15. * Delete a file.
  16. *
  17. * @param int $fileID
  18. * @param object $obj
  19. * @access public
  20. * @return void
  21. */
  22. function deleteFile(fileID, obj)
  23. {
  24. if(!fileID) return;
  25. hiddenwin.location.href = createLink('file', 'delete', 'fileID=' + fileID);
  26. }
  27. /**
  28. * Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it.
  29. *
  30. * @param int $fileID
  31. * @param int $extension
  32. * @param int $imageWidth
  33. * @param string $fileTitle
  34. * @param string $type download|preview
  35. * @access public
  36. * @return void
  37. */
  38. function downloadFile(fileID, extension, imageWidth, fileTitle, type = 'download')
  39. {
  40. if(!fileID) return;
  41. var fileTypes = 'txt,jpg,jpeg,gif,png,bmp,mp4';
  42. var windowWidth = $(window).width();
  43. var width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth;
  44. var checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1);
  45. var url = createLink('file', type, 'fileID=' + fileID + '&mouse=left');
  46. url += url.indexOf('?') >= 0 ? '&' : '?';
  47. if(fileTypes.indexOf(extension) >= 0 && checkExtension && config.onlybody != 'yes')
  48. {
  49. $('<a>').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click');
  50. }
  51. else
  52. {
  53. url = url.replace('?onlybody=yes&', '?');
  54. url = url.replace('?onlybody=yes', '?');
  55. url = url.replace('&onlybody=yes', '');
  56. window.open(url, '_blank');
  57. }
  58. return false;
  59. }
  60. /* Show edit box for editing file name. */
  61. /**
  62. * Show edit box for editing file name.
  63. *
  64. * @param int $fileID
  65. * @access public
  66. * @return void
  67. */
  68. function showRenameBox(fileID)
  69. {
  70. $('#renameFile' + fileID).closest('li').addClass('hidden');
  71. $('#renameBox' + fileID).closest('li').removeClass('hidden');
  72. }
  73. /**
  74. * Show File.
  75. *
  76. * @param int $fileID
  77. * @access public
  78. * @return void
  79. */
  80. function showFile(fileID)
  81. {
  82. $('#renameBox' + fileID).closest('li').addClass('hidden');
  83. $('#renameFile' + fileID).closest('li').removeClass('hidden');
  84. }
  85. /**
  86. * Smooth refresh file name.
  87. *
  88. * @param int $fileID
  89. * @access public
  90. * @return void
  91. */
  92. function setFileName(fileID)
  93. {
  94. var fileName = $('#fileName' + fileID).val();
  95. var extension = $('#extension' + fileID).val();
  96. var postData = {'fileName' : fileName, 'extension' : extension};
  97. console.log(postData, fileID, fileName);
  98. $.ajax(
  99. {
  100. url:createLink('file', 'edit', 'fileID=' + fileID),
  101. dataType: 'json',
  102. method: 'post',
  103. data: postData,
  104. success: function(data)
  105. {
  106. $('#fileTitle' + fileID).html("<i class='icon icon-file-text'></i> &nbsp;" + data['title']);
  107. $('#renameFile' + fileID).closest('li').removeClass('hidden');
  108. $('#renameBox' + fileID).closest('li').addClass('hidden');
  109. }
  110. })
  111. }