Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

107 linhas
3.7 KiB

  1. $(document).ready(function() {
  2. // Smooth scrolling
  3. $('a[href*=#]:not([href=#])').click(function() {
  4. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  5. var target = $(this.hash);
  6. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  7. if (target.length) {
  8. $('html,body').animate({
  9. scrollTop: target.offset().top
  10. }, 1000);
  11. return false;
  12. }
  13. }
  14. });
  15. });
  16. (function() {
  17. var files = Array()
  18. function upload(file) {
  19. $('.browse').addClass('uploading');
  20. var li = $('<li style="clear:both;"/>');
  21. li.append($('<div><div class="upload-progress"><span></span><div class="bar" style="width:0%;">####################################################</div></div><p>Uploading... ' + file.name + '</p></div>'));
  22. $(li).appendTo($('.queue'));
  23. var xhr = new XMLHttpRequest();
  24. xhr.upload.addEventListener("progress", function(e) {
  25. var pc = parseInt((e.loaded / e.total * 100));
  26. $('.upload-progress', $(li)).show();
  27. $('.upload-progress .bar', $(li)).css('width', pc + "%");
  28. $('.upload-progress span ').empty().append(pc + "%");
  29. }, false);
  30. xhr.onreadystatechange = function(e) {
  31. if (xhr.readyState == 4) {
  32. /* $('.upload-progress', $(li)).hide();*/
  33. $('#web').addClass('uploading');
  34. // progress.className = (xhr.status == 200 ? "success" : "failure");
  35. if (xhr.status == 200) {
  36. $(li).html('<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
  37. } else {
  38. $(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>');
  39. }
  40. files.push(xhr.responseText.replace("https://transfer.sh/", "").replace("\n", ""));
  41. // files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
  42. $(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
  43. $(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
  44. $(".all-files").addClass('show');
  45. }
  46. };
  47. // should queue all uploads.
  48. // start upload
  49. xhr.open("PUT", '/' + file.name, true);
  50. xhr.setRequestHeader("X_FILENAME", file.name);
  51. xhr.send(file);
  52. };
  53. $(document).bind("dragenter", function(event) {
  54. event.preventDefault();
  55. }).bind("dragover", function(event) {
  56. event.preventDefault();
  57. // show drop indicator
  58. $('#terminal').addClass('dragged');
  59. $('#web').addClass('dragged');
  60. }).bind("dragleave", function(event) {
  61. $('#terminal').removeClass('dragged');
  62. $('#web').removeClass('dragged');
  63. }).bind("drop dragdrop", function(event) {
  64. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  65. $.each(files, function(index, file) {
  66. console.debug(file);
  67. upload(file);
  68. });
  69. event.stopPropagation();
  70. event.preventDefault();
  71. });
  72. $('a.browse').on('click', function(event) {
  73. $("input[type=file]").click();
  74. return (false);
  75. });
  76. $('input[type=file]').on('change', function(event) {
  77. $.each(this.files, function(index, file) {
  78. if (file instanceof Blob) {
  79. upload(file);
  80. }
  81. });
  82. });
  83. })();