You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

113 lines
4.1 KiB

  1. $(document).ready(function () {
  2. // Terminal typing animation
  3. $("#from-terminal p").typed({
  4. strings: ["curl --upload-file ./hello.txt https://transfer.sh/hello.txt\n######################################################\nhttps://transfer.sh/66nb8/hello.txt \n "],
  5. typeSpeed: 0, // typing speed
  6. backSpeed: 0, // backspacing speed
  7. startDelay: 0, // time before typing starts
  8. backDelay: 500, // pause before backspacing
  9. loop: false, // loop on or off (true or false)
  10. loopCount: false, // number of loops, false = infinite
  11. showCursor: true,
  12. attr: null, // attribute to type, null = text for everything except inputs, which default to placeholder
  13. callback: function(){ } // call function after typing is done
  14. });
  15. // Smooth scrolling
  16. $('a[href*=#]:not([href=#])').click(function () {
  17. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  18. var target = $(this.hash);
  19. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  20. if (target.length) {
  21. $('html,body').animate({
  22. scrollTop: target.offset().top
  23. }, 1000);
  24. return false;
  25. }
  26. }
  27. });
  28. });
  29. (function () {
  30. var files = Array()
  31. function upload(file) {
  32. var li = $('<li style="clear:both;"/>');
  33. li.append($('<div><div class="progress active upload-progress" style="margin-bottom: 0;"><div class="progress-bar" style="width: 0%;"></div></div><p>Uploading... ' + file.name + '</p></div>'));
  34. $(li).appendTo($('.queue'));
  35. var xhr = new XMLHttpRequest();
  36. xhr.upload.addEventListener("progress", function (e) {
  37. var pc = parseInt((e.loaded / e.total * 100));
  38. $('.upload-progress', $(li)).show();
  39. $('.upload-progress .bar', $(li)).css('width', pc + "%");
  40. }, false);
  41. xhr.onreadystatechange = function (e) {
  42. if (xhr.readyState == 4) {
  43. $('.upload-progress', $(li)).hide();
  44. // progress.className = (xhr.status == 200 ? "success" : "failure");
  45. if (xhr.status == 200) {
  46. $(li).html('<i class="icon-file fileupload-exists"></i><a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>');
  47. } else {
  48. $(li).html('Error (' + xhr.status + ') during upload of file ' + file.name + '.');
  49. }
  50. files.push(xhr.responseText.replace("https://transfer.sh/", ""));
  51. files.push(URI(xhr.responseText).absoluteTo(location.href).toString());
  52. $(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString());
  53. $(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString());
  54. $(".all-files").css("opacity", "1");
  55. }
  56. };
  57. // should queue all uploads.
  58. // start upload
  59. xhr.open("PUT", '/' + file.name, true);
  60. xhr.setRequestHeader("X_FILENAME", file.name);
  61. xhr.send(file);
  62. };
  63. $(document).bind("dragenter", function (event) {
  64. event.preventDefault();
  65. }).bind("dragover", function (event) {
  66. event.preventDefault();
  67. // show drop indicator
  68. }).bind("dragleave", function (event) {}).bind("drop dragdrop", function (event) {
  69. var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
  70. $.each(files, function (index, file) {
  71. console.debug(file);
  72. upload(file);
  73. });
  74. event.stopPropagation();
  75. event.preventDefault();
  76. });
  77. $('a.browse').on('click', function (event) {
  78. $("input[type=file]").click();
  79. return (false);
  80. });
  81. $('input[type=file]').on('change', function (event) {
  82. $.each(this.files, function (index, file) {
  83. if (file instanceof Blob) {
  84. upload(file);
  85. }
  86. });
  87. });
  88. })();